pi-for-word

Pi4Word Specification

Product Contract

Pi4Word is a Microsoft Word task pane add-in that embeds a Pi Agent assistant powered by @mariozechner/pi-agent-core.

The assistant can read the current Word selection as GitHub-flavored Markdown, reason over the document through Word tools, and insert or replace content by rendering Markdown into sanitized HTML for the Word JavaScript API.

Core user-visible surfaces:

Runtime Model

Assistant Contract

Tool descriptions and parameter schemas in source are authoritative.

Word Tools

createWordTools() lives in src/assistant-tools/index.js and returns these Word tools in order.

Tool Source Contract
word_get_selection word-tool-get-selection.js Runs Word.run, loads selection text, queues range.getHtml(), syncs, converts Word HTML to GFM Markdown, and falls back to range.text if Markdown is empty but text is present.
word_get_document_outline word-tool-get-document-outline.js Returns a table-of-contents-style outline from document body paragraphs using built-in Heading 1-9 styles and/or outline levels 1-9.
word_search_text word-tool-search-text.js Searches the document body with Word search, accepts optional search_options, and returns match count plus a preview for the selected match_index.
word_insert_markdown word-tool-insert-markdown.js Converts Markdown to sanitized HTML and inserts it using Word insertHtml at the requested placement or search anchor.

word_insert_markdown

Required parameters:

Accepted where aliases:

Optional search anchoring parameters:

When anchor_search_text is non-empty and where is not end_of_document, insertion targets the Nth body search hit instead of the current selection.

Search Options

word_search_text.search_options and word_insert_markdown.anchor_search_options accept Word SearchOptions flags in snake_case:

When an insert is anchored from a prior search, anchor_search_options must mirror the original search_options; mismatched flags can target a different occurrence. Word wildcard and search behavior follows Microsoft’s search-option guidance.

Markdown And HTML

JavaScript REPL Tool

createPi4WordJavaScriptReplTool() lives in src/assistant-tools/javascript-repl-tool.js and wraps pi-web-ui’s javascript_repl.

Contract differences from the upstream tool:

Settings And Storage

Networking

LLM traffic uses createPi4WordStreamFn() in src/assistant/pi-assistant.js.

Build And Assets

Source Boundaries