@ai-agent-forge/plugin-workspace-files-write 0.88.28 → 0.88.29
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/README.md +3 -4
- package/agent-forge.json +1 -1
- package/dist/capability.d.ts +1 -1
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +1 -3
- package/dist/capability.js.map +1 -1
- package/dist/entry.d.ts +1 -2
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +1 -2
- package/dist/entry.js.map +1 -1
- package/package.json +2 -2
- package/plugin.json +1 -1
package/README.md
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
# @agent-forge/plugin-workspace-files-write
|
|
2
2
|
|
|
3
3
|
Workspace file write capability plugin for [Agent Forge](https://github.com/agent-forge/agent-forge), extracted from
|
|
4
|
-
the host's `src/plugins/workspace-files-write` (D-075 S3). It registers
|
|
4
|
+
the host's `src/plugins/workspace-files-write` (D-075 S3). It registers the `workspace_write` tool, which
|
|
5
5
|
atomically replaces or patches a host-owned file using opaque file and artifact references; bytes and local paths never
|
|
6
6
|
cross the capability boundary.
|
|
7
7
|
|
|
8
8
|
The plugin is deliberately inert at load time. Without a host-bound write seam the tool reports an explicit
|
|
9
9
|
`unsupported` result; hosts that want real writes bind `createNodeWorkspaceFilesWriteHostAdapterV1` (sandboxed root,
|
|
10
|
-
artifact resolution, version-checked atomic commits) through their profile machinery.
|
|
11
|
-
registration at all.
|
|
10
|
+
artifact resolution, version-checked atomic commits) through their profile machinery.
|
|
12
11
|
|
|
13
12
|
## Install
|
|
14
13
|
|
|
@@ -31,7 +30,7 @@ The package ships two manifests: `agent-forge.json` (ecosystem manifest for the
|
|
|
31
30
|
returns `unsupported`.
|
|
32
31
|
- `createNodeWorkspaceFilesWriteHostAdapterV1({ root, resolveFileRef, readArtifact, ... })` — real sandboxed host
|
|
33
32
|
writer: atomic rename commits, expectedVersion checks, per-path single-flight serialization, `committed` reporting.
|
|
34
|
-
- `createWorkspaceFilesWriteCapabilityFactoryV1(adapter?)` — registers `workspace_write` on a
|
|
33
|
+
- `createWorkspaceFilesWriteCapabilityFactoryV1(adapter?)` — registers `workspace_write` on a
|
|
35
34
|
`CapabilityAPI` (defaults to the unbound adapter).
|
|
36
35
|
- Default export of `dist/entry.js` — the precomposed factory used by external plugin loading.
|
|
37
36
|
|
package/agent-forge.json
CHANGED
package/dist/capability.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CapabilityPluginSyncFactory } from "@agent-forge/plugin-sdk";
|
|
2
2
|
import type { WorkspaceFilesWriteAdapterV1 } from "./types.ts";
|
|
3
|
-
/** Registers opaque file writes and patches
|
|
3
|
+
/** Registers opaque file writes and patches. */
|
|
4
4
|
export declare function createWorkspaceFilesWriteCapabilityFactoryV1(runtime?: WorkspaceFilesWriteAdapterV1): CapabilityPluginSyncFactory;
|
|
5
5
|
//# sourceMappingURL=capability.d.ts.map
|
package/dist/capability.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAU3E,OAAO,KAAK,EACX,4BAA4B,EAI5B,MAAM,YAAY,CAAC;AA+GpB,
|
|
1
|
+
{"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAU3E,OAAO,KAAK,EACX,4BAA4B,EAI5B,MAAM,YAAY,CAAC;AA+GpB,gDAAgD;AAChD,wBAAgB,4CAA4C,CAC3D,OAAO,GAAE,4BAAuE,GAC9E,2BAA2B,CA+C7B","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { CapabilityPluginSyncFactory } from \"@agent-forge/plugin-sdk\";\nimport { Type } from \"typebox\";\nimport { Value } from \"typebox/value\";\nimport {\n\tcreateNodeWorkspaceFilesWriteAdapterV1,\n\tprojectWorkspaceFilesWriteV1,\n\tWORKSPACE_FILES_WRITE_MAX_OPERATION_ID_CHARS_V1,\n\tWORKSPACE_FILES_WRITE_MAX_REF_CHARS_V1,\n\tWORKSPACE_FILES_WRITE_MAX_VERSION_CHARS_V1,\n} from \"./node-adapter.ts\";\nimport type {\n\tWorkspaceFilesWriteAdapterV1,\n\tWorkspaceFilesWriteModeV1,\n\tWorkspaceFilesWriteRequestV1,\n\tWorkspaceFilesWriteResultV1,\n} from \"./types.ts\";\n\nconst refSchema = Type.String({\n\tminLength: 1,\n\tmaxLength: WORKSPACE_FILES_WRITE_MAX_REF_CHARS_V1,\n\tpattern: \"^[A-Za-z0-9][A-Za-z0-9._:-]*$\",\n});\nconst requestSchema = Type.Object(\n\t{\n\t\tfileRef: refSchema,\n\t\tmode: Type.Union([Type.Literal(\"replace\"), Type.Literal(\"patch\")]),\n\t\tsourceArtifactRef: refSchema,\n\t\texpectedVersion: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: WORKSPACE_FILES_WRITE_MAX_VERSION_CHARS_V1,\n\t\t\t\tpattern: \"^[A-Za-z0-9][A-Za-z0-9._:-]*$\",\n\t\t\t}),\n\t\t),\n\t\tcreateIfMissing: Type.Optional(Type.Boolean()),\n\t},\n\t{ additionalProperties: false },\n);\nconst inputSchema = Type.Object({ request: requestSchema }, { additionalProperties: false });\n\nfunction generatedOperationId(): string {\n\treturn `profile-runtime-tool-call-${randomUUID()}`;\n}\n\nfunction operationIdFor(first: unknown, second: unknown): string {\n\tconst explicit = second === undefined ? undefined : first;\n\treturn typeof explicit === \"string\" &&\n\t\texplicit.trim() !== \"\" &&\n\t\texplicit.length <= WORKSPACE_FILES_WRITE_MAX_OPERATION_ID_CHARS_V1\n\t\t? explicit\n\t\t: generatedOperationId();\n}\n\nfunction objectInput(first: unknown, second: unknown): Record<string, unknown> {\n\t// Shape-based dual-convention read (aligned with subagent-delegate): the\n\t// runtime invoke face passes the input object first and the host\n\t// CapabilityToolContext second; the agent tool face passes the tool call\n\t// id (a string) first and the params object second.\n\tconst value = first !== null && typeof first === \"object\" && !Array.isArray(first) ? first : second;\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value))\n\t\tthrow new Error(\"Write input must be an object\");\n\treturn value as Record<string, unknown>;\n}\n\nfunction signalFrom(value: unknown): AbortSignal | undefined {\n\treturn value instanceof AbortSignal ? value : undefined;\n}\n\nfunction fallback(\n\toperationId: string,\n\tstatus: \"failed\" | \"cancelled\",\n\trequest?: Partial<WorkspaceFilesWriteRequestV1>,\n): WorkspaceFilesWriteResultV1 {\n\treturn {\n\t\tversion: 1,\n\t\toperationId,\n\t\tstatus,\n\t\tfileRef: request?.fileRef ?? \"invalid:file\",\n\t\tmode: (request?.mode ?? \"replace\") as WorkspaceFilesWriteModeV1,\n\t\tchanged: false,\n\t\tbytesWritten: 0,\n\t\terror: {\n\t\t\tversion: 1,\n\t\t\tcode: status === \"cancelled\" ? \"cancelled\" : \"adapter_failed\",\n\t\t\tmessage: status === \"cancelled\" ? \"Workspace write was cancelled\" : \"Workspace writer failed\",\n\t\t},\n\t};\n}\n\nfunction invalidInput(operationId: string): WorkspaceFilesWriteResultV1 {\n\treturn {\n\t\t...fallback(operationId, \"failed\"),\n\t\terror: { version: 1, code: \"invalid_input\", message: \"Workspace write request was invalid\" },\n\t};\n}\n\nfunction cancelled(operationId: string, request?: Partial<WorkspaceFilesWriteRequestV1>): WorkspaceFilesWriteResultV1 {\n\treturn fallback(operationId, \"cancelled\", request);\n}\n\nfunction malformed(operationId: string, request?: Partial<WorkspaceFilesWriteRequestV1>): WorkspaceFilesWriteResultV1 {\n\treturn {\n\t\t...fallback(operationId, \"failed\", request),\n\t\terror: { version: 1, code: \"adapter_failed\", message: \"Workspace writer returned an invalid result\" },\n\t};\n}\n\nasync function runWithCancellation(\n\trun: () => Promise<WorkspaceFilesWriteResultV1>,\n\tsignal: AbortSignal | undefined,\n\toperationId: string,\n\trequest: WorkspaceFilesWriteRequestV1,\n): Promise<WorkspaceFilesWriteResultV1> {\n\tconst result = await run();\n\tif (!signal?.aborted || result.status === \"cancelled\") return result;\n\tconst replacement = cancelled(operationId, request);\n\t// An adapter that already committed the write must not lose that fact when\n\t// its result is converted to cancelled after an abort; a timeout result with\n\t// an unknown commit state must not degrade into a false \"nothing changed\".\n\tif (result.committed === \"unknown\" || result.changed === \"unknown\")\n\t\treturn { ...replacement, changed: \"unknown\", committed: \"unknown\" };\n\treturn result.committed === true\n\t\t? { ...replacement, committed: true, changed: result.changed, bytesWritten: result.bytesWritten }\n\t\t: replacement;\n}\n\n/** Registers opaque file writes and patches. */\nexport function createWorkspaceFilesWriteCapabilityFactoryV1(\n\truntime: WorkspaceFilesWriteAdapterV1 = createNodeWorkspaceFilesWriteAdapterV1(),\n): CapabilityPluginSyncFactory {\n\treturn (api) => {\n\t\tapi.registerTool({\n\t\t\tname: \"workspace_write\",\n\t\t\tlabel: \"Write workspace file\",\n\t\t\tdescription:\n\t\t\t\t\"Atomically replace or patch a host file. fileRef and sourceArtifactRef are opaque host handles; never construct; unbound hosts report unsupported (workspace_files_write_unavailable). Failure codes: invalid_input, cancelled/timeout (retry), version_conflict (resend expectedVersion), file_missing (set createIfMissing), read_failed, invalid_file_ref, sandbox_violation (request a new handle), artifact_budget_exceeded (smaller bytes), invalid_patch (ranges must fit), workspace_write_failed (errno in message), adapter_failed (retry), artifact_record_failed (committed true; bytes on disk)\",\n\t\t\tparameters: inputSchema,\n\t\t\texecute: async (first: unknown, second?: unknown, third?: unknown) => {\n\t\t\t\tconst operationId = operationIdFor(first, second);\n\t\t\t\tlet input: Record<string, unknown>;\n\t\t\t\ttry {\n\t\t\t\t\tinput = objectInput(first, second);\n\t\t\t\t\tif (!Value.Check(inputSchema, input)) return invalidInput(operationId);\n\t\t\t\t} catch {\n\t\t\t\t\treturn invalidInput(operationId);\n\t\t\t\t}\n\t\t\t\tconst requestInput = input.request as Record<string, unknown>;\n\t\t\t\tconst request: WorkspaceFilesWriteRequestV1 = {\n\t\t\t\t\tversion: 1,\n\t\t\t\t\toperationId,\n\t\t\t\t\tfileRef: requestInput.fileRef as string,\n\t\t\t\t\tmode: requestInput.mode as WorkspaceFilesWriteModeV1,\n\t\t\t\t\tsourceArtifactRef: requestInput.sourceArtifactRef as string,\n\t\t\t\t\t...(requestInput.expectedVersion === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { expectedVersion: requestInput.expectedVersion as string }),\n\t\t\t\t\t...(requestInput.createIfMissing === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { createIfMissing: requestInput.createIfMissing as boolean }),\n\t\t\t\t};\n\t\t\t\tconst signal = signalFrom(third);\n\t\t\t\tif (signal?.aborted) return cancelled(operationId, request);\n\t\t\t\ttry {\n\t\t\t\t\tconst output = await runWithCancellation(\n\t\t\t\t\t\t() => runtime.write(request, signal),\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\toperationId,\n\t\t\t\t\t\trequest,\n\t\t\t\t\t);\n\t\t\t\t\treturn projectWorkspaceFilesWriteV1(output, request) ?? malformed(operationId, request);\n\t\t\t\t} catch {\n\t\t\t\t\treturn signal?.aborted ? cancelled(operationId, request) : malformed(operationId, request);\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t};\n}\n"]}
|
package/dist/capability.js
CHANGED
|
@@ -88,11 +88,9 @@ async function runWithCancellation(run, signal, operationId, request) {
|
|
|
88
88
|
? { ...replacement, committed: true, changed: result.changed, bytesWritten: result.bytesWritten }
|
|
89
89
|
: replacement;
|
|
90
90
|
}
|
|
91
|
-
/** Registers opaque file writes and patches
|
|
91
|
+
/** Registers opaque file writes and patches. */
|
|
92
92
|
export function createWorkspaceFilesWriteCapabilityFactoryV1(runtime = createNodeWorkspaceFilesWriteAdapterV1()) {
|
|
93
93
|
return (api) => {
|
|
94
|
-
if (api.host.mode === "readonly")
|
|
95
|
-
return;
|
|
96
94
|
api.registerTool({
|
|
97
95
|
name: "workspace_write",
|
|
98
96
|
label: "Write workspace file",
|
package/dist/capability.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability.js","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACN,sCAAsC,EACtC,4BAA4B,EAC5B,+CAA+C,EAC/C,sCAAsC,EACtC,0CAA0C,GAC1C,MAAM,mBAAmB,CAAC;AAQ3B,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC;IAC7B,SAAS,EAAE,CAAC;IACZ,SAAS,EAAE,sCAAsC;IACjD,OAAO,EAAE,+BAA+B;CACxC,CAAC,CAAC;AACH,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAChC;IACC,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAClE,iBAAiB,EAAE,SAAS;IAC5B,eAAe,EAAE,IAAI,CAAC,QAAQ,CAC7B,IAAI,CAAC,MAAM,CAAC;QACX,SAAS,EAAE,CAAC;QACZ,SAAS,EAAE,0CAA0C;QACrD,OAAO,EAAE,+BAA+B;KACxC,CAAC,CACF;IACD,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;CAC9C,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAC/B,CAAC;AACF,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,oBAAoB,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"node:crypto\";\nimport type { CapabilityPluginSyncFactory } from \"@agent-forge/plugin-sdk\";\nimport { Type } from \"typebox\";\nimport { Value } from \"typebox/value\";\nimport {\n\tcreateNodeWorkspaceFilesWriteAdapterV1,\n\tprojectWorkspaceFilesWriteV1,\n\tWORKSPACE_FILES_WRITE_MAX_OPERATION_ID_CHARS_V1,\n\tWORKSPACE_FILES_WRITE_MAX_REF_CHARS_V1,\n\tWORKSPACE_FILES_WRITE_MAX_VERSION_CHARS_V1,\n} from \"./node-adapter.ts\";\nimport type {\n\tWorkspaceFilesWriteAdapterV1,\n\tWorkspaceFilesWriteModeV1,\n\tWorkspaceFilesWriteRequestV1,\n\tWorkspaceFilesWriteResultV1,\n} from \"./types.ts\";\n\nconst refSchema = Type.String({\n\tminLength: 1,\n\tmaxLength: WORKSPACE_FILES_WRITE_MAX_REF_CHARS_V1,\n\tpattern: \"^[A-Za-z0-9][A-Za-z0-9._:-]*$\",\n});\nconst requestSchema = Type.Object(\n\t{\n\t\tfileRef: refSchema,\n\t\tmode: Type.Union([Type.Literal(\"replace\"), Type.Literal(\"patch\")]),\n\t\tsourceArtifactRef: refSchema,\n\t\texpectedVersion: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: WORKSPACE_FILES_WRITE_MAX_VERSION_CHARS_V1,\n\t\t\t\tpattern: \"^[A-Za-z0-9][A-Za-z0-9._:-]*$\",\n\t\t\t}),\n\t\t),\n\t\tcreateIfMissing: Type.Optional(Type.Boolean()),\n\t},\n\t{ additionalProperties: false },\n);\nconst inputSchema = Type.Object({ request: requestSchema }, { additionalProperties: false });\n\nfunction generatedOperationId(): string {\n\treturn `profile-runtime-tool-call-${randomUUID()}`;\n}\n\nfunction operationIdFor(first: unknown, second: unknown): string {\n\tconst explicit = second === undefined ? undefined : first;\n\treturn typeof explicit === \"string\" &&\n\t\texplicit.trim() !== \"\" &&\n\t\texplicit.length <= WORKSPACE_FILES_WRITE_MAX_OPERATION_ID_CHARS_V1\n\t\t? explicit\n\t\t: generatedOperationId();\n}\n\nfunction objectInput(first: unknown, second: unknown): Record<string, unknown> {\n\t// Shape-based dual-convention read (aligned with subagent-delegate): the\n\t// runtime invoke face passes the input object first and the host\n\t// CapabilityToolContext second; the agent tool face passes the tool call\n\t// id (a string) first and the params object second.\n\tconst value = first !== null && typeof first === \"object\" && !Array.isArray(first) ? first : second;\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value))\n\t\tthrow new Error(\"Write input must be an object\");\n\treturn value as Record<string, unknown>;\n}\n\nfunction signalFrom(value: unknown): AbortSignal | undefined {\n\treturn value instanceof AbortSignal ? value : undefined;\n}\n\nfunction fallback(\n\toperationId: string,\n\tstatus: \"failed\" | \"cancelled\",\n\trequest?: Partial<WorkspaceFilesWriteRequestV1>,\n): WorkspaceFilesWriteResultV1 {\n\treturn {\n\t\tversion: 1,\n\t\toperationId,\n\t\tstatus,\n\t\tfileRef: request?.fileRef ?? \"invalid:file\",\n\t\tmode: (request?.mode ?? \"replace\") as WorkspaceFilesWriteModeV1,\n\t\tchanged: false,\n\t\tbytesWritten: 0,\n\t\terror: {\n\t\t\tversion: 1,\n\t\t\tcode: status === \"cancelled\" ? \"cancelled\" : \"adapter_failed\",\n\t\t\tmessage: status === \"cancelled\" ? \"Workspace write was cancelled\" : \"Workspace writer failed\",\n\t\t},\n\t};\n}\n\nfunction invalidInput(operationId: string): WorkspaceFilesWriteResultV1 {\n\treturn {\n\t\t...fallback(operationId, \"failed\"),\n\t\terror: { version: 1, code: \"invalid_input\", message: \"Workspace write request was invalid\" },\n\t};\n}\n\nfunction cancelled(operationId: string, request?: Partial<WorkspaceFilesWriteRequestV1>): WorkspaceFilesWriteResultV1 {\n\treturn fallback(operationId, \"cancelled\", request);\n}\n\nfunction malformed(operationId: string, request?: Partial<WorkspaceFilesWriteRequestV1>): WorkspaceFilesWriteResultV1 {\n\treturn {\n\t\t...fallback(operationId, \"failed\", request),\n\t\terror: { version: 1, code: \"adapter_failed\", message: \"Workspace writer returned an invalid result\" },\n\t};\n}\n\nasync function runWithCancellation(\n\trun: () => Promise<WorkspaceFilesWriteResultV1>,\n\tsignal: AbortSignal | undefined,\n\toperationId: string,\n\trequest: WorkspaceFilesWriteRequestV1,\n): Promise<WorkspaceFilesWriteResultV1> {\n\tconst result = await run();\n\tif (!signal?.aborted || result.status === \"cancelled\") return result;\n\tconst replacement = cancelled(operationId, request);\n\t// An adapter that already committed the write must not lose that fact when\n\t// its result is converted to cancelled after an abort; a timeout result with\n\t// an unknown commit state must not degrade into a false \"nothing changed\".\n\tif (result.committed === \"unknown\" || result.changed === \"unknown\")\n\t\treturn { ...replacement, changed: \"unknown\", committed: \"unknown\" };\n\treturn result.committed === true\n\t\t? { ...replacement, committed: true, changed: result.changed, bytesWritten: result.bytesWritten }\n\t\t: replacement;\n}\n\n/** Registers opaque file writes and patches only for a full-control host. */\nexport function createWorkspaceFilesWriteCapabilityFactoryV1(\n\truntime: WorkspaceFilesWriteAdapterV1 = createNodeWorkspaceFilesWriteAdapterV1(),\n): CapabilityPluginSyncFactory {\n\treturn (api) => {\n\t\tif (api.host.mode === \"readonly\") return;\n\t\tapi.registerTool({\n\t\t\tname: \"workspace_write\",\n\t\t\tlabel: \"Write workspace file\",\n\t\t\tdescription:\n\t\t\t\t\"Atomically replace or patch a host file. fileRef and sourceArtifactRef are opaque host handles; never construct; unbound hosts report unsupported (workspace_files_write_unavailable). Failure codes: invalid_input, cancelled/timeout (retry), version_conflict (resend expectedVersion), file_missing (set createIfMissing), read_failed, invalid_file_ref, sandbox_violation (request a new handle), artifact_budget_exceeded (smaller bytes), invalid_patch (ranges must fit), workspace_write_failed (errno in message), adapter_failed (retry), artifact_record_failed (committed true; bytes on disk)\",\n\t\t\tparameters: inputSchema,\n\t\t\texecute: async (first: unknown, second?: unknown, third?: unknown) => {\n\t\t\t\tconst operationId = operationIdFor(first, second);\n\t\t\t\tlet input: Record<string, unknown>;\n\t\t\t\ttry {\n\t\t\t\t\tinput = objectInput(first, second);\n\t\t\t\t\tif (!Value.Check(inputSchema, input)) return invalidInput(operationId);\n\t\t\t\t} catch {\n\t\t\t\t\treturn invalidInput(operationId);\n\t\t\t\t}\n\t\t\t\tconst requestInput = input.request as Record<string, unknown>;\n\t\t\t\tconst request: WorkspaceFilesWriteRequestV1 = {\n\t\t\t\t\tversion: 1,\n\t\t\t\t\toperationId,\n\t\t\t\t\tfileRef: requestInput.fileRef as string,\n\t\t\t\t\tmode: requestInput.mode as WorkspaceFilesWriteModeV1,\n\t\t\t\t\tsourceArtifactRef: requestInput.sourceArtifactRef as string,\n\t\t\t\t\t...(requestInput.expectedVersion === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { expectedVersion: requestInput.expectedVersion as string }),\n\t\t\t\t\t...(requestInput.createIfMissing === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { createIfMissing: requestInput.createIfMissing as boolean }),\n\t\t\t\t};\n\t\t\t\tconst signal = signalFrom(third);\n\t\t\t\tif (signal?.aborted) return cancelled(operationId, request);\n\t\t\t\ttry {\n\t\t\t\t\tconst output = await runWithCancellation(\n\t\t\t\t\t\t() => runtime.write(request, signal),\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\toperationId,\n\t\t\t\t\t\trequest,\n\t\t\t\t\t);\n\t\t\t\t\treturn projectWorkspaceFilesWriteV1(output, request) ?? malformed(operationId, request);\n\t\t\t\t} catch {\n\t\t\t\t\treturn signal?.aborted ? cancelled(operationId, request) : malformed(operationId, request);\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"capability.js","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EACN,sCAA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S;wBAC7C,CAAC,CAAC,EAAE;wBACJ,CAAC,CAAC,EAAE,eAAe,EAAE,YAAY,CAAC,eAA0B,EAAE,CAAC;iBAChE,CAAC;gBACF,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;gBACjC,IAAI,MAAM,EAAE,OAAO;oBAAE,OAAO,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;gBAC5D,IAAI,CAAC;oBACJ,MAAM,MAAM,GAAG,MAAM,mBAAmB,CACvC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,EACpC,MAAM,EACN,WAAW,EACX,OAAO,CACP,CAAC;oBACF,OAAO,4BAA4B,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;gBACzF,CAAC;gBAAC,MAAM,CAAC;oBACR,OAAO,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;gBAC5F,CAAC;YAAA,CACD;SACD,CAAC,CAAC;IAAA,CACH,CAAC;AAAA,CACF","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { CapabilityPluginSyncFactory } from \"@agent-forge/plugin-sdk\";\nimport { Type } from \"typebox\";\nimport { Value } from \"typebox/value\";\nimport {\n\tcreateNodeWorkspaceFilesWriteAdapterV1,\n\tprojectWorkspaceFilesWriteV1,\n\tWORKSPACE_FILES_WRITE_MAX_OPERATION_ID_CHARS_V1,\n\tWORKSPACE_FILES_WRITE_MAX_REF_CHARS_V1,\n\tWORKSPACE_FILES_WRITE_MAX_VERSION_CHARS_V1,\n} from \"./node-adapter.ts\";\nimport type {\n\tWorkspaceFilesWriteAdapterV1,\n\tWorkspaceFilesWriteModeV1,\n\tWorkspaceFilesWriteRequestV1,\n\tWorkspaceFilesWriteResultV1,\n} from \"./types.ts\";\n\nconst refSchema = Type.String({\n\tminLength: 1,\n\tmaxLength: WORKSPACE_FILES_WRITE_MAX_REF_CHARS_V1,\n\tpattern: \"^[A-Za-z0-9][A-Za-z0-9._:-]*$\",\n});\nconst requestSchema = Type.Object(\n\t{\n\t\tfileRef: refSchema,\n\t\tmode: Type.Union([Type.Literal(\"replace\"), Type.Literal(\"patch\")]),\n\t\tsourceArtifactRef: refSchema,\n\t\texpectedVersion: Type.Optional(\n\t\t\tType.String({\n\t\t\t\tminLength: 1,\n\t\t\t\tmaxLength: WORKSPACE_FILES_WRITE_MAX_VERSION_CHARS_V1,\n\t\t\t\tpattern: \"^[A-Za-z0-9][A-Za-z0-9._:-]*$\",\n\t\t\t}),\n\t\t),\n\t\tcreateIfMissing: Type.Optional(Type.Boolean()),\n\t},\n\t{ additionalProperties: false },\n);\nconst inputSchema = Type.Object({ request: requestSchema }, { additionalProperties: false });\n\nfunction generatedOperationId(): string {\n\treturn `profile-runtime-tool-call-${randomUUID()}`;\n}\n\nfunction operationIdFor(first: unknown, second: unknown): string {\n\tconst explicit = second === undefined ? undefined : first;\n\treturn typeof explicit === \"string\" &&\n\t\texplicit.trim() !== \"\" &&\n\t\texplicit.length <= WORKSPACE_FILES_WRITE_MAX_OPERATION_ID_CHARS_V1\n\t\t? explicit\n\t\t: generatedOperationId();\n}\n\nfunction objectInput(first: unknown, second: unknown): Record<string, unknown> {\n\t// Shape-based dual-convention read (aligned with subagent-delegate): the\n\t// runtime invoke face passes the input object first and the host\n\t// CapabilityToolContext second; the agent tool face passes the tool call\n\t// id (a string) first and the params object second.\n\tconst value = first !== null && typeof first === \"object\" && !Array.isArray(first) ? first : second;\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value))\n\t\tthrow new Error(\"Write input must be an object\");\n\treturn value as Record<string, unknown>;\n}\n\nfunction signalFrom(value: unknown): AbortSignal | undefined {\n\treturn value instanceof AbortSignal ? value : undefined;\n}\n\nfunction fallback(\n\toperationId: string,\n\tstatus: \"failed\" | \"cancelled\",\n\trequest?: Partial<WorkspaceFilesWriteRequestV1>,\n): WorkspaceFilesWriteResultV1 {\n\treturn {\n\t\tversion: 1,\n\t\toperationId,\n\t\tstatus,\n\t\tfileRef: request?.fileRef ?? \"invalid:file\",\n\t\tmode: (request?.mode ?? \"replace\") as WorkspaceFilesWriteModeV1,\n\t\tchanged: false,\n\t\tbytesWritten: 0,\n\t\terror: {\n\t\t\tversion: 1,\n\t\t\tcode: status === \"cancelled\" ? \"cancelled\" : \"adapter_failed\",\n\t\t\tmessage: status === \"cancelled\" ? \"Workspace write was cancelled\" : \"Workspace writer failed\",\n\t\t},\n\t};\n}\n\nfunction invalidInput(operationId: string): WorkspaceFilesWriteResultV1 {\n\treturn {\n\t\t...fallback(operationId, \"failed\"),\n\t\terror: { version: 1, code: \"invalid_input\", message: \"Workspace write request was invalid\" },\n\t};\n}\n\nfunction cancelled(operationId: string, request?: Partial<WorkspaceFilesWriteRequestV1>): WorkspaceFilesWriteResultV1 {\n\treturn fallback(operationId, \"cancelled\", request);\n}\n\nfunction malformed(operationId: string, request?: Partial<WorkspaceFilesWriteRequestV1>): WorkspaceFilesWriteResultV1 {\n\treturn {\n\t\t...fallback(operationId, \"failed\", request),\n\t\terror: { version: 1, code: \"adapter_failed\", message: \"Workspace writer returned an invalid result\" },\n\t};\n}\n\nasync function runWithCancellation(\n\trun: () => Promise<WorkspaceFilesWriteResultV1>,\n\tsignal: AbortSignal | undefined,\n\toperationId: string,\n\trequest: WorkspaceFilesWriteRequestV1,\n): Promise<WorkspaceFilesWriteResultV1> {\n\tconst result = await run();\n\tif (!signal?.aborted || result.status === \"cancelled\") return result;\n\tconst replacement = cancelled(operationId, request);\n\t// An adapter that already committed the write must not lose that fact when\n\t// its result is converted to cancelled after an abort; a timeout result with\n\t// an unknown commit state must not degrade into a false \"nothing changed\".\n\tif (result.committed === \"unknown\" || result.changed === \"unknown\")\n\t\treturn { ...replacement, changed: \"unknown\", committed: \"unknown\" };\n\treturn result.committed === true\n\t\t? { ...replacement, committed: true, changed: result.changed, bytesWritten: result.bytesWritten }\n\t\t: replacement;\n}\n\n/** Registers opaque file writes and patches. */\nexport function createWorkspaceFilesWriteCapabilityFactoryV1(\n\truntime: WorkspaceFilesWriteAdapterV1 = createNodeWorkspaceFilesWriteAdapterV1(),\n): CapabilityPluginSyncFactory {\n\treturn (api) => {\n\t\tapi.registerTool({\n\t\t\tname: \"workspace_write\",\n\t\t\tlabel: \"Write workspace file\",\n\t\t\tdescription:\n\t\t\t\t\"Atomically replace or patch a host file. fileRef and sourceArtifactRef are opaque host handles; never construct; unbound hosts report unsupported (workspace_files_write_unavailable). Failure codes: invalid_input, cancelled/timeout (retry), version_conflict (resend expectedVersion), file_missing (set createIfMissing), read_failed, invalid_file_ref, sandbox_violation (request a new handle), artifact_budget_exceeded (smaller bytes), invalid_patch (ranges must fit), workspace_write_failed (errno in message), adapter_failed (retry), artifact_record_failed (committed true; bytes on disk)\",\n\t\t\tparameters: inputSchema,\n\t\t\texecute: async (first: unknown, second?: unknown, third?: unknown) => {\n\t\t\t\tconst operationId = operationIdFor(first, second);\n\t\t\t\tlet input: Record<string, unknown>;\n\t\t\t\ttry {\n\t\t\t\t\tinput = objectInput(first, second);\n\t\t\t\t\tif (!Value.Check(inputSchema, input)) return invalidInput(operationId);\n\t\t\t\t} catch {\n\t\t\t\t\treturn invalidInput(operationId);\n\t\t\t\t}\n\t\t\t\tconst requestInput = input.request as Record<string, unknown>;\n\t\t\t\tconst request: WorkspaceFilesWriteRequestV1 = {\n\t\t\t\t\tversion: 1,\n\t\t\t\t\toperationId,\n\t\t\t\t\tfileRef: requestInput.fileRef as string,\n\t\t\t\t\tmode: requestInput.mode as WorkspaceFilesWriteModeV1,\n\t\t\t\t\tsourceArtifactRef: requestInput.sourceArtifactRef as string,\n\t\t\t\t\t...(requestInput.expectedVersion === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { expectedVersion: requestInput.expectedVersion as string }),\n\t\t\t\t\t...(requestInput.createIfMissing === undefined\n\t\t\t\t\t\t? {}\n\t\t\t\t\t\t: { createIfMissing: requestInput.createIfMissing as boolean }),\n\t\t\t\t};\n\t\t\t\tconst signal = signalFrom(third);\n\t\t\t\tif (signal?.aborted) return cancelled(operationId, request);\n\t\t\t\ttry {\n\t\t\t\t\tconst output = await runWithCancellation(\n\t\t\t\t\t\t() => runtime.write(request, signal),\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\toperationId,\n\t\t\t\t\t\trequest,\n\t\t\t\t\t);\n\t\t\t\t\treturn projectWorkspaceFilesWriteV1(output, request) ?? malformed(operationId, request);\n\t\t\t\t} catch {\n\t\t\t\t\treturn signal?.aborted ? cancelled(operationId, request) : malformed(operationId, request);\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t};\n}\n"]}
|
package/dist/entry.d.ts
CHANGED
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* paths, atomic writes) is host-owned, so the registered `workspace_write`
|
|
7
7
|
* tool reports an explicit `unsupported` result until a host binds a real
|
|
8
8
|
* writer through its own profile machinery (fail-closed by design, same
|
|
9
|
-
* contract as the embedded build).
|
|
10
|
-
* at all.
|
|
9
|
+
* contract as the embedded build).
|
|
11
10
|
*/
|
|
12
11
|
declare const _default: import("@agent-forge/plugin-sdk").CapabilityPluginSyncFactory;
|
|
13
12
|
export default _default;
|
package/dist/entry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;;AACH,wBAA8D","sourcesContent":["import { createWorkspaceFilesWriteCapabilityFactoryV1 } from \"./capability.ts\";\n\n/**\n * Default-export factory consumed by the host's `loadCapabilityPluginFromManifest`.\n *\n * The capability factory already defaults to the Node adapter constructed\n * without host injection: the write seam (artifact resolution, sandboxed\n * paths, atomic writes) is host-owned, so the registered `workspace_write`\n * tool reports an explicit `unsupported` result until a host binds a real\n * writer through its own profile machinery (fail-closed by design, same\n * contract as the embedded build).\n */\nexport default createWorkspaceFilesWriteCapabilityFactoryV1();\n"]}
|
package/dist/entry.js
CHANGED
|
@@ -7,8 +7,7 @@ import { createWorkspaceFilesWriteCapabilityFactoryV1 } from "./capability.js";
|
|
|
7
7
|
* paths, atomic writes) is host-owned, so the registered `workspace_write`
|
|
8
8
|
* tool reports an explicit `unsupported` result until a host binds a real
|
|
9
9
|
* writer through its own profile machinery (fail-closed by design, same
|
|
10
|
-
* contract as the embedded build).
|
|
11
|
-
* at all.
|
|
10
|
+
* contract as the embedded build).
|
|
12
11
|
*/
|
|
13
12
|
export default createWorkspaceFilesWriteCapabilityFactoryV1();
|
|
14
13
|
//# sourceMappingURL=entry.js.map
|
package/dist/entry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4CAA4C,EAAE,MAAM,iBAAiB,CAAC;AAE/E
|
|
1
|
+
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4CAA4C,EAAE,MAAM,iBAAiB,CAAC;AAE/E;;;;;;;;;GASG;AACH,eAAe,4CAA4C,EAAE,CAAC","sourcesContent":["import { createWorkspaceFilesWriteCapabilityFactoryV1 } from \"./capability.ts\";\n\n/**\n * Default-export factory consumed by the host's `loadCapabilityPluginFromManifest`.\n *\n * The capability factory already defaults to the Node adapter constructed\n * without host injection: the write seam (artifact resolution, sandboxed\n * paths, atomic writes) is host-owned, so the registered `workspace_write`\n * tool reports an explicit `unsupported` result until a host binds a real\n * writer through its own profile machinery (fail-closed by design, same\n * contract as the embedded build).\n */\nexport default createWorkspaceFilesWriteCapabilityFactoryV1();\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-agent-forge/plugin-workspace-files-write",
|
|
3
|
-
"version": "0.88.
|
|
3
|
+
"version": "0.88.29",
|
|
4
4
|
"description": "Workspace file write capability plugin for Agent Forge (full-control workspace_write tool with atomic replace/patch)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"typebox": "1.3.27",
|
|
49
|
-
"@ai-agent-forge/plugin-sdk": "^0.88.
|
|
49
|
+
"@ai-agent-forge/plugin-sdk": "^0.88.29"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"shx": "0.3.4",
|