dsh-tool-docx 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +53 -0
- package/README.i18n.yaml +7 -0
- package/README.md +202 -0
- package/README.ru.md +202 -0
- package/README.zh.md +202 -0
- package/cordis.patch.yml +18 -0
- package/lib/fs-binary-D0seEN6R.js +63 -0
- package/lib/fs-binary-local-n8Ls-bn_.js +155 -0
- package/lib/fs-binary-local-plugin.js +24 -0
- package/lib/fs-binary-local.js +2 -0
- package/lib/fs-binary-sandbox-BobaE5Hr.js +135 -0
- package/lib/fs-binary-sandbox-plugin.js +31 -0
- package/lib/fs-binary-sandbox.js +2 -0
- package/lib/index.js +1507 -0
- package/lib/invariant.js +23 -0
- package/lib/types/caps.d.ts +14 -0
- package/lib/types/docx/extract.d.ts +18 -0
- package/lib/types/docx/generate.d.ts +17 -0
- package/lib/types/docx/zip.d.ts +17 -0
- package/lib/types/error.d.ts +20 -0
- package/lib/types/fs-binary-local-plugin.d.ts +19 -0
- package/lib/types/fs-binary-local.d.ts +45 -0
- package/lib/types/fs-binary-sandbox-plugin.d.ts +22 -0
- package/lib/types/fs-binary-sandbox.d.ts +51 -0
- package/lib/types/fs-binary.d.ts +52 -0
- package/lib/types/fsio-bytes.d.ts +27 -0
- package/lib/types/index.d.ts +32 -0
- package/lib/types/invariant.d.ts +16 -0
- package/lib/types/markdown.d.ts +35 -0
- package/lib/types/path-contains.d.ts +21 -0
- package/lib/types/sandbox.d.ts +63 -0
- package/lib/types/tool-utils.d.ts +56 -0
- package/lib/types/tools/create.d.ts +19 -0
- package/lib/types/tools/edit.d.ts +19 -0
- package/lib/types/tools/read.d.ts +16 -0
- package/lib/types/types.d.ts +77 -0
- package/package.json +114 -0
package/lib/invariant.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region lib/types/invariant.js
|
|
2
|
+
/**
|
|
3
|
+
* Package-owned invariant companion for `dsh-tool-docx`.
|
|
4
|
+
* @module dsh-tool-docx/invariant
|
|
5
|
+
*/
|
|
6
|
+
const PACKAGE_NAME = "dsh-tool-docx";
|
|
7
|
+
/** Cordis companion plugin name. */
|
|
8
|
+
const name = "tool-docx-invariant";
|
|
9
|
+
/** Service required before the companion can reserve package ownership. */
|
|
10
|
+
const inject = ["invariants"];
|
|
11
|
+
/**
|
|
12
|
+
* No runtime invariant: the tools are model-facing consumers of the filesystem
|
|
13
|
+
* seam; execution relations are owned by the seam they call.
|
|
14
|
+
*/
|
|
15
|
+
const install = () => {};
|
|
16
|
+
/**
|
|
17
|
+
* Register this package's invariant companion.
|
|
18
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
19
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
20
|
+
*/
|
|
21
|
+
const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
|
|
22
|
+
//#endregion
|
|
23
|
+
export { apply, inject, name };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolved docx tool caps — plugin config after defaulting (see `Config` in
|
|
3
|
+
* index.ts), shared by all three tools.
|
|
4
|
+
* @module dsh-tool-docx/caps
|
|
5
|
+
*/
|
|
6
|
+
export interface DocxToolCaps {
|
|
7
|
+
/** Inclusive byte cap on a whole `.docx` file (read + ZIP expansion). */
|
|
8
|
+
maxDocxBytes: number;
|
|
9
|
+
/** Inclusive character cap on the markdown input to create/edit. */
|
|
10
|
+
maxMarkdownChars: number;
|
|
11
|
+
/** Inclusive character cap on the markdown returned by `docx_read`. */
|
|
12
|
+
maxReadChars: number;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=caps.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract a `.docx` package into Markdown and structured blocks: walks
|
|
3
|
+
* `word/document.xml` (paragraphs, runs, lists, tables, hyperlinks, images),
|
|
4
|
+
* resolves list numbering through `word/numbering.xml`, and reads document
|
|
5
|
+
* properties from `docProps/core.xml`. Pure — no I/O; callers supply the
|
|
6
|
+
* bounded package bytes.
|
|
7
|
+
* @module dsh-tool-docx/docx/extract
|
|
8
|
+
*/
|
|
9
|
+
import type { ExtractedDocx } from '../types.ts';
|
|
10
|
+
/**
|
|
11
|
+
* Extract one `.docx` package into markdown + structured blocks.
|
|
12
|
+
* @param data - the whole package bytes (already bounded by the caller).
|
|
13
|
+
* @param maxUncompressedBytes - cap for the ZIP expansion.
|
|
14
|
+
* @returns the extraction result.
|
|
15
|
+
* @throws {@link DocxError} with a stable code for invalid/encrypted packages.
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractDocx(data: Uint8Array, maxUncompressedBytes: number): Promise<ExtractedDocx>;
|
|
18
|
+
//# sourceMappingURL=extract.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a `.docx` package buffer from structured blocks using the `docx`
|
|
3
|
+
* library: headings, paragraphs with inline styling, nested bullet/numbered
|
|
4
|
+
* lists, pipe tables, and external hyperlinks. Document properties come from
|
|
5
|
+
* the caller (extracted from the previous version on an edit).
|
|
6
|
+
* @module dsh-tool-docx/docx/generate
|
|
7
|
+
*/
|
|
8
|
+
import type { Buffer } from 'node:buffer';
|
|
9
|
+
import type { DocxBlock, DocxProps } from '../types.ts';
|
|
10
|
+
/**
|
|
11
|
+
* Generate a `.docx` package buffer from blocks.
|
|
12
|
+
* @param blocks - the structured content to render.
|
|
13
|
+
* @param props - document properties to stamp (title/creator/created).
|
|
14
|
+
* @returns the packed `.docx` bytes.
|
|
15
|
+
*/
|
|
16
|
+
export declare function generateDocx(blocks: DocxBlock[], props: DocxProps): Promise<Buffer>;
|
|
17
|
+
//# sourceMappingURL=generate.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal bounded ZIP reader over `yauzl`: extracts every entry of a docx
|
|
3
|
+
* package into a name в†’ bytes map. The uncompressed total is capped so a
|
|
4
|
+
* compressed bomb inside an already-bounded file cannot expand without limit.
|
|
5
|
+
* @module dsh-tool-docx/zip
|
|
6
|
+
*/
|
|
7
|
+
import { Buffer } from 'node:buffer';
|
|
8
|
+
/** All entries of one ZIP archive, keyed by their archive names. */
|
|
9
|
+
export type ZipEntries = Map<string, Buffer>;
|
|
10
|
+
/**
|
|
11
|
+
* Read every file entry of a ZIP buffer into memory.
|
|
12
|
+
* @param data - the whole archive bytes (already bounded by the caller's read cap).
|
|
13
|
+
* @param maxUncompressedBytes - inclusive cap on the total uncompressed content.
|
|
14
|
+
* @returns archive-name в†’ content, directory entries omitted.
|
|
15
|
+
*/
|
|
16
|
+
export declare function readZip(data: Uint8Array, maxUncompressedBytes: number): Promise<ZipEntries>;
|
|
17
|
+
//# sourceMappingURL=zip.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error vocabulary for the docx tools: a stable machine-routable code
|
|
3
|
+
* distinct from the human-readable message, plus the mapping from the
|
|
4
|
+
* filesystem seam's `FsError` codes.
|
|
5
|
+
* @module dsh-tool-docx/error
|
|
6
|
+
*/
|
|
7
|
+
import { HarnessError } from '@deepseek-ai/dsh-llm';
|
|
8
|
+
/** Stable, machine-routable failure classes raised by the docx tool suite. */
|
|
9
|
+
export type DocxErrorCode = 'DOCX_NOT_FOUND' | 'DOCX_NOT_REGULAR_FILE' | 'DOCX_TOO_LARGE' | 'DOCX_INPUT_TOO_LARGE' | 'DOCX_LEGACY_DOC' | 'DOCX_NOT_DOCX' | 'DOCX_ENCRYPTED' | 'DOCX_PARSE_ERROR' | 'DOCX_EXISTS' | 'DOCX_STALE' | 'DOCX_SANDBOX_DENIED' | 'DOCX_WRITE_ERROR' | 'DOCX_HOST_FS_UNSUPPORTED';
|
|
10
|
+
/** Typed docx failure. Extends {@link HarnessError} for a stable code and `cause` chaining. */
|
|
11
|
+
export declare class DocxError extends HarnessError {
|
|
12
|
+
readonly code: DocxErrorCode;
|
|
13
|
+
constructor(message: string, code: DocxErrorCode, options?: ErrorOptions);
|
|
14
|
+
}
|
|
15
|
+
/** Map a filesystem-seam failure to the docx vocabulary; other errors pass through.
|
|
16
|
+
* @param error - the thrown filesystem error (or any other value).
|
|
17
|
+
* @returns the mapped `DocxError`, or the original value when it is not an `FsError`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function mapFsError(error: unknown): unknown;
|
|
20
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `fs-binary-local-plugin` — the mount for minimal hosts without a sandbox
|
|
3
|
+
* policy: a namespace plugin that registers the binary write primitive as the
|
|
4
|
+
* SEPARATE `fsBinary` service, unfenced, over the host's own `ctx.fs`. The
|
|
5
|
+
* host filesystem is left untouched. Sandboxed hosts should mount
|
|
6
|
+
* `fs-binary-sandbox-plugin` instead, which applies the policy fence.
|
|
7
|
+
* @module dsh-tool-docx/fs-binary-local-plugin
|
|
8
|
+
*/
|
|
9
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
10
|
+
/** Cordis plugin name used by loader diagnostics. */
|
|
11
|
+
export declare const name = "fs-binary-local";
|
|
12
|
+
/** Services required: the host filesystem (reads/stat/resolve and the write body). */
|
|
13
|
+
export declare const inject: string[];
|
|
14
|
+
/**
|
|
15
|
+
* Register the `fsBinary` service: unfenced binary writes over `ctx.fs`.
|
|
16
|
+
* @param ctx - the plugin context; execution uses its `fs` service.
|
|
17
|
+
*/
|
|
18
|
+
export declare function apply(ctx: Context): void;
|
|
19
|
+
//# sourceMappingURL=fs-binary-local-plugin.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The plugin's own distribution of the harness's binary filesystem seam: a
|
|
3
|
+
* local `ctx.fs` provider that adds the `writeBytes` primitive to the
|
|
4
|
+
* published `@deepseek-ai/dsh-fs-local` backend. Mount this plugin as `ctx.fs`
|
|
5
|
+
* (in place of `dsh-fs-local`) on a host whose filesystem seam lacks
|
|
6
|
+
* `writeBytes`; the docx tools then run unchanged, with the same
|
|
7
|
+
* probe → intent-guard → atomic-publish flow the harness seam provides.
|
|
8
|
+
*
|
|
9
|
+
* For a sandboxed host (a `SandboxedFileSystem` mounted as `ctx.fs`), mount
|
|
10
|
+
* `dsh-tool-docx/fs-binary-sandbox` instead — it preserves the policy fence.
|
|
11
|
+
* @module dsh-tool-docx/fs-binary-local
|
|
12
|
+
*/
|
|
13
|
+
import type { FsInfo, FsTarget, FsWriteIntent } from '@deepseek-ai/dsh-fs';
|
|
14
|
+
import { LocalFileSystem } from '@deepseek-ai/dsh-fs-local';
|
|
15
|
+
import type { FsBytesWriteOutcome } from './fs-binary.ts';
|
|
16
|
+
/**
|
|
17
|
+
* The probe → intent-guard → atomic-publish body shared by the plugin's binary
|
|
18
|
+
* fs providers: stat the target, enforce the version/absence intent
|
|
19
|
+
* (`FS_STALE_VERSION` / `FS_NOT_OBSERVED`), publish atomically, and report the
|
|
20
|
+
* fresh version.
|
|
21
|
+
* @param provider - the filesystem whose `stat` observes the target (the
|
|
22
|
+
* provider itself, after any sandbox fence has run).
|
|
23
|
+
* @param target - the (possibly fence-checked) target to write.
|
|
24
|
+
* @param data - the raw bytes to write.
|
|
25
|
+
* @param expected - the write intent guarding the write; omit for unconditional.
|
|
26
|
+
* @param signal - cancellation.
|
|
27
|
+
* @returns the create/update outcome with the fresh version.
|
|
28
|
+
*/
|
|
29
|
+
export declare function performByteWrite(provider: {
|
|
30
|
+
stat(target: FsTarget, signal?: AbortSignal): Promise<FsInfo | undefined>;
|
|
31
|
+
}, target: FsTarget, data: Uint8Array, expected: FsWriteIntent | undefined, signal: AbortSignal | undefined): Promise<FsBytesWriteOutcome>;
|
|
32
|
+
/**
|
|
33
|
+
* The local filesystem backend with the binary write primitive. Inherits the
|
|
34
|
+
* full published `LocalFileSystem` contract (text reads/writes, `readBytes`,
|
|
35
|
+
* intent handling) and adds `writeBytes`. Per-targetKey operations are
|
|
36
|
+
* serialized with a tail promise, mirroring the backend's own lock discipline.
|
|
37
|
+
*/
|
|
38
|
+
export declare class DocxBinaryFileSystem extends LocalFileSystem {
|
|
39
|
+
private readonly byteLocks;
|
|
40
|
+
private withByteLock;
|
|
41
|
+
/** Write raw bytes with an optional version/absence guard. */
|
|
42
|
+
writeBytes(target: FsTarget, data: Uint8Array, expected?: FsWriteIntent, signal?: AbortSignal): Promise<FsBytesWriteOutcome>;
|
|
43
|
+
}
|
|
44
|
+
export default DocxBinaryFileSystem;
|
|
45
|
+
//# sourceMappingURL=fs-binary-local.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `fs-binary-sandbox-plugin` — the recommended mount for sandboxed hosts: a
|
|
3
|
+
* namespace plugin that registers the binary write primitive as the SEPARATE
|
|
4
|
+
* `fsBinary` service, fenced by the same per-call policy as the harness's
|
|
5
|
+
* `fs-sandbox` mutations. The host's own `ctx.fs` (and its `fs-sandbox` row)
|
|
6
|
+
* is left untouched, so this plugin can never break the host filesystem — at
|
|
7
|
+
* worst the docx write tools report `DOCX_HOST_FS_UNSUPPORTED` when it is not
|
|
8
|
+
* mounted.
|
|
9
|
+
* @module dsh-tool-docx/fs-binary-sandbox-plugin
|
|
10
|
+
*/
|
|
11
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
12
|
+
/** Cordis plugin name used by loader diagnostics. */
|
|
13
|
+
export declare const name = "fs-binary-sandbox";
|
|
14
|
+
/** Services required: the host filesystem (reads/stat/resolve) and the policy. */
|
|
15
|
+
export declare const inject: string[];
|
|
16
|
+
/**
|
|
17
|
+
* Register the `fsBinary` service: fenced binary writes through the same
|
|
18
|
+
* containment the sandbox applies to every mutation.
|
|
19
|
+
* @param ctx - the plugin context; execution uses its `fs` and `sandboxPolicy`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function apply(ctx: Context): void;
|
|
22
|
+
//# sourceMappingURL=fs-binary-sandbox-plugin.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sandbox-preserving binary fs provider: `DocxSandboxedFileSystem` extends
|
|
3
|
+
* the published `@deepseek-ai/dsh-fs-sandbox` `SandboxedFileSystem` and adds the
|
|
4
|
+
* binary `writeBytes` primitive through the SAME policy fence as the base's
|
|
5
|
+
* `writeText`/`editText`. The fence itself (`checkWriteTarget`) is shared with
|
|
6
|
+
* the `fs-binary-sandbox-plugin` namespace plugin, which registers it as the
|
|
7
|
+
* separate `fsBinary` service — the recommended mount for sandboxed hosts,
|
|
8
|
+
* because it never replaces the host's own `ctx.fs`.
|
|
9
|
+
* @module dsh-tool-docx/fs-binary-sandbox
|
|
10
|
+
*/
|
|
11
|
+
import { type FsTarget, type FsWriteIntent } from '@deepseek-ai/dsh-fs';
|
|
12
|
+
import { SandboxedFileSystem } from '@deepseek-ai/dsh-fs-sandbox';
|
|
13
|
+
import { type SandboxExecutionPolicy } from '@deepseek-ai/dsh-sandbox';
|
|
14
|
+
import type { FsBytesWriteOutcome } from './fs-binary.ts';
|
|
15
|
+
/**
|
|
16
|
+
* Enforce the per-call policy against `target` and return the exact target the
|
|
17
|
+
* mutation must use — the same containment the base `SandboxedFileSystem`
|
|
18
|
+
* applies to its mutations (`danger-full-access` passes unfenced, `read-only`
|
|
19
|
+
* denies, `workspace-write` re-canonicalizes now and requires containment under
|
|
20
|
+
* a writable root). Throws `FS_SANDBOX_DENIED` on refusal.
|
|
21
|
+
* @param resolveTarget - resolves a display path to a fresh canonical target
|
|
22
|
+
* (the provider's own `resolve`, so the checked identity is the mutated one).
|
|
23
|
+
* @param policy - the per-call mode and workspace root.
|
|
24
|
+
* @param target - the caller's resolved target.
|
|
25
|
+
* @returns the fresh target the mutation must use.
|
|
26
|
+
*/
|
|
27
|
+
export declare function checkWriteTarget(resolveTarget: (displayPath: string) => Promise<FsTarget>, policy: SandboxExecutionPolicy, target: FsTarget): Promise<FsTarget>;
|
|
28
|
+
/**
|
|
29
|
+
* The sandboxed filesystem backend with the binary write primitive. Inherits
|
|
30
|
+
* the full `SandboxedFileSystem` contract (local text/binary reads, fenced
|
|
31
|
+
* `writeText`/`editText`) and adds fenced `writeBytes`: the per-call policy
|
|
32
|
+
* fence runs first (the same containment check the base applies to mutations),
|
|
33
|
+
* then the probe → intent-guard → atomic-publish body. Per-targetKey
|
|
34
|
+
* operations are serialized with a tail promise. Intended for hosts that want
|
|
35
|
+
* the full backend mounted AS `ctx.fs` (replacing `fs-sandbox` deliberately);
|
|
36
|
+
* the default mount for sandboxed hosts is the `fs-binary-sandbox-plugin`,
|
|
37
|
+
* which registers this same fenced write under the separate `fsBinary` service.
|
|
38
|
+
*/
|
|
39
|
+
export declare class DocxSandboxedFileSystem extends SandboxedFileSystem {
|
|
40
|
+
private readonly byteLocks;
|
|
41
|
+
private withByteLock;
|
|
42
|
+
/**
|
|
43
|
+
* Enforce the per-call policy against `target` and return the exact target
|
|
44
|
+
* the mutation must use, via the shared {@link checkWriteTarget}.
|
|
45
|
+
*/
|
|
46
|
+
private checkedWriteTarget;
|
|
47
|
+
/** Write raw bytes with an optional version/absence guard, through the policy fence. */
|
|
48
|
+
writeBytes(target: FsTarget, data: Uint8Array, expected?: FsWriteIntent, signal?: AbortSignal, sandboxPolicy?: SandboxExecutionPolicy): Promise<FsBytesWriteOutcome>;
|
|
49
|
+
}
|
|
50
|
+
export default DocxSandboxedFileSystem;
|
|
51
|
+
//# sourceMappingURL=fs-binary-sandbox.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The binary filesystem contract the docx tools require.
|
|
3
|
+
*
|
|
4
|
+
* The plugin reads whole `.docx` packages through `readBytes` and writes them
|
|
5
|
+
* through `writeBytes`. `readBytes` is part of the published `@deepseek-ai/dsh-fs`
|
|
6
|
+
* contract since `0.1.0-rc.7`, so every conforming host provides it on `ctx.fs`.
|
|
7
|
+
* `writeBytes` is NOT part of any published `dsh-fs` release yet, so the plugin
|
|
8
|
+
* ships its own binary providers (`dsh-tool-docx/fs-binary-sandbox-plugin` for
|
|
9
|
+
* sandboxed hosts, `dsh-tool-docx/fs-binary-local-plugin` for minimal hosts)
|
|
10
|
+
* that register a SEPARATE `fsBinary` service — the host's `ctx.fs` is never
|
|
11
|
+
* replaced or modified. A host that natively gained `writeBytes` is used
|
|
12
|
+
* directly. This module declares the extended contract and resolves the writer
|
|
13
|
+
* at call time, so a host without any binary writer fails with a clear typed
|
|
14
|
+
* error instead of a cryptic `fs.writeBytes is not a function`.
|
|
15
|
+
* @module dsh-tool-docx/fs-binary
|
|
16
|
+
*/
|
|
17
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
18
|
+
import { FileSystem, type FsTarget, type FsVersion, type FsWriteIntent } from '@deepseek-ai/dsh-fs';
|
|
19
|
+
/** The outcome of a binary write, mirroring the host seam's `FsBytesWriteOutcome`. */
|
|
20
|
+
export interface FsBytesWriteOutcome {
|
|
21
|
+
/** Whether the write created a new file or updated an existing one. */
|
|
22
|
+
operation: 'create' | 'update';
|
|
23
|
+
/** The new file version after the write. */
|
|
24
|
+
version: FsVersion;
|
|
25
|
+
}
|
|
26
|
+
/** The binary write surface the docx tools need, wherever it comes from. */
|
|
27
|
+
export type FsBytesWriter = (target: FsTarget, data: Uint8Array, expected?: FsWriteIntent, signal?: AbortSignal, sandboxPolicy?: unknown) => Promise<FsBytesWriteOutcome>;
|
|
28
|
+
/** A host filesystem that additionally provides the binary read/write primitives. */
|
|
29
|
+
export declare abstract class BinaryFileSystem extends FileSystem {
|
|
30
|
+
/** Read the whole file as bytes, bounded by `maxBytes`. */
|
|
31
|
+
abstract readBytes(target: FsTarget, signal: AbortSignal | undefined, maxBytes: number): Promise<Uint8Array>;
|
|
32
|
+
/** Write raw bytes with an optional version/intent guard. */
|
|
33
|
+
abstract writeBytes(target: FsTarget, data: Uint8Array, expected?: FsWriteIntent, signal?: AbortSignal, sandboxPolicy?: unknown): Promise<FsBytesWriteOutcome>;
|
|
34
|
+
}
|
|
35
|
+
/** The service name the plugin's binary providers register under. */
|
|
36
|
+
export declare const FS_BINARY_SERVICE = "fsBinary";
|
|
37
|
+
/**
|
|
38
|
+
* Resolve the binary writer for this context: the plugin's `fsBinary` service
|
|
39
|
+
* when mounted, else a host `ctx.fs` that natively provides `writeBytes`.
|
|
40
|
+
* @param ctx - the plugin context; `fsBinary` is resolved optionally.
|
|
41
|
+
* @returns the bound writer, or `undefined` when no binary writer is mounted.
|
|
42
|
+
*/
|
|
43
|
+
export declare function resolveWriteBytes(ctx: Context): FsBytesWriter | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Resolve the binary writer or fail with the typed host-requirement error.
|
|
46
|
+
* @param ctx - the plugin context.
|
|
47
|
+
* @returns the bound writer.
|
|
48
|
+
* @throws `DOCX_HOST_FS_UNSUPPORTED` when neither the `fsBinary` service nor a
|
|
49
|
+
* native `ctx.fs.writeBytes` is available.
|
|
50
|
+
*/
|
|
51
|
+
export declare function requireWriteBytes(ctx: Context): FsBytesWriter;
|
|
52
|
+
//# sourceMappingURL=fs-binary.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal atomic binary write for the plugin's local filesystem provider.
|
|
3
|
+
* Mirrors the deepseek-harness `fs-local` `writeFileAtomic` semantics — a
|
|
4
|
+
* private owner-only staging directory, an exclusive temp file, fsync, then an
|
|
5
|
+
* atomic publish; a `createIfAbsent` publish uses a hard-link no-replace
|
|
6
|
+
* primitive so a concurrent creator wins (`FS_NOT_OBSERVED`) — for a
|
|
7
|
+
* `Uint8Array` payload. The Win32 DACL-preservation ceremony of the harness
|
|
8
|
+
* original is intentionally omitted in this first version (a replacement
|
|
9
|
+
* inherits the temp file's owner-only ACL).
|
|
10
|
+
* @module dsh-tool-docx/fsio-bytes
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Atomically write raw bytes to `absolutePath`: stage an owner-only temp file
|
|
14
|
+
* in a private sibling directory, fsync, then publish. With `createIfAbsent`,
|
|
15
|
+
* publish uses a hard link that fails if the target appeared concurrently
|
|
16
|
+
* (`FS_NOT_OBSERVED`); otherwise the temp is renamed over the target.
|
|
17
|
+
* @param absolutePath - destination path (typically a target key); missing
|
|
18
|
+
* parent directories are created.
|
|
19
|
+
* @param data - the raw bytes to write.
|
|
20
|
+
* @param signal - cancellation checked before and during the write.
|
|
21
|
+
* @param createIfAbsent - when provided, publish with the no-replace primitive
|
|
22
|
+
* and reject a concurrent creator with `FS_NOT_OBSERVED`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function writeFileAtomicBytes(absolutePath: string, data: Uint8Array, signal: AbortSignal | undefined, createIfAbsent?: {
|
|
25
|
+
displayPath: string;
|
|
26
|
+
}): Promise<void>;
|
|
27
|
+
//# sourceMappingURL=fsio-bytes.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing Microsoft Word (.docx) tools: `docx_read` (docx → Markdown or
|
|
3
|
+
* structured JSON blocks), `docx_create` (Markdown → new docx), and
|
|
4
|
+
* `docx_edit` (round-trip Markdown replacement preserving document
|
|
5
|
+
* properties). Reading uses the bounded `ctx.fs.readBytes` primitive (part of
|
|
6
|
+
* the published filesystem contract since rc.7); creating and editing use a
|
|
7
|
+
* binary writer resolved at call time — the plugin's `fsBinary` service
|
|
8
|
+
* (`dsh-tool-docx/fs-binary-sandbox-plugin` / `fs-binary-local-plugin`) or a
|
|
9
|
+
* host `ctx.fs` that natively provides `writeBytes` — so the sandbox fence and
|
|
10
|
+
* observation policy apply to docx mutations exactly as they do to text
|
|
11
|
+
* writes, without ever replacing the host's own `ctx.fs`.
|
|
12
|
+
* @module dsh-tool-docx
|
|
13
|
+
*/
|
|
14
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
15
|
+
import z from '@deepseek-ai/schemastery';
|
|
16
|
+
/** Cordis plugin name used by loader diagnostics. */
|
|
17
|
+
export declare const name = "tool-docx";
|
|
18
|
+
/** Services required by the docx tool suite. */
|
|
19
|
+
export declare const inject: string[];
|
|
20
|
+
/** Plugin config (all optional — `Config` supplies the defaults). */
|
|
21
|
+
export interface Config {
|
|
22
|
+
/** Inclusive byte cap on a whole `.docx` file (read + ZIP expansion). */
|
|
23
|
+
maxDocxBytes?: number;
|
|
24
|
+
/** Inclusive character cap on the markdown input to create/edit. */
|
|
25
|
+
maxMarkdownChars?: number;
|
|
26
|
+
/** Inclusive character cap on the markdown returned by `docx_read`. */
|
|
27
|
+
maxReadChars?: number;
|
|
28
|
+
}
|
|
29
|
+
export declare const Config: z<Config>;
|
|
30
|
+
/** Register the full `docx_read`/`docx_create`/`docx_edit` tool suite. */
|
|
31
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned invariant companion for `dsh-tool-docx`.
|
|
3
|
+
* @module dsh-tool-docx/invariant
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
6
|
+
/** Cordis companion plugin name. */
|
|
7
|
+
export declare const name = "tool-docx-invariant";
|
|
8
|
+
/** Service required before the companion can reserve package ownership. */
|
|
9
|
+
export declare const inject: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Register this package's invariant companion.
|
|
12
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
13
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
14
|
+
*/
|
|
15
|
+
export declare const apply: (ctx: Context) => Promise<() => void>;
|
|
16
|
+
//# sourceMappingURL=invariant.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown в†’ block parsing for the docx generator: headings, paragraphs,
|
|
3
|
+
* nested lists, pipe tables, and inline formatting (`**bold**`, `*italic*`,
|
|
4
|
+
* `` `code` ``, `~~strike~~`, `[text](url)`). The supported subset is
|
|
5
|
+
* deliberately small and matches what {@link extractDocx} emits, so a
|
|
6
|
+
* read в†’ edit в†’ write round trip is stable. Unsupported constructs degrade to
|
|
7
|
+
* paragraphs with a warning instead of failing.
|
|
8
|
+
* @module dsh-tool-docx/markdown
|
|
9
|
+
*/
|
|
10
|
+
import type { DocxBlock } from './types.ts';
|
|
11
|
+
/** One inline segment of a paragraph/heading/cell. */
|
|
12
|
+
export interface InlineSegment {
|
|
13
|
+
text: string;
|
|
14
|
+
bold?: boolean;
|
|
15
|
+
italic?: boolean;
|
|
16
|
+
code?: boolean;
|
|
17
|
+
strike?: boolean;
|
|
18
|
+
/** External link target when the segment came from `[text](url)`. */
|
|
19
|
+
link?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Split inline text into styled segments. Bare asterisks, unterminated
|
|
23
|
+
* markers, and stray brackets stay literal text.
|
|
24
|
+
* @param text - inline markdown text (escapes from extraction are unescaped).
|
|
25
|
+
* @returns ordered segments; adjacent plain text is not merged.
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseInline(text: string): InlineSegment[];
|
|
28
|
+
/**
|
|
29
|
+
* Parse a markdown document into structured blocks.
|
|
30
|
+
* @param markdown - the markdown source (must fit the caller's input cap).
|
|
31
|
+
* @param warnings - receives human-readable notes about unsupported constructs.
|
|
32
|
+
* @returns the blocks the generator renders; an empty document yields `[]`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseMarkdown(markdown: string, warnings: string[]): DocxBlock[];
|
|
35
|
+
//# sourceMappingURL=markdown.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Path-containment mechanics for the plugin's sandboxed filesystem provider —
|
|
3
|
+
* ported from the deepseek-harness `fs-sandbox` package (MIT, see LICENSE):
|
|
4
|
+
* the lexical fast path handles canonical spellings, and filesystem identity
|
|
5
|
+
* supplies the conservative fallback for alias-equivalent roots (Windows 8.3
|
|
6
|
+
* names, casing).
|
|
7
|
+
* @module dsh-tool-docx/path-contains
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Determine whether a canonical target is a writable root or lies beneath it.
|
|
11
|
+
* The lexical fast path handles normal canonical spellings; when spellings
|
|
12
|
+
* differ, walk the target's existing ancestors and compare filesystem identity
|
|
13
|
+
* with the root.
|
|
14
|
+
* @param path - canonical target key, which may end in a missing suffix.
|
|
15
|
+
* @param root - canonical writable root.
|
|
16
|
+
* @param caseSensitive - whether lexical comparison preserves case; defaults
|
|
17
|
+
* to the host filesystem convention used by supported platforms.
|
|
18
|
+
* @returns whether the target is the root or a descendant of it.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isPathUnder(path: string, root: string, caseSensitive?: boolean): Promise<boolean>;
|
|
21
|
+
//# sourceMappingURL=path-contains.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sandbox-escalation API for the mutating docx tools: per-call policy
|
|
3
|
+
* resolution, advertised escalation fields, and denial-marker mapping — the
|
|
4
|
+
* same pieces `dsh-tool-fs` uses, so docx mutations escalate identically to
|
|
5
|
+
* bash and fs. Built ONCE per plugin from `ctx.fs.sandboxMode`.
|
|
6
|
+
*
|
|
7
|
+
* This mirrors `packages/fs/tool-fs/src/sandbox.ts`; extracting a shared
|
|
8
|
+
* controller is deferred work (see the package README).
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-tool-docx/sandbox
|
|
11
|
+
*/
|
|
12
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
13
|
+
import type { ToolExecution } from '@deepseek-ai/dsh-tools';
|
|
14
|
+
import type { SandboxExecutionPolicy, SandboxMode } from '@deepseek-ai/dsh-sandbox';
|
|
15
|
+
/** The two escalation arguments a mutating tool may carry. */
|
|
16
|
+
export interface DocxEscalationArgs {
|
|
17
|
+
sandbox_permissions?: string;
|
|
18
|
+
justification?: string;
|
|
19
|
+
}
|
|
20
|
+
/** The schema fields spread into a mutating tool's `parameters` under a confining backend. */
|
|
21
|
+
export interface EscalationSchemaFields {
|
|
22
|
+
sandbox_permissions: {
|
|
23
|
+
type: 'string';
|
|
24
|
+
enum: string[];
|
|
25
|
+
description: string;
|
|
26
|
+
};
|
|
27
|
+
justification: {
|
|
28
|
+
type: 'string';
|
|
29
|
+
description: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** The docx escalation API: advertisement gating, policy resolution, and denial mapping. */
|
|
33
|
+
export declare class DocxSandboxController {
|
|
34
|
+
private readonly ctx;
|
|
35
|
+
/** Escalation targets this composition advertises (`[]` when no confining backend is mounted). */
|
|
36
|
+
readonly escalationModes: readonly SandboxMode[];
|
|
37
|
+
private readonly policy;
|
|
38
|
+
constructor(ctx: Context);
|
|
39
|
+
/**
|
|
40
|
+
* The escalation schema fields for a mutating tool's `parameters` (confining backend only).
|
|
41
|
+
* @returns the two escalation parameter specs.
|
|
42
|
+
*/
|
|
43
|
+
schemaFields(): EscalationSchemaFields;
|
|
44
|
+
/**
|
|
45
|
+
* The policy to stamp onto this mutation: an approved escalation grant, else
|
|
46
|
+
* the session's standing mode (with the session cwd as the workspace root).
|
|
47
|
+
* @param toolName - the mutating tool's name, for the approval audit trail.
|
|
48
|
+
* @param args - the call's escalation arguments.
|
|
49
|
+
* @param exec - the tool-execution context.
|
|
50
|
+
* @returns the policy for the mutation, or undefined for an unsandboxed backend.
|
|
51
|
+
*/
|
|
52
|
+
resolvePolicy(toolName: string, args: DocxEscalationArgs, exec: ToolExecution): Promise<SandboxExecutionPolicy | undefined>;
|
|
53
|
+
/**
|
|
54
|
+
* Map a thrown provider error for the model: a `FS_SANDBOX_DENIED` becomes a
|
|
55
|
+
* `DocxError` carrying the shared `[sandbox: …]` marker plus the same-turn
|
|
56
|
+
* escalation hint (keeping the structured `DOCX_SANDBOX_DENIED` code).
|
|
57
|
+
* @param error - the error thrown by the mutation.
|
|
58
|
+
* @param policy - the policy stamped onto the call.
|
|
59
|
+
* @returns the error to throw.
|
|
60
|
+
*/
|
|
61
|
+
mapError(error: unknown, policy: SandboxExecutionPolicy | undefined): unknown;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=sandbox.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for the docx tools: path/extension validation, session-cwd
|
|
3
|
+
* resolution, observed-state emission, and common argument validation.
|
|
4
|
+
* @module dsh-tool-docx/tool-utils
|
|
5
|
+
*/
|
|
6
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
7
|
+
import type { ToolExecution } from '@deepseek-ai/dsh-tools';
|
|
8
|
+
import type { FsTarget, FsVersion } from '@deepseek-ai/dsh-fs';
|
|
9
|
+
/**
|
|
10
|
+
* Reject `.doc` with the legacy hint; everything else is parsed by content.
|
|
11
|
+
* @param path - the file path to check.
|
|
12
|
+
*/
|
|
13
|
+
export declare function assertSupportedExtension(path: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Validate a non-empty file path; whitespace-only paths are rejected like the fs tool suite.
|
|
16
|
+
* @param path - the raw tool argument.
|
|
17
|
+
* @returns the same path, confirmed non-blank.
|
|
18
|
+
*/
|
|
19
|
+
export declare function requirePath(path: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* The calling agent's session cwd, or undefined for a non-agent caller.
|
|
22
|
+
* @param exec - the tool-execution context; only its optional `agent` is read.
|
|
23
|
+
* @returns the agent's session workspace cwd, or undefined.
|
|
24
|
+
*/
|
|
25
|
+
export declare function sessionCwd(exec: ToolExecution): string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Resolution options for the current call: session cwd + cancellation.
|
|
28
|
+
* @param exec - the tool-execution context supplying session cwd and cancellation.
|
|
29
|
+
* @returns provider resolution options for the current tool call.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveOptions(exec: ToolExecution): {
|
|
32
|
+
cwd?: string;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Record an authoritative positive observation (no-op when no policy listens).
|
|
37
|
+
* @param ctx - the Cordis context the event is emitted on.
|
|
38
|
+
* @param target - the observed target.
|
|
39
|
+
* @param version - the observed file version.
|
|
40
|
+
* @param exec - the tool-execution context, carried as the event actor.
|
|
41
|
+
*/
|
|
42
|
+
export declare function emitObserved(ctx: Context, target: FsTarget, version: FsVersion, exec: ToolExecution): void;
|
|
43
|
+
/**
|
|
44
|
+
* Record a confirmed-absent observation (no-op when no policy listens).
|
|
45
|
+
* @param ctx - the Cordis context the event is emitted on.
|
|
46
|
+
* @param target - the observed (absent) target.
|
|
47
|
+
* @param exec - the tool-execution context, carried as the event actor.
|
|
48
|
+
*/
|
|
49
|
+
export declare function emitAbsent(ctx: Context, target: FsTarget, exec: ToolExecution): void;
|
|
50
|
+
/**
|
|
51
|
+
* Validate a positive-integer cap from config.
|
|
52
|
+
* @param name - the config field name, for the error message.
|
|
53
|
+
* @param value - the configured value to validate.
|
|
54
|
+
*/
|
|
55
|
+
export declare function assertPositiveInteger(name: string, value: number): void;
|
|
56
|
+
//# sourceMappingURL=tool-utils.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing `docx_create`: generate a new `.docx` file from Markdown.
|
|
3
|
+
* Guarded with `createIfAbsent` by default so an existing file is never
|
|
4
|
+
* blindly overwritten (the observation-policy waterfall may supply its own
|
|
5
|
+
* intent).
|
|
6
|
+
* @module dsh-tool-docx/tools/create
|
|
7
|
+
*/
|
|
8
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
9
|
+
import type { DocxToolCaps } from '../caps.ts';
|
|
10
|
+
import { DocxSandboxController } from '../sandbox.ts';
|
|
11
|
+
/**
|
|
12
|
+
* Register the `docx_create` tool.
|
|
13
|
+
* @param ctx - the plugin context; execution uses its `fs` service for
|
|
14
|
+
* resolution/reads and the `fsBinary` binary writer for the mutation.
|
|
15
|
+
* @param caps - the deployment's resolved caps.
|
|
16
|
+
* @param sandbox - the shared sandbox-escalation API.
|
|
17
|
+
*/
|
|
18
|
+
export declare function applyCreateTool(ctx: Context, caps: DocxToolCaps, sandbox: DocxSandboxController): void;
|
|
19
|
+
//# sourceMappingURL=create.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing `docx_edit`: replace a `.docx` document's content from
|
|
3
|
+
* Markdown, preserving its title/author/created properties. Reads the current
|
|
4
|
+
* file (validating it is a docx), regenerates the body, and writes back with a
|
|
5
|
+
* version guard so a concurrent change reports `DOCX_STALE`.
|
|
6
|
+
* @module dsh-tool-docx/tools/edit
|
|
7
|
+
*/
|
|
8
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
9
|
+
import type { DocxToolCaps } from '../caps.ts';
|
|
10
|
+
import { DocxSandboxController } from '../sandbox.ts';
|
|
11
|
+
/**
|
|
12
|
+
* Register the `docx_edit` tool.
|
|
13
|
+
* @param ctx - the plugin context; execution uses its `fs` service for
|
|
14
|
+
* resolution/reads and the `fsBinary` binary writer for the mutation.
|
|
15
|
+
* @param caps - the deployment's resolved caps.
|
|
16
|
+
* @param sandbox - the shared sandbox-escalation API.
|
|
17
|
+
*/
|
|
18
|
+
export declare function applyEditTool(ctx: Context, caps: DocxToolCaps, sandbox: DocxSandboxController): void;
|
|
19
|
+
//# sourceMappingURL=edit.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing `docx_read`: extract a `.docx` file as Markdown or structured
|
|
3
|
+
* JSON blocks. Bounded by the configured byte cap (whole file), the ZIP
|
|
4
|
+
* expansion cap, and the returned-markdown character cap.
|
|
5
|
+
* @module dsh-tool-docx/tools/read
|
|
6
|
+
*/
|
|
7
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
8
|
+
import type { DocxToolCaps } from '../caps.ts';
|
|
9
|
+
/**
|
|
10
|
+
* Register the `docx_read` tool and its system-prompt guidance.
|
|
11
|
+
* @param ctx - the plugin context; execution uses its `fs` service (`readBytes`
|
|
12
|
+
* is part of the published filesystem contract since rc.7).
|
|
13
|
+
* @param caps - the deployment's resolved caps.
|
|
14
|
+
*/
|
|
15
|
+
export declare function applyReadTool(ctx: Context, caps: DocxToolCaps): void;
|
|
16
|
+
//# sourceMappingURL=read.d.ts.map
|