Files
deepseek-harness/packages/document/tool-office
涂轶翔 101f26de4e fix(system-prompt): 保留 section API 的增量系统指令 (#6941)
* feat(system-prompt): admit section updates incrementally

* docs(system-prompt): accept retirement restart gap

* test(system-prompt): cover retirement and reentry before admission

* test(system-prompt): align rebase fixtures and persistence history

* fix: align section prompt consumers and CI fixtures

* test: pin credentials for section snapshot fixtures

* test: align remaining snapshots with section admission

* test: preserve section metadata in Web and PowerShell replays

* refactor(system-prompt): retire sections through Cordis cleanup

* chore: refresh section admission history after rebase

* fix(system-prompt): advance admission head after compaction

* fix(system-prompt): trim sections before admission hashing

* docs: move system upgrade guides to current version

* docs: add system message contribution cookbook

* perf(system-prompt): avoid indexing history for admission

* refactor(system-prompt): derive admission from logged sections

* test(system-prompt): update lifecycle and compaction consumers

* test(system-prompt): refresh CLI section event expectations

* test(system-prompt): refresh question composer section metadata

* feat(system-prompt): resolve same-name sections by scope

* refactor(persona): use ordinary section registrations

* refactor(system-prompt): clarify assembly and related control flow

* test(system-prompt): reconcile rebased section snapshots

* test(python): use current system text helper after rebase

* test(system-prompt): refresh CLI expected section blocks

* test(system-prompt): reconcile latest master integration

* test(agent-loop): seed tools before deferred addition assertion

* refactor(compaction): replace system heads when compacting prefixes

* refactor(system-prompt): separate source text and notice attribution

* fix(system-prompt): preserve legacy instructions in compaction snapshots

* refactor(compaction): build system snapshots while reading the summary prefix

* refactor(compaction): rebuild current system instructions

* refactor(system-prompt): defer compaction rebuild to admission

* refactor(system-prompt): remove redundant fixtures and setup

* fix(plan-mode): announce committed user transitions

* docs(system-prompt): reconcile section lifecycle and compaction design

* refactor(system-prompt): consolidate projection version increments

* fix(system-prompt): reconcile master integration and replay fixtures

* docs(system-prompt): align upgrade guide with current release

* refactor(system-prompt): make admission operations explicit

* fix(system-prompt): reconcile master API and release changes

* docs(system-prompt): regenerate catalogs after master refresh

* refactor(llm-pi-ai): delegate text rendering to pi-ai

* fix(llm-pi-ai): preserve blank lines between system text parts

* refactor(system-prompt): remove redundant retirement metadata

* refactor(system-prompt): own admission and use canonical surface targets

* refactor(system-prompt): compare captured sections at commitment

Assembly fixes section text and lifecycle; PromptAssembly.systemUpdates() compares them with the committed projection when the loop commits. This replaces SystemPrompt.admit(), needsRebuild() and isCurrent(), the SystemAdmission export, the loop's reassembly after compaction, and SessionSurface.systemHeadResetSeq. The projection records a pending rebuild as a boolean that an attributed reset clears.

After a compaction inside a step, the rebuilt head uses the sections captured for that step; later source changes arrive as ordinary updates at the next step.

* test: await the session read fixture and type a matcher for lint

* test(tool-executor-ptc): describe same-name section override on executor replacement

Duplicate section names no longer reject a scoped executor; the earlier registration is overridden and returns as an ordinary update when the executor leaves.

* docs(upgrade-guide): move system-prompt integrations to v0.2.2-rc.3

The root version on master is 0.2.2-rc.3; verify-upgrade-guides rejects a guide added under an earlier version directory.

* refactor(system-prompt): rebuild over system messages without sections

A system message without source.sections now marks rebuilding pending, like a compaction summary. The next model attempt replaces the head with current sections and clears later system messages. This removes the separate legacy flag and its appended whole-prompt replacement and notice.

Sessions written by earlier releases, migrated logs, and imported DeepSeek conversations take the same path, so the importer and its tests return to their master versions.

* test(web): refresh the imported-conversation recording and drop a stray bytecode file

The Web recording for a resumed DeepSeek import was recorded while the prompt was appended after the imported history; the head is replaced again, as on master. The .pyc under the macOS signing skill was staged by accident in an earlier merge.

* refactor(session): scan system nodes on read

surface.systemNodes is read only when a system rebuild is written. Scanning the current surface nodes on each read restores the surface fold's plan types and state to their master definitions, which no longer carry the system message.

* refactor(session): rename SystemSurfaceNode.hasContent to isEmpty

The flag reports that the logged content array has no blocks. isEmpty matches the documented "empty head" wording and covers a head that was written empty without ever being cleared.

* refactor(llm): join system text through extractTextContent

extractTextContent gains a trim option that trims each text block and omits blocks left empty. The DeepSeek serializer, the pi-ai converter, and the prompt inspector use it with a blank-line separator in place of three hand-written joins.

The pi-ai converter now trims system and developer text like the other two, so whitespace-only blocks are omitted there as well.

* test(snapshots): refresh the PowerShell and cordis-inspect recordings

The two PowerShell scenarios still held the initial system message as one unattributed block; replay now writes one block per section with its attribution. The cordis-inspect-jsdoc recording embeds the API catalog, which names SystemSurfaceNode.isEmpty since the rename.

* test(plan-mode,harness-dev-context): cover a rejected pre-step and a repeated legacy prompt

A rejected pre-step must leave a queued plan-mode switch pending and unannounced until the next accepted step. A second unattributed system message with the same legacy paragraphs must keep the admitted paragraphs.

* test(web): refresh Web recordings for section-attributed system messages

Twenty-seven Web recordings still held the initial system message as one unattributed block. Replay now writes one text block per section with its attribution; twenty-six recordings differ only in that line.

plan-review also records the plan-mode switch notice before the first prompt and appends a plan:status update on exit in place of a head replacement and a series header, so its expanded golden gains the notice row.

The Creator persona test joins the system text blocks with blank lines, as the adapters do, before matching the persona line.

* refactor(system-prompt): require the retry argument of systemUpdates

The agent loop passes it on every attempt. A custom loop that omitted it on a retry received a full comparison in place of the pending rebuild, with no diagnostic; the type now makes each caller state which attempt it is.

* docs(upgrade-guide): move the system prompt integrations guide to v0.2.2-rc.5

The root version is 0.2.2-rc.5 after the master merge, and verify-upgrade-guides rejects a guide added under an earlier version directory.

* test(web): refresh the mention path presence recording for section-attributed system messages

* test: align two specs that master left failing

The DeepSeek settings spec waited for a saved notice carrying the provider label from before the rename to DeepSeek API. The Windows packaging workflow spec seeded one of the two helpers that the Stage workflow helpers step copies.

* chore: remove a Python cache file committed by mistake
2026-11-19 21:11:38 +08:00
..

description, kind
description kind
Skill-activated Office tools for viewing document pages, converting documents, and recalculating workbooks. package-reference

@deepseek-ai/dsh-tool-office

English | 中文

Summary

After an Office skill loads, the model gains three tools. office_render returns document pages, slides, or worksheet areas as images for layout inspection, without temporary image files or a separate image read. office_convert produces a document in another format; office_recalculate refreshes workbook formulas. Both return a temporary file to copy to its destination with the shell. The tools do not modify inputs or write workspace files, and work in standard and PTC modes alike.

Table of Contents


Use this package

The Web bundle and the SDK bundle mount this plugin with office-kit in Desktop, ordinary dsh web, and the SDK; in the Web bundle the standard and ptc agent presets include it and the minimal preset does not. Loading any configured Office skill activates all three tools from the next model step, whether loaded by a model skill call, a nested PTC call, or direct user invocation such as /office. Failed loads and other skills do not activate them. Calls before activation return UNKNOWN_TOOL.

Activation matches only the skill names listed in activationSkills, so mount @deepseek-ai/dsh-skill-office or another provider that registers skills with those names; without one, the three tools never appear.

The tools read the Office kit service at each call. When Kit is missing, calls fail with the service's unavailable message; while the service is absent, calls fail with The document converter is unavailable. Every unavailable failure tells the model to inform the user, or to retry later when the cause may be temporary, such as a full output store or a service being unloaded, without substituting system soffice, npx, or another converter.

- name: '@deepseek-ai/dsh-office-kit'
- name: '@deepseek-ai/dsh-tool-office'
  config:
    maxImages: 20
Field Default Meaning
activationSkills [office, office-docx, office-xlsx, office-pptx] Nonempty list of kebab-case skill names whose successful loading activates all three tools
maxImages 20 Maximum images one render returns, including worksheet fragments
maxImagePixels 8388608 Maximum pixels of each image
maxImageDimension 8192 Maximum width and height of each image
maxImageBytes 33554432 Maximum PNG bytes across all images of one render

A render applies the lower of each field and the attachment store's corresponding image limit (maxImagesPerMessage, maxImagePixels, maxImageDimension, maxMessageImageBytes), and refuses any single image above maxImageBytes of the store. A selection beyond a bound fails instead of being truncated. Rendering requires an attachment store and a calling model route that declares image input. The tool reads that route from the latest model request of the Session, or from the agent options before the first request, and refuses a model whose input modalities omit images or are not declared before any rendering work starts.

Inputs resolve against the Session working directory and use the filesystem backend's read authority, as read and Office previews do, so files outside the workspace are readable. The input extension selects the document family. office_convert accepts Word, Excel, and PowerPoint documents: Word exports to pdf, docx, odt, or txt; Excel to pdf, xlsx, ods, or csv; PowerPoint to pdf, pptx, or odp. CSV export requires a worksheet name for a workbook with several sheets. office_recalculate accepts xls, xlsx, and ods workbooks and requires xlsx or ods output. office_render also accepts PDF.

Conversion and recalculation results name a file in the Office kit's private output store under the Harness home; the model copies it with the shell, so the shell's sandbox and approvals govern where it lands. When the filesystem backend cannot read Host files, such as an SSH workspace, these two tools fail before converting; rendering still works.

Failed calls record a structured name and code on tool/result. An Office kit failure becomes OfficeToolError with the matching OfficeToolErrorCode and keeps the OfficeKitError as cause: OFFICE_UNAVAILABLE (also for an absent Office service), OFFICE_BUSY, OFFICE_INPUT_TOO_LARGE, OFFICE_OUTPUT_TOO_LARGE, OFFICE_INVALID_DOCUMENT, OFFICE_UNSUPPORTED_FORMAT, OFFICE_INVALID_REQUEST, OFFICE_INVALID_OUTPUT, OFFICE_TIMEOUT, OFFICE_SOURCE_CHANGED, or OFFICE_CONVERSION_FAILED for the kit code failed. The tools also throw OfficeToolError with OFFICE_OUTPUT_TOO_LARGE for a rendered image above the store's per-image byte limit, OFFICE_UNSUPPORTED_REMOTE_WORKSPACE when the execution world cannot read conversion output, and MODEL_DOES_NOT_SUPPORT_IMAGES when the model route does not declare image input. Argument checks the schema cannot express, including an input extension the operation does not accept, throw ToolArgsError (INVALID_ARGS) with the message prefixed by invalid arguments: . A call outside an Agent step, a missing attachment store, or an unresolvable model route throws ToolContextUnavailableError (TOOL_CONTEXT_UNAVAILABLE). A missing input throws FsError FS_NOT_FOUND, a non-regular input FS_NOT_REGULAR_FILE, and other filesystem failures keep their FsError codes. An attachment store refusal keeps its AttachmentError code, with the operation and path prepended to the message. Other failures, including cancellation, pass through unchanged.

Every request enters the Office kit's shared queue with foreground priority, the same class as an open preview. Foreground work runs before background prewarming and can evict queued background jobs, so speculative previews cannot starve tool calls; tool calls and open previews share admission in arrival order.


Understand the implementation

Implementation internals — click to expand

Argument checks, including input-dependent conversion formats, and the Office kit lookup run before any filesystem access, so a malformed call or an absent service fails without reading the input. The tool then resolves the input through ctx.fs, requires a regular file, reads its first byte through fs.readByteRange, and stats it again, so a call without content read access, or for a file replaced since its stat, fails before the Office kit can answer from its cache. It then passes the Office kit an authorized source whose deferred read stats the file before and after a bounded fs.readBytes and rejects a changed version. Render results are committed through attachments.saveImages() before the result returns, so the tool/result event carries durable image references; resume, fork, and replay restore the same images, and image offload applies to them like any other tool-result image. The canonical value carries attachment references and image locations; output.render produces one summary text, then a location label and image block per rendered page or area. presentationMeta records the canonical input path, plus the temporary file path for conversions. Output store files are owned by the root Session of the caller's subagent tree, read through subagents.rootOf() when that service is mounted and otherwise the calling Session, and are named after the input with the new extension.

Each tool declares its own parameters and result schema. The supported schema subset cannot express page uniqueness, numeric bounds, or cross-parameter rules, so those render selections and input-dependent conversion formats are checked at runtime. Office kit errors are reported as cannot <operation> "<path>": <message>, where <path> is the resolved input path, or the path as given when the service is absent, with a hint for unavailable to tell the user or, when the cause may be temporary, to retry later without substituting another converter, a retry hint for busy, and a selection hint for oversized renders. Nested PTC calls re-enter the same execution pipeline, so policy and logging apply to them; a nested render's images are attached after the program run.

Successful tools/result notifications mark the calling Agent in a plugin-owned WeakSet. The post-commit session/event feed also marks direct user skill invocations, without depending on pre-step listener order. agent/disposed clears the mark. The three tools share one when: the Agent is marked, or the Session's latest public requestHeader() lists any Office tool. No additional projection or Session event is registered.

Native request headers retain Office declarations across resume and fork, including the first request after restoration; compaction replaces conversation content without removing request headers. PTC records only run_code in its request header, so a resumed or forked PTC Agent must load an Office skill again. Losing an Agent's memory before a native Office declaration is recorded also loses activation; calling skill again restores it on the following step.


Further Exploration

Model Experience

office_render, office_convert, office_recalculate

What the model sees

The three declarations are documented in the tool catalog. A render result opens with Rendered <count> image(s) of <absolute input path> (<pageCount> in the document) at <dpi> DPI., adds Fonts not installed and substituted: <families>. when fonts are missing, then gives each image as a Page <n>: <width>x<height> px or Sheet "<name>" <range>: <width>x<height> px label followed by the image. A conversion reports Converted <input> to <format> (<bytes> bytes[, <n> pages]): <temporary file> (or Recalculated …), then Copy this temporary file to its destination with the shell now; it may be deleted after a retention period or to free space, and is deleted when this conversation ends. and the same font line. Failures read cannot <operation> "<path>": <reason>, or cannot read "<path>": <reason> for an input the filesystem cannot read. An argument rule the schema cannot express reads invalid arguments: <violations>.

Token effect

No Office declarations before activation; three fixed tool schemas afterward, represented as program bindings in PTC mode. Each render adds its summary, one short label per image, and the images, bounded by the configured and attachment image limits; image tokens depend on the route's image pricing. Conversions add two lines.

KV Cache effect

In native mode, activation during a conversation appends one developer/message with tool-addition blocks; a route that declares toolUpdate keeps the request prefix unchanged, and other routes start one new request series. Native resume and fork retain the declarations. In PTC mode, the three tools are bindings listed in the run_code section of the system prompt, so activation rewrites the system prompt: a route that declares systemPromptUpdate: in-history appends one system message, and other routes start one new request series. PTC resume or fork loses the in-memory mark, so the system prompt changes twice: the next step removes the bindings, and loading an Office skill again adds them back. Results append to the conversation; image offload may later replace an image occurrence with placeholder text through its own logged event.

Known Limitations and Deferred Work

  • Converted files need a shell copy — the filesystem service creates no binary files, so the model copies each temporary file with the shell. Deployments without a shell tool cannot deliver converted files, and the temporary file is deleted after the Office kit's retention or when the root Session of the caller's subagent tree is disposed; a file a subagent produced stays after that subagent ends.
  • No conversion on remote workspaces — the Office kit runs on the Host, and a remote shell cannot read its output store.
  • Render saves no image file — office_render returns images only for the model to view and writes no PNG or other image file. A user who needs the pages as a file gets a PDF through office_convert with format: "pdf".
  • Web GUI does not display rendered images — the ui-tool Office row shows the text blocks of an office_render result and omits its images, so the user does not see the pages the model inspected. The model still receives every image.
  • Native engine in the Host process — rendering, conversion, and recalculation that the model starts run the native LibreOffice Kit engine inside the Host process through ctx.officeKit, so the shell sandbox and PTC permissions do not confine them. Inputs remain subject to the filesystem backend's read authority. The native parser processes an untrusted document with the Host user's permissions.
  • PTC activation does not survive resume or fork — the PTC request header records only run_code, so a resumed or forked PTC Agent offers no Office bindings until the model loads an Office skill again; the removal and the re-addition each rewrite the system prompt, with the cache effect described under KV Cache effect.
  • Plugin reload clears activation — hot reload, or disabling and re-enabling the plugin, clears the in-memory marks. If a step runs in the meantime, its request header omits the three tools, and the model must load an Office skill again to restore them.
  • Direct invocation activates from the next step — the tool set of a step is fixed before the content of a user-invoked skill such as /office is injected, so the first model request after the invocation declares no Office tools. The tools appear from the next model step.
  • Rendering fidelity, fonts, and pagination follow LibreOffice Kit and can differ from Microsoft Office.

Dev Note

Working context for maintainers — click to expand

None.