@ai-agent-forge/plugin-workspace-files-write 0.88.24 → 0.88.26
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/agent-forge.json +1 -1
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +1 -1
- package/dist/capability.js.map +1 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +19 -6
- package/dist/host.js.map +1 -1
- package/package.json +2 -2
- package/plugin.json +1 -1
package/agent-forge.json
CHANGED
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,6EAA6E;AAC7E,wBAAgB,4CAA4C,CAC3D,OAAO,GAAE,4BAAuE,GAC9E,2BAA2B,
|
|
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,6EAA6E;AAC7E,wBAAgB,4CAA4C,CAC3D,OAAO,GAAE,4BAAuE,GAC9E,2BAA2B,CAgD7B","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 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"]}
|
package/dist/capability.js
CHANGED
|
@@ -96,7 +96,7 @@ export function createWorkspaceFilesWriteCapabilityFactoryV1(runtime = createNod
|
|
|
96
96
|
api.registerTool({
|
|
97
97
|
name: "workspace_write",
|
|
98
98
|
label: "Write workspace file",
|
|
99
|
-
description: "Atomically replace or patch a host
|
|
99
|
+
description: "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)",
|
|
100
100
|
parameters: inputSchema,
|
|
101
101
|
execute: async (first, second, third) => {
|
|
102
102
|
const operationId = operationIdFor(first, second);
|
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,EAAE,KAAK,EAAE,CAAC,CAAC;AAE7F,SAAS,oBAAo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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: \"Atomically replace or patch a host-owned file using opaque artifact references\",\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,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,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AAO,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 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"]}
|
package/dist/host.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACX,oCAAoC,EACpC,6BAA6B,EAE7B,4BAA4B,EAC5B,4BAA4B,EAC5B,2BAA2B,EAC3B,MAAM,YAAY,CAAC;AAmCpB,iBAAe,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,oCAAoC,CAAC,gBAAgB,CAAC,EACtE,MAAM,EAAE,WAAW,GACjB,OAAO,CAAC,MAAM,CAAC,CAoBjB;AAcD,iBAAS,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,6BAA6B,CAoCpE;AAED,iBAAS,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAW1E;AAeD;;;;;;;;;GASG;AACH,wBAAgB,wCAAwC,CACvD,OAAO,EAAE,oCAAoC,GAC3C,CAAC,OAAO,EAAE,4BAA4B,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,2BAA2B,CAAC,CAgItG;AAED;;;GAGG;AACH,wBAAgB,0CAA0C,CACzD,OAAO,EAAE,oCAAoC,GAC3C,4BAA4B,CAK9B;AAED,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { readFile as fsReadFile, mkdtemp, realpath, rename, rm, stat, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from \"node:path\";\nimport { createNodeWorkspaceFilesWriteAdapterV1 } from \"./node-adapter.ts\";\nimport type {\n\tNodeWorkspaceFilesWriteHostOptionsV1,\n\tWorkspaceFilesPatchDocumentV1,\n\tWorkspaceFilesPatchOperationV1,\n\tWorkspaceFilesWriteAdapterV1,\n\tWorkspaceFilesWriteRequestV1,\n\tWorkspaceFilesWriteResultV1,\n} from \"./types.ts\";\n\nconst MAX_ARTIFACT_BYTES_V1 = 256 * 1024 * 1024;\nconst MAX_PATCH_OPERATIONS_V1 = 16_384;\nconst MAX_PATCH_REPLACEMENT_CHARS_V1 = 1_048_576;\n\nclass HostWriteFailureV1 extends Error {\n\treadonly code: string;\n\n\tconstructor(code: string, message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"HostWriteFailureV1\";\n\t\tthis.code = code;\n\t}\n}\n\nfunction throwIfAborted(signal: AbortSignal): void {\n\tif (signal.aborted) throw new HostWriteFailureV1(\"cancelled\", \"Workspace write was cancelled\");\n}\n\nfunction digest(bytes: Uint8Array): string {\n\treturn createHash(\"sha256\").update(bytes).digest(\"hex\");\n}\n\nfunction isInside(root: string, target: string): boolean {\n\tconst relativePath = relative(root, target);\n\treturn (\n\t\trelativePath !== \"\" && relativePath !== \".\" && !relativePath.startsWith(`..${sep}`) && !isAbsolute(relativePath)\n\t);\n}\n\nfunction isWithin(root: string, target: string): boolean {\n\treturn target === root || isInside(root, target);\n}\n\nasync function resolveSandboxedPath(\n\troot: string,\n\tfileRef: string,\n\tresolveFileRef: NodeWorkspaceFilesWriteHostOptionsV1[\"resolveFileRef\"],\n\tsignal: AbortSignal,\n): Promise<string> {\n\tthrowIfAborted(signal);\n\tconst rootPath = await realpath(root);\n\tconst requested = await resolveFileRef(fileRef, signal);\n\tif (!isAbsolute(requested))\n\t\tthrow new HostWriteFailureV1(\"invalid_file_ref\", \"Resolved workspace file is not absolute\");\n\tconst candidate = resolve(requested);\n\tconst parent = await realpath(dirname(candidate));\n\tif (!isWithin(rootPath, parent))\n\t\tthrow new HostWriteFailureV1(\"sandbox_violation\", \"Workspace parent is outside the host root\");\n\tconst canonicalCandidate = join(parent, basename(candidate));\n\tlet existing: string | undefined;\n\ttry {\n\t\texisting = await realpath(canonicalCandidate);\n\t} catch {\n\t\texisting = undefined;\n\t}\n\tif (existing !== undefined && !isInside(rootPath, existing))\n\t\tthrow new HostWriteFailureV1(\"sandbox_violation\", \"Workspace file resolves outside the host root\");\n\treturn canonicalCandidate;\n}\n\nasync function readSourceArtifact(\n\trequest: WorkspaceFilesWriteRequestV1,\n\toptions: NodeWorkspaceFilesWriteHostOptionsV1,\n\tsignal: AbortSignal,\n): Promise<Uint8Array> {\n\tthrowIfAborted(signal);\n\tconst bytes = await options.readArtifact(request.sourceArtifactRef, signal);\n\tif (!(bytes instanceof Uint8Array) || bytes.byteLength > MAX_ARTIFACT_BYTES_V1)\n\t\tthrow new HostWriteFailureV1(\"artifact_budget_exceeded\", \"Workspace source artifact exceeds the host budget\");\n\treturn bytes;\n}\n\nfunction parsePatch(bytes: Uint8Array): WorkspaceFilesPatchDocumentV1 {\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes));\n\t} catch {\n\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch artifact is not valid UTF-8 JSON\");\n\t}\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value))\n\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch document must be an object\");\n\tconst record = value as Record<string, unknown>;\n\tif (record.version !== 1 || !Array.isArray(record.operations) || record.operations.length > MAX_PATCH_OPERATIONS_V1)\n\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch document is invalid\");\n\tlet previousEnd = 0;\n\tconst operations: WorkspaceFilesPatchOperationV1[] = [];\n\tfor (const item of record.operations) {\n\t\tif (item === null || typeof item !== \"object\" || Array.isArray(item))\n\t\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch operation is invalid\");\n\t\tconst operation = item as Record<string, unknown>;\n\t\tif (\n\t\t\t!Number.isSafeInteger(operation.start) ||\n\t\t\t!Number.isSafeInteger(operation.end) ||\n\t\t\t(operation.start as number) < 0 ||\n\t\t\t(operation.end as number) < (operation.start as number) ||\n\t\t\ttypeof operation.replacement !== \"string\" ||\n\t\t\t[...(operation.replacement as string)].length > MAX_PATCH_REPLACEMENT_CHARS_V1 ||\n\t\t\t(operation.start as number) < previousEnd\n\t\t)\n\t\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch operation is invalid\");\n\t\tpreviousEnd = operation.end as number;\n\t\toperations.push({\n\t\t\tstart: operation.start as number,\n\t\t\tend: operation.end as number,\n\t\t\treplacement: operation.replacement as string,\n\t\t});\n\t}\n\treturn { version: 1, operations };\n}\n\nfunction applyPatch(source: Uint8Array, patchBytes: Uint8Array): Uint8Array {\n\tconst patch = parsePatch(patchBytes);\n\tconst text = new TextDecoder(\"utf-8\", { fatal: true }).decode(source);\n\tlet output = text;\n\tfor (let index = patch.operations.length - 1; index >= 0; index -= 1) {\n\t\tconst operation = patch.operations[index]!;\n\t\tif (operation.end > output.length)\n\t\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch range exceeds the file\");\n\t\toutput = `${output.slice(0, operation.start)}${operation.replacement}${output.slice(operation.end)}`;\n\t}\n\treturn new TextEncoder().encode(output);\n}\n\nasync function atomicWrite(path: string, bytes: Uint8Array, signal: AbortSignal): Promise<void> {\n\tthrowIfAborted(signal);\n\tconst directory = await mkdtemp(join(dirname(path), \".agent-forge-write-\"));\n\tconst temporary = join(directory, basename(path));\n\ttry {\n\t\tawait writeFile(temporary, bytes);\n\t\tthrowIfAborted(signal);\n\t\tawait rename(temporary, path);\n\t} finally {\n\t\tawait rm(directory, { recursive: true, force: true }).catch(() => undefined);\n\t}\n}\n\n/**\n * Host-level write: resolves the sandboxed path, then serializes the\n * read-check-commit critical section per resolved canonical path so concurrent\n * requests cannot both pass the expectedVersion check (single-flight). After\n * the rename committed new bytes, a later artifact-record failure or\n * cancellation is reported with `committed: true` and a truthful changed state\n * instead of masking the write that already reached the disk. The timeout and\n * stop race of the full adapter lives in node-adapter; this seam exposes the\n * host mapping itself.\n */\nexport function createNodeWorkspaceFilesWriteHostWriteV1(\n\toptions: NodeWorkspaceFilesWriteHostOptionsV1,\n): (request: WorkspaceFilesWriteRequestV1, signal: AbortSignal) => Promise<WorkspaceFilesWriteResultV1> {\n\tif (!isAbsolute(options.root)) throw new Error(\"root must be an absolute path\");\n\tconst writeGates = new Map<string, Promise<void>>();\n\tconst runSerialized = async <T>(key: string, work: () => Promise<T>): Promise<T> => {\n\t\tconst previous = writeGates.get(key);\n\t\tlet releaseGate: (() => void) | undefined;\n\t\tconst gate = new Promise<void>((resolveGate) => {\n\t\t\treleaseGate = resolveGate;\n\t\t});\n\t\tconst chained =\n\t\t\tprevious === undefined\n\t\t\t\t? gate\n\t\t\t\t: previous.then(\n\t\t\t\t\t\t() => gate,\n\t\t\t\t\t\t() => gate,\n\t\t\t\t\t);\n\t\twriteGates.set(key, chained);\n\t\ttry {\n\t\t\tawait previous;\n\t\t\treturn await work();\n\t\t} finally {\n\t\t\treleaseGate?.();\n\t\t\tif (writeGates.get(key) === chained) writeGates.delete(key);\n\t\t}\n\t};\n\tconst performWrite = async (\n\t\trequest: WorkspaceFilesWriteRequestV1,\n\t\tsignal: AbortSignal,\n\t): Promise<WorkspaceFilesWriteResultV1> => {\n\t\t/** Set only after the rename committed new bytes, so later failures cannot mask the disk state. */\n\t\tconst commit = { committed: false, bytes: 0 };\n\t\ttry {\n\t\t\tthrowIfAborted(signal);\n\t\t\tconst path = await resolveSandboxedPath(options.root, request.fileRef, options.resolveFileRef, signal);\n\t\t\treturn await runSerialized(path, async () => {\n\t\t\t\tthrowIfAborted(signal);\n\t\t\t\tlet current = new Uint8Array();\n\t\t\t\tlet exists = true;\n\t\t\t\ttry {\n\t\t\t\t\tconst information = await stat(path);\n\t\t\t\t\tif (!information.isFile())\n\t\t\t\t\t\tthrow new HostWriteFailureV1(\"invalid_file_ref\", \"Workspace target is not a file\");\n\t\t\t\t\tcurrent = new Uint8Array(\n\t\t\t\t\t\tawait (options.readWorkspaceFile === undefined\n\t\t\t\t\t\t\t? fsReadFile(path)\n\t\t\t\t\t\t\t: options.readWorkspaceFile(path, signal)),\n\t\t\t\t\t);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof HostWriteFailureV1) throw error;\n\t\t\t\t\tif (error === null || typeof error !== \"object\" || (error as { code?: unknown }).code !== \"ENOENT\")\n\t\t\t\t\t\tthrow new HostWriteFailureV1(\"read_failed\", \"Workspace target could not be read\");\n\t\t\t\t\texists = false;\n\t\t\t\t}\n\t\t\t\tif (!exists && request.createIfMissing !== true)\n\t\t\t\t\tthrow new HostWriteFailureV1(\"file_missing\", \"Workspace target does not exist\");\n\t\t\t\tif (request.expectedVersion !== undefined && request.expectedVersion !== digest(current))\n\t\t\t\t\tthrow new HostWriteFailureV1(\n\t\t\t\t\t\t\"version_conflict\",\n\t\t\t\t\t\t\"Workspace target version does not match expectedVersion\",\n\t\t\t\t\t);\n\t\t\t\tconst source = await readSourceArtifact(request, options, signal);\n\t\t\t\tconst next = request.mode === \"replace\" ? source : applyPatch(current, source);\n\t\t\t\tconst changed = digest(current) !== digest(next);\n\t\t\t\tif (changed) {\n\t\t\t\t\tawait atomicWrite(path, next, signal);\n\t\t\t\t\tcommit.committed = true;\n\t\t\t\t\tcommit.bytes = next.byteLength;\n\t\t\t\t}\n\t\t\t\tconst outputArtifactRef =\n\t\t\t\t\toptions.writeArtifact === undefined\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: (\n\t\t\t\t\t\t\t\tawait options.writeArtifact(\n\t\t\t\t\t\t\t\t\t{ operationId: request.operationId, fileRef: request.fileRef, bytes: next },\n\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t).artifactRef;\n\t\t\t\treturn {\n\t\t\t\t\tversion: 1 as const,\n\t\t\t\t\toperationId: request.operationId,\n\t\t\t\t\tstatus: \"succeeded\" as const,\n\t\t\t\t\tfileRef: request.fileRef,\n\t\t\t\t\tmode: request.mode,\n\t\t\t\t\tchanged,\n\t\t\t\t\tbytesWritten: changed ? next.byteLength : 0,\n\t\t\t\t\t...(outputArtifactRef === undefined ? {} : { outputArtifactRef }),\n\t\t\t\t\tversionToken: digest(next),\n\t\t\t\t};\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tconst cancelled = signal.aborted || (error instanceof HostWriteFailureV1 && error.code === \"cancelled\");\n\t\t\tif (commit.committed) {\n\t\t\t\treturn {\n\t\t\t\t\tversion: 1 as const,\n\t\t\t\t\toperationId: request.operationId,\n\t\t\t\t\tstatus: cancelled ? (\"cancelled\" as const) : (\"failed\" as const),\n\t\t\t\t\tfileRef: request.fileRef,\n\t\t\t\t\tmode: request.mode,\n\t\t\t\t\tchanged: true,\n\t\t\t\t\tbytesWritten: commit.bytes,\n\t\t\t\t\tcommitted: true,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tversion: 1 as const,\n\t\t\t\t\t\tcode: cancelled ? \"cancelled\" : \"artifact_record_failed\",\n\t\t\t\t\t\tmessage: cancelled\n\t\t\t\t\t\t\t? \"Workspace write was cancelled\"\n\t\t\t\t\t\t\t: \"Workspace file was committed but the artifact record failed\",\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst code = cancelled ? \"cancelled\" : error instanceof HostWriteFailureV1 ? error.code : \"adapter_failed\";\n\t\t\treturn {\n\t\t\t\tversion: 1 as const,\n\t\t\t\toperationId: request.operationId,\n\t\t\t\tstatus: cancelled ? (\"cancelled\" as const) : (\"failed\" as const),\n\t\t\t\tfileRef: request.fileRef,\n\t\t\t\tmode: request.mode,\n\t\t\t\tchanged: false,\n\t\t\t\tbytesWritten: 0,\n\t\t\t\terror: {\n\t\t\t\t\tversion: 1 as const,\n\t\t\t\t\tcode,\n\t\t\t\t\tmessage: cancelled ? \"Workspace write was cancelled\" : \"Workspace write failed\",\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t};\n\treturn performWrite;\n}\n\n/**\n * Real Node host adapter. All local paths and bytes stay inside this host;\n * model-facing requests and results remain opaque and bounded.\n */\nexport function createNodeWorkspaceFilesWriteHostAdapterV1(\n\toptions: NodeWorkspaceFilesWriteHostOptionsV1,\n): WorkspaceFilesWriteAdapterV1 {\n\treturn createNodeWorkspaceFilesWriteAdapterV1({\n\t\tdefaultTimeoutMs: options.defaultTimeoutMs,\n\t\twrite: createNodeWorkspaceFilesWriteHostWriteV1(options),\n\t});\n}\n\nexport { applyPatch, parsePatch, resolveSandboxedPath };\n"]}
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACX,oCAAoC,EACpC,6BAA6B,EAE7B,4BAA4B,EAC5B,4BAA4B,EAC5B,2BAA2B,EAC3B,MAAM,YAAY,CAAC;AAmCpB,iBAAe,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,oCAAoC,CAAC,gBAAgB,CAAC,EACtE,MAAM,EAAE,WAAW,GACjB,OAAO,CAAC,MAAM,CAAC,CAoBjB;AAcD,iBAAS,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,6BAA6B,CAoCpE;AAED,iBAAS,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,GAAG,UAAU,CAW1E;AAeD;;;;;;;;;GASG;AACH,wBAAgB,wCAAwC,CACvD,OAAO,EAAE,oCAAoC,GAC3C,CAAC,OAAO,EAAE,4BAA4B,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,2BAA2B,CAAC,CA0ItG;AAED;;;GAGG;AACH,wBAAgB,0CAA0C,CACzD,OAAO,EAAE,oCAAoC,GAC3C,4BAA4B,CAK9B;AAED,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { readFile as fsReadFile, mkdtemp, realpath, rename, rm, stat, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from \"node:path\";\nimport { createNodeWorkspaceFilesWriteAdapterV1 } from \"./node-adapter.ts\";\nimport type {\n\tNodeWorkspaceFilesWriteHostOptionsV1,\n\tWorkspaceFilesPatchDocumentV1,\n\tWorkspaceFilesPatchOperationV1,\n\tWorkspaceFilesWriteAdapterV1,\n\tWorkspaceFilesWriteRequestV1,\n\tWorkspaceFilesWriteResultV1,\n} from \"./types.ts\";\n\nconst MAX_ARTIFACT_BYTES_V1 = 256 * 1024 * 1024;\nconst MAX_PATCH_OPERATIONS_V1 = 16_384;\nconst MAX_PATCH_REPLACEMENT_CHARS_V1 = 1_048_576;\n\nclass HostWriteFailureV1 extends Error {\n\treadonly code: string;\n\n\tconstructor(code: string, message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"HostWriteFailureV1\";\n\t\tthis.code = code;\n\t}\n}\n\nfunction throwIfAborted(signal: AbortSignal): void {\n\tif (signal.aborted) throw new HostWriteFailureV1(\"cancelled\", \"Workspace write was cancelled\");\n}\n\nfunction digest(bytes: Uint8Array): string {\n\treturn createHash(\"sha256\").update(bytes).digest(\"hex\");\n}\n\nfunction isInside(root: string, target: string): boolean {\n\tconst relativePath = relative(root, target);\n\treturn (\n\t\trelativePath !== \"\" && relativePath !== \".\" && !relativePath.startsWith(`..${sep}`) && !isAbsolute(relativePath)\n\t);\n}\n\nfunction isWithin(root: string, target: string): boolean {\n\treturn target === root || isInside(root, target);\n}\n\nasync function resolveSandboxedPath(\n\troot: string,\n\tfileRef: string,\n\tresolveFileRef: NodeWorkspaceFilesWriteHostOptionsV1[\"resolveFileRef\"],\n\tsignal: AbortSignal,\n): Promise<string> {\n\tthrowIfAborted(signal);\n\tconst rootPath = await realpath(root);\n\tconst requested = await resolveFileRef(fileRef, signal);\n\tif (!isAbsolute(requested))\n\t\tthrow new HostWriteFailureV1(\"invalid_file_ref\", \"Resolved workspace file is not absolute\");\n\tconst candidate = resolve(requested);\n\tconst parent = await realpath(dirname(candidate));\n\tif (!isWithin(rootPath, parent))\n\t\tthrow new HostWriteFailureV1(\"sandbox_violation\", \"Workspace parent is outside the host root\");\n\tconst canonicalCandidate = join(parent, basename(candidate));\n\tlet existing: string | undefined;\n\ttry {\n\t\texisting = await realpath(canonicalCandidate);\n\t} catch {\n\t\texisting = undefined;\n\t}\n\tif (existing !== undefined && !isInside(rootPath, existing))\n\t\tthrow new HostWriteFailureV1(\"sandbox_violation\", \"Workspace file resolves outside the host root\");\n\treturn canonicalCandidate;\n}\n\nasync function readSourceArtifact(\n\trequest: WorkspaceFilesWriteRequestV1,\n\toptions: NodeWorkspaceFilesWriteHostOptionsV1,\n\tsignal: AbortSignal,\n): Promise<Uint8Array> {\n\tthrowIfAborted(signal);\n\tconst bytes = await options.readArtifact(request.sourceArtifactRef, signal);\n\tif (!(bytes instanceof Uint8Array) || bytes.byteLength > MAX_ARTIFACT_BYTES_V1)\n\t\tthrow new HostWriteFailureV1(\"artifact_budget_exceeded\", \"Workspace source artifact exceeds the host budget\");\n\treturn bytes;\n}\n\nfunction parsePatch(bytes: Uint8Array): WorkspaceFilesPatchDocumentV1 {\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes));\n\t} catch {\n\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch artifact is not valid UTF-8 JSON\");\n\t}\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value))\n\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch document must be an object\");\n\tconst record = value as Record<string, unknown>;\n\tif (record.version !== 1 || !Array.isArray(record.operations) || record.operations.length > MAX_PATCH_OPERATIONS_V1)\n\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch document is invalid\");\n\tlet previousEnd = 0;\n\tconst operations: WorkspaceFilesPatchOperationV1[] = [];\n\tfor (const item of record.operations) {\n\t\tif (item === null || typeof item !== \"object\" || Array.isArray(item))\n\t\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch operation is invalid\");\n\t\tconst operation = item as Record<string, unknown>;\n\t\tif (\n\t\t\t!Number.isSafeInteger(operation.start) ||\n\t\t\t!Number.isSafeInteger(operation.end) ||\n\t\t\t(operation.start as number) < 0 ||\n\t\t\t(operation.end as number) < (operation.start as number) ||\n\t\t\ttypeof operation.replacement !== \"string\" ||\n\t\t\t[...(operation.replacement as string)].length > MAX_PATCH_REPLACEMENT_CHARS_V1 ||\n\t\t\t(operation.start as number) < previousEnd\n\t\t)\n\t\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch operation is invalid\");\n\t\tpreviousEnd = operation.end as number;\n\t\toperations.push({\n\t\t\tstart: operation.start as number,\n\t\t\tend: operation.end as number,\n\t\t\treplacement: operation.replacement as string,\n\t\t});\n\t}\n\treturn { version: 1, operations };\n}\n\nfunction applyPatch(source: Uint8Array, patchBytes: Uint8Array): Uint8Array {\n\tconst patch = parsePatch(patchBytes);\n\tconst text = new TextDecoder(\"utf-8\", { fatal: true }).decode(source);\n\tlet output = text;\n\tfor (let index = patch.operations.length - 1; index >= 0; index -= 1) {\n\t\tconst operation = patch.operations[index]!;\n\t\tif (operation.end > output.length)\n\t\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch range exceeds the file\");\n\t\toutput = `${output.slice(0, operation.start)}${operation.replacement}${output.slice(operation.end)}`;\n\t}\n\treturn new TextEncoder().encode(output);\n}\n\nasync function atomicWrite(path: string, bytes: Uint8Array, signal: AbortSignal): Promise<void> {\n\tthrowIfAborted(signal);\n\tconst directory = await mkdtemp(join(dirname(path), \".agent-forge-write-\"));\n\tconst temporary = join(directory, basename(path));\n\ttry {\n\t\tawait writeFile(temporary, bytes);\n\t\tthrowIfAborted(signal);\n\t\tawait rename(temporary, path);\n\t} finally {\n\t\tawait rm(directory, { recursive: true, force: true }).catch(() => undefined);\n\t}\n}\n\n/**\n * Host-level write: resolves the sandboxed path, then serializes the\n * read-check-commit critical section per resolved canonical path so concurrent\n * requests cannot both pass the expectedVersion check (single-flight). After\n * the rename committed new bytes, a later artifact-record failure or\n * cancellation is reported with `committed: true` and a truthful changed state\n * instead of masking the write that already reached the disk. The timeout and\n * stop race of the full adapter lives in node-adapter; this seam exposes the\n * host mapping itself.\n */\nexport function createNodeWorkspaceFilesWriteHostWriteV1(\n\toptions: NodeWorkspaceFilesWriteHostOptionsV1,\n): (request: WorkspaceFilesWriteRequestV1, signal: AbortSignal) => Promise<WorkspaceFilesWriteResultV1> {\n\tif (!isAbsolute(options.root)) throw new Error(\"root must be an absolute path\");\n\tconst writeGates = new Map<string, Promise<void>>();\n\tconst runSerialized = async <T>(key: string, work: () => Promise<T>): Promise<T> => {\n\t\tconst previous = writeGates.get(key);\n\t\tlet releaseGate: (() => void) | undefined;\n\t\tconst gate = new Promise<void>((resolveGate) => {\n\t\t\treleaseGate = resolveGate;\n\t\t});\n\t\tconst chained =\n\t\t\tprevious === undefined\n\t\t\t\t? gate\n\t\t\t\t: previous.then(\n\t\t\t\t\t\t() => gate,\n\t\t\t\t\t\t() => gate,\n\t\t\t\t\t);\n\t\twriteGates.set(key, chained);\n\t\ttry {\n\t\t\tawait previous;\n\t\t\treturn await work();\n\t\t} finally {\n\t\t\treleaseGate?.();\n\t\t\tif (writeGates.get(key) === chained) writeGates.delete(key);\n\t\t}\n\t};\n\tconst performWrite = async (\n\t\trequest: WorkspaceFilesWriteRequestV1,\n\t\tsignal: AbortSignal,\n\t): Promise<WorkspaceFilesWriteResultV1> => {\n\t\t/** Set only after the rename committed new bytes, so later failures cannot mask the disk state. */\n\t\tconst commit = { committed: false, bytes: 0 };\n\t\ttry {\n\t\t\tthrowIfAborted(signal);\n\t\t\tconst path = await resolveSandboxedPath(options.root, request.fileRef, options.resolveFileRef, signal);\n\t\t\treturn await runSerialized(path, async () => {\n\t\t\t\tthrowIfAborted(signal);\n\t\t\t\tlet current = new Uint8Array();\n\t\t\t\tlet exists = true;\n\t\t\t\ttry {\n\t\t\t\t\tconst information = await stat(path);\n\t\t\t\t\tif (!information.isFile())\n\t\t\t\t\t\tthrow new HostWriteFailureV1(\"invalid_file_ref\", \"Workspace target is not a file\");\n\t\t\t\t\tcurrent = new Uint8Array(\n\t\t\t\t\t\tawait (options.readWorkspaceFile === undefined\n\t\t\t\t\t\t\t? fsReadFile(path)\n\t\t\t\t\t\t\t: options.readWorkspaceFile(path, signal)),\n\t\t\t\t\t);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof HostWriteFailureV1) throw error;\n\t\t\t\t\tif (error === null || typeof error !== \"object\" || (error as { code?: unknown }).code !== \"ENOENT\")\n\t\t\t\t\t\tthrow new HostWriteFailureV1(\"read_failed\", \"Workspace target could not be read\");\n\t\t\t\t\texists = false;\n\t\t\t\t}\n\t\t\t\tif (!exists && request.createIfMissing !== true)\n\t\t\t\t\tthrow new HostWriteFailureV1(\"file_missing\", \"Workspace target does not exist\");\n\t\t\t\tif (request.expectedVersion !== undefined && request.expectedVersion !== digest(current))\n\t\t\t\t\tthrow new HostWriteFailureV1(\n\t\t\t\t\t\t\"version_conflict\",\n\t\t\t\t\t\t\"Workspace target version does not match expectedVersion\",\n\t\t\t\t\t);\n\t\t\t\tconst source = await readSourceArtifact(request, options, signal);\n\t\t\t\tconst next = request.mode === \"replace\" ? source : applyPatch(current, source);\n\t\t\t\tconst changed = digest(current) !== digest(next);\n\t\t\t\tif (changed) {\n\t\t\t\t\tawait atomicWrite(path, next, signal);\n\t\t\t\t\tcommit.committed = true;\n\t\t\t\t\tcommit.bytes = next.byteLength;\n\t\t\t\t}\n\t\t\t\tconst outputArtifactRef =\n\t\t\t\t\toptions.writeArtifact === undefined\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: (\n\t\t\t\t\t\t\t\tawait options.writeArtifact(\n\t\t\t\t\t\t\t\t\t{ operationId: request.operationId, fileRef: request.fileRef, bytes: next },\n\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t).artifactRef;\n\t\t\t\treturn {\n\t\t\t\t\tversion: 1 as const,\n\t\t\t\t\toperationId: request.operationId,\n\t\t\t\t\tstatus: \"succeeded\" as const,\n\t\t\t\t\tfileRef: request.fileRef,\n\t\t\t\t\tmode: request.mode,\n\t\t\t\t\tchanged,\n\t\t\t\t\tbytesWritten: changed ? next.byteLength : 0,\n\t\t\t\t\t...(outputArtifactRef === undefined ? {} : { outputArtifactRef }),\n\t\t\t\t\tversionToken: digest(next),\n\t\t\t\t};\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tconst cancelled = signal.aborted || (error instanceof HostWriteFailureV1 && error.code === \"cancelled\");\n\t\t\tif (commit.committed) {\n\t\t\t\treturn {\n\t\t\t\t\tversion: 1 as const,\n\t\t\t\t\toperationId: request.operationId,\n\t\t\t\t\tstatus: cancelled ? (\"cancelled\" as const) : (\"failed\" as const),\n\t\t\t\t\tfileRef: request.fileRef,\n\t\t\t\t\tmode: request.mode,\n\t\t\t\t\tchanged: true,\n\t\t\t\t\tbytesWritten: commit.bytes,\n\t\t\t\t\tcommitted: true,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tversion: 1 as const,\n\t\t\t\t\t\tcode: cancelled ? \"cancelled\" : \"artifact_record_failed\",\n\t\t\t\t\t\tmessage: cancelled\n\t\t\t\t\t\t\t? \"Workspace write was cancelled\"\n\t\t\t\t\t\t\t: \"Workspace file was committed but the artifact record failed\",\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\tlet code = \"workspace_write_failed\";\n\t\t\tlet message = \"Workspace write failed\";\n\t\t\tif (cancelled) {\n\t\t\t\tcode = \"cancelled\";\n\t\t\t\tmessage = \"Workspace write was cancelled\";\n\t\t\t} else if (error instanceof HostWriteFailureV1) {\n\t\t\t\t// Host failures carry curated messages that stand alone without the code.\n\t\t\t\tcode = error.code;\n\t\t\t\tmessage = error.message;\n\t\t\t} else {\n\t\t\t\t// Raw fs errors keep only the errno: platform messages embed absolute\n\t\t\t\t// host paths, which must not cross the model boundary.\n\t\t\t\tconst errno = (error as NodeJS.ErrnoException).code;\n\t\t\t\tif (typeof errno === \"string\" && errno !== \"\") message = `Workspace write failed (${errno})`;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tversion: 1 as const,\n\t\t\t\toperationId: request.operationId,\n\t\t\t\tstatus: cancelled ? (\"cancelled\" as const) : (\"failed\" as const),\n\t\t\t\tfileRef: request.fileRef,\n\t\t\t\tmode: request.mode,\n\t\t\t\tchanged: false,\n\t\t\t\tbytesWritten: 0,\n\t\t\t\terror: { version: 1 as const, code, message },\n\t\t\t};\n\t\t}\n\t};\n\treturn performWrite;\n}\n\n/**\n * Real Node host adapter. All local paths and bytes stay inside this host;\n * model-facing requests and results remain opaque and bounded.\n */\nexport function createNodeWorkspaceFilesWriteHostAdapterV1(\n\toptions: NodeWorkspaceFilesWriteHostOptionsV1,\n): WorkspaceFilesWriteAdapterV1 {\n\treturn createNodeWorkspaceFilesWriteAdapterV1({\n\t\tdefaultTimeoutMs: options.defaultTimeoutMs,\n\t\twrite: createNodeWorkspaceFilesWriteHostWriteV1(options),\n\t});\n}\n\nexport { applyPatch, parsePatch, resolveSandboxedPath };\n"]}
|
package/dist/host.js
CHANGED
|
@@ -225,7 +225,24 @@ export function createNodeWorkspaceFilesWriteHostWriteV1(options) {
|
|
|
225
225
|
},
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
|
-
|
|
228
|
+
let code = "workspace_write_failed";
|
|
229
|
+
let message = "Workspace write failed";
|
|
230
|
+
if (cancelled) {
|
|
231
|
+
code = "cancelled";
|
|
232
|
+
message = "Workspace write was cancelled";
|
|
233
|
+
}
|
|
234
|
+
else if (error instanceof HostWriteFailureV1) {
|
|
235
|
+
// Host failures carry curated messages that stand alone without the code.
|
|
236
|
+
code = error.code;
|
|
237
|
+
message = error.message;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
// Raw fs errors keep only the errno: platform messages embed absolute
|
|
241
|
+
// host paths, which must not cross the model boundary.
|
|
242
|
+
const errno = error.code;
|
|
243
|
+
if (typeof errno === "string" && errno !== "")
|
|
244
|
+
message = `Workspace write failed (${errno})`;
|
|
245
|
+
}
|
|
229
246
|
return {
|
|
230
247
|
version: 1,
|
|
231
248
|
operationId: request.operationId,
|
|
@@ -234,11 +251,7 @@ export function createNodeWorkspaceFilesWriteHostWriteV1(options) {
|
|
|
234
251
|
mode: request.mode,
|
|
235
252
|
changed: false,
|
|
236
253
|
bytesWritten: 0,
|
|
237
|
-
error: {
|
|
238
|
-
version: 1,
|
|
239
|
-
code,
|
|
240
|
-
message: cancelled ? "Workspace write was cancelled" : "Workspace write failed",
|
|
241
|
-
},
|
|
254
|
+
error: { version: 1, code, message },
|
|
242
255
|
};
|
|
243
256
|
}
|
|
244
257
|
};
|
package/dist/host.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1G,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACxF,OAAO,EAAE,sCAAsC,EAAE,MAAM,mBAA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BAC/E;aACD,CAAC;QACH,CAAC;IAAA,CACD,CAAC;IACF,OAAO,YAAY,CAAC;AAAA,CACpB;AAED;;;GAGG;AACH,MAAM,UAAU,0CAA0C,CACzD,OAA6C,EACd;IAC/B,OAAO,sCAAsC,CAAC;QAC7C,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;QAC1C,KAAK,EAAE,wCAAwC,CAAC,OAAO,CAAC;KACxD,CAAC,CAAC;AAAA,CACH;AAED,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { readFile as fsReadFile, mkdtemp, realpath, rename, rm, stat, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from \"node:path\";\nimport { createNodeWorkspaceFilesWriteAdapterV1 } from \"./node-adapter.ts\";\nimport type {\n\tNodeWorkspaceFilesWriteHostOptionsV1,\n\tWorkspaceFilesPatchDocumentV1,\n\tWorkspaceFilesPatchOperationV1,\n\tWorkspaceFilesWriteAdapterV1,\n\tWorkspaceFilesWriteRequestV1,\n\tWorkspaceFilesWriteResultV1,\n} from \"./types.ts\";\n\nconst MAX_ARTIFACT_BYTES_V1 = 256 * 1024 * 1024;\nconst MAX_PATCH_OPERATIONS_V1 = 16_384;\nconst MAX_PATCH_REPLACEMENT_CHARS_V1 = 1_048_576;\n\nclass HostWriteFailureV1 extends Error {\n\treadonly code: string;\n\n\tconstructor(code: string, message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"HostWriteFailureV1\";\n\t\tthis.code = code;\n\t}\n}\n\nfunction throwIfAborted(signal: AbortSignal): void {\n\tif (signal.aborted) throw new HostWriteFailureV1(\"cancelled\", \"Workspace write was cancelled\");\n}\n\nfunction digest(bytes: Uint8Array): string {\n\treturn createHash(\"sha256\").update(bytes).digest(\"hex\");\n}\n\nfunction isInside(root: string, target: string): boolean {\n\tconst relativePath = relative(root, target);\n\treturn (\n\t\trelativePath !== \"\" && relativePath !== \".\" && !relativePath.startsWith(`..${sep}`) && !isAbsolute(relativePath)\n\t);\n}\n\nfunction isWithin(root: string, target: string): boolean {\n\treturn target === root || isInside(root, target);\n}\n\nasync function resolveSandboxedPath(\n\troot: string,\n\tfileRef: string,\n\tresolveFileRef: NodeWorkspaceFilesWriteHostOptionsV1[\"resolveFileRef\"],\n\tsignal: AbortSignal,\n): Promise<string> {\n\tthrowIfAborted(signal);\n\tconst rootPath = await realpath(root);\n\tconst requested = await resolveFileRef(fileRef, signal);\n\tif (!isAbsolute(requested))\n\t\tthrow new HostWriteFailureV1(\"invalid_file_ref\", \"Resolved workspace file is not absolute\");\n\tconst candidate = resolve(requested);\n\tconst parent = await realpath(dirname(candidate));\n\tif (!isWithin(rootPath, parent))\n\t\tthrow new HostWriteFailureV1(\"sandbox_violation\", \"Workspace parent is outside the host root\");\n\tconst canonicalCandidate = join(parent, basename(candidate));\n\tlet existing: string | undefined;\n\ttry {\n\t\texisting = await realpath(canonicalCandidate);\n\t} catch {\n\t\texisting = undefined;\n\t}\n\tif (existing !== undefined && !isInside(rootPath, existing))\n\t\tthrow new HostWriteFailureV1(\"sandbox_violation\", \"Workspace file resolves outside the host root\");\n\treturn canonicalCandidate;\n}\n\nasync function readSourceArtifact(\n\trequest: WorkspaceFilesWriteRequestV1,\n\toptions: NodeWorkspaceFilesWriteHostOptionsV1,\n\tsignal: AbortSignal,\n): Promise<Uint8Array> {\n\tthrowIfAborted(signal);\n\tconst bytes = await options.readArtifact(request.sourceArtifactRef, signal);\n\tif (!(bytes instanceof Uint8Array) || bytes.byteLength > MAX_ARTIFACT_BYTES_V1)\n\t\tthrow new HostWriteFailureV1(\"artifact_budget_exceeded\", \"Workspace source artifact exceeds the host budget\");\n\treturn bytes;\n}\n\nfunction parsePatch(bytes: Uint8Array): WorkspaceFilesPatchDocumentV1 {\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes));\n\t} catch {\n\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch artifact is not valid UTF-8 JSON\");\n\t}\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value))\n\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch document must be an object\");\n\tconst record = value as Record<string, unknown>;\n\tif (record.version !== 1 || !Array.isArray(record.operations) || record.operations.length > MAX_PATCH_OPERATIONS_V1)\n\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch document is invalid\");\n\tlet previousEnd = 0;\n\tconst operations: WorkspaceFilesPatchOperationV1[] = [];\n\tfor (const item of record.operations) {\n\t\tif (item === null || typeof item !== \"object\" || Array.isArray(item))\n\t\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch operation is invalid\");\n\t\tconst operation = item as Record<string, unknown>;\n\t\tif (\n\t\t\t!Number.isSafeInteger(operation.start) ||\n\t\t\t!Number.isSafeInteger(operation.end) ||\n\t\t\t(operation.start as number) < 0 ||\n\t\t\t(operation.end as number) < (operation.start as number) ||\n\t\t\ttypeof operation.replacement !== \"string\" ||\n\t\t\t[...(operation.replacement as string)].length > MAX_PATCH_REPLACEMENT_CHARS_V1 ||\n\t\t\t(operation.start as number) < previousEnd\n\t\t)\n\t\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch operation is invalid\");\n\t\tpreviousEnd = operation.end as number;\n\t\toperations.push({\n\t\t\tstart: operation.start as number,\n\t\t\tend: operation.end as number,\n\t\t\treplacement: operation.replacement as string,\n\t\t});\n\t}\n\treturn { version: 1, operations };\n}\n\nfunction applyPatch(source: Uint8Array, patchBytes: Uint8Array): Uint8Array {\n\tconst patch = parsePatch(patchBytes);\n\tconst text = new TextDecoder(\"utf-8\", { fatal: true }).decode(source);\n\tlet output = text;\n\tfor (let index = patch.operations.length - 1; index >= 0; index -= 1) {\n\t\tconst operation = patch.operations[index]!;\n\t\tif (operation.end > output.length)\n\t\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch range exceeds the file\");\n\t\toutput = `${output.slice(0, operation.start)}${operation.replacement}${output.slice(operation.end)}`;\n\t}\n\treturn new TextEncoder().encode(output);\n}\n\nasync function atomicWrite(path: string, bytes: Uint8Array, signal: AbortSignal): Promise<void> {\n\tthrowIfAborted(signal);\n\tconst directory = await mkdtemp(join(dirname(path), \".agent-forge-write-\"));\n\tconst temporary = join(directory, basename(path));\n\ttry {\n\t\tawait writeFile(temporary, bytes);\n\t\tthrowIfAborted(signal);\n\t\tawait rename(temporary, path);\n\t} finally {\n\t\tawait rm(directory, { recursive: true, force: true }).catch(() => undefined);\n\t}\n}\n\n/**\n * Host-level write: resolves the sandboxed path, then serializes the\n * read-check-commit critical section per resolved canonical path so concurrent\n * requests cannot both pass the expectedVersion check (single-flight). After\n * the rename committed new bytes, a later artifact-record failure or\n * cancellation is reported with `committed: true` and a truthful changed state\n * instead of masking the write that already reached the disk. The timeout and\n * stop race of the full adapter lives in node-adapter; this seam exposes the\n * host mapping itself.\n */\nexport function createNodeWorkspaceFilesWriteHostWriteV1(\n\toptions: NodeWorkspaceFilesWriteHostOptionsV1,\n): (request: WorkspaceFilesWriteRequestV1, signal: AbortSignal) => Promise<WorkspaceFilesWriteResultV1> {\n\tif (!isAbsolute(options.root)) throw new Error(\"root must be an absolute path\");\n\tconst writeGates = new Map<string, Promise<void>>();\n\tconst runSerialized = async <T>(key: string, work: () => Promise<T>): Promise<T> => {\n\t\tconst previous = writeGates.get(key);\n\t\tlet releaseGate: (() => void) | undefined;\n\t\tconst gate = new Promise<void>((resolveGate) => {\n\t\t\treleaseGate = resolveGate;\n\t\t});\n\t\tconst chained =\n\t\t\tprevious === undefined\n\t\t\t\t? gate\n\t\t\t\t: previous.then(\n\t\t\t\t\t\t() => gate,\n\t\t\t\t\t\t() => gate,\n\t\t\t\t\t);\n\t\twriteGates.set(key, chained);\n\t\ttry {\n\t\t\tawait previous;\n\t\t\treturn await work();\n\t\t} finally {\n\t\t\treleaseGate?.();\n\t\t\tif (writeGates.get(key) === chained) writeGates.delete(key);\n\t\t}\n\t};\n\tconst performWrite = async (\n\t\trequest: WorkspaceFilesWriteRequestV1,\n\t\tsignal: AbortSignal,\n\t): Promise<WorkspaceFilesWriteResultV1> => {\n\t\t/** Set only after the rename committed new bytes, so later failures cannot mask the disk state. */\n\t\tconst commit = { committed: false, bytes: 0 };\n\t\ttry {\n\t\t\tthrowIfAborted(signal);\n\t\t\tconst path = await resolveSandboxedPath(options.root, request.fileRef, options.resolveFileRef, signal);\n\t\t\treturn await runSerialized(path, async () => {\n\t\t\t\tthrowIfAborted(signal);\n\t\t\t\tlet current = new Uint8Array();\n\t\t\t\tlet exists = true;\n\t\t\t\ttry {\n\t\t\t\t\tconst information = await stat(path);\n\t\t\t\t\tif (!information.isFile())\n\t\t\t\t\t\tthrow new HostWriteFailureV1(\"invalid_file_ref\", \"Workspace target is not a file\");\n\t\t\t\t\tcurrent = new Uint8Array(\n\t\t\t\t\t\tawait (options.readWorkspaceFile === undefined\n\t\t\t\t\t\t\t? fsReadFile(path)\n\t\t\t\t\t\t\t: options.readWorkspaceFile(path, signal)),\n\t\t\t\t\t);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof HostWriteFailureV1) throw error;\n\t\t\t\t\tif (error === null || typeof error !== \"object\" || (error as { code?: unknown }).code !== \"ENOENT\")\n\t\t\t\t\t\tthrow new HostWriteFailureV1(\"read_failed\", \"Workspace target could not be read\");\n\t\t\t\t\texists = false;\n\t\t\t\t}\n\t\t\t\tif (!exists && request.createIfMissing !== true)\n\t\t\t\t\tthrow new HostWriteFailureV1(\"file_missing\", \"Workspace target does not exist\");\n\t\t\t\tif (request.expectedVersion !== undefined && request.expectedVersion !== digest(current))\n\t\t\t\t\tthrow new HostWriteFailureV1(\n\t\t\t\t\t\t\"version_conflict\",\n\t\t\t\t\t\t\"Workspace target version does not match expectedVersion\",\n\t\t\t\t\t);\n\t\t\t\tconst source = await readSourceArtifact(request, options, signal);\n\t\t\t\tconst next = request.mode === \"replace\" ? source : applyPatch(current, source);\n\t\t\t\tconst changed = digest(current) !== digest(next);\n\t\t\t\tif (changed) {\n\t\t\t\t\tawait atomicWrite(path, next, signal);\n\t\t\t\t\tcommit.committed = true;\n\t\t\t\t\tcommit.bytes = next.byteLength;\n\t\t\t\t}\n\t\t\t\tconst outputArtifactRef =\n\t\t\t\t\toptions.writeArtifact === undefined\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: (\n\t\t\t\t\t\t\t\tawait options.writeArtifact(\n\t\t\t\t\t\t\t\t\t{ operationId: request.operationId, fileRef: request.fileRef, bytes: next },\n\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t).artifactRef;\n\t\t\t\treturn {\n\t\t\t\t\tversion: 1 as const,\n\t\t\t\t\toperationId: request.operationId,\n\t\t\t\t\tstatus: \"succeeded\" as const,\n\t\t\t\t\tfileRef: request.fileRef,\n\t\t\t\t\tmode: request.mode,\n\t\t\t\t\tchanged,\n\t\t\t\t\tbytesWritten: changed ? next.byteLength : 0,\n\t\t\t\t\t...(outputArtifactRef === undefined ? {} : { outputArtifactRef }),\n\t\t\t\t\tversionToken: digest(next),\n\t\t\t\t};\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tconst cancelled = signal.aborted || (error instanceof HostWriteFailureV1 && error.code === \"cancelled\");\n\t\t\tif (commit.committed) {\n\t\t\t\treturn {\n\t\t\t\t\tversion: 1 as const,\n\t\t\t\t\toperationId: request.operationId,\n\t\t\t\t\tstatus: cancelled ? (\"cancelled\" as const) : (\"failed\" as const),\n\t\t\t\t\tfileRef: request.fileRef,\n\t\t\t\t\tmode: request.mode,\n\t\t\t\t\tchanged: true,\n\t\t\t\t\tbytesWritten: commit.bytes,\n\t\t\t\t\tcommitted: true,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tversion: 1 as const,\n\t\t\t\t\t\tcode: cancelled ? \"cancelled\" : \"artifact_record_failed\",\n\t\t\t\t\t\tmessage: cancelled\n\t\t\t\t\t\t\t? \"Workspace write was cancelled\"\n\t\t\t\t\t\t\t: \"Workspace file was committed but the artifact record failed\",\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst code = cancelled ? \"cancelled\" : error instanceof HostWriteFailureV1 ? error.code : \"adapter_failed\";\n\t\t\treturn {\n\t\t\t\tversion: 1 as const,\n\t\t\t\toperationId: request.operationId,\n\t\t\t\tstatus: cancelled ? (\"cancelled\" as const) : (\"failed\" as const),\n\t\t\t\tfileRef: request.fileRef,\n\t\t\t\tmode: request.mode,\n\t\t\t\tchanged: false,\n\t\t\t\tbytesWritten: 0,\n\t\t\t\terror: {\n\t\t\t\t\tversion: 1 as const,\n\t\t\t\t\tcode,\n\t\t\t\t\tmessage: cancelled ? \"Workspace write was cancelled\" : \"Workspace write failed\",\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t};\n\treturn performWrite;\n}\n\n/**\n * Real Node host adapter. All local paths and bytes stay inside this host;\n * model-facing requests and results remain opaque and bounded.\n */\nexport function createNodeWorkspaceFilesWriteHostAdapterV1(\n\toptions: NodeWorkspaceFilesWriteHostOptionsV1,\n): WorkspaceFilesWriteAdapterV1 {\n\treturn createNodeWorkspaceFilesWriteAdapterV1({\n\t\tdefaultTimeoutMs: options.defaultTimeoutMs,\n\t\twrite: createNodeWorkspaceFilesWriteHostWriteV1(options),\n\t});\n}\n\nexport { applyPatch, parsePatch, resolveSandboxedPath };\n"]}
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1G,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU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OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE;oBAAE,OAAO,GAAG,2BAA2B,KAAK,GAAG,CAAC;YAC9F,CAAC;YACD,OAAO;gBACN,OAAO,EAAE,CAAU;gBACnB,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAE,WAAqB,CAAC,CAAC,CAAE,QAAkB;gBAChE,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,OAAO,EAAE,KAAK;gBACd,YAAY,EAAE,CAAC;gBACf,KAAK,EAAE,EAAE,OAAO,EAAE,CAAU,EAAE,IAAI,EAAE,OAAO,EAAE;aAC7C,CAAC;QACH,CAAC;IAAA,CACD,CAAC;IACF,OAAO,YAAY,CAAC;AAAA,CACpB;AAED;;;GAGG;AACH,MAAM,UAAU,0CAA0C,CACzD,OAA6C,EACd;IAC/B,OAAO,sCAAsC,CAAC;QAC7C,gBAAgB,EAAE,OAAO,CAAC,gBAAgB;QAC1C,KAAK,EAAE,wCAAwC,CAAC,OAAO,CAAC;KACxD,CAAC,CAAC;AAAA,CACH;AAED,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { readFile as fsReadFile, mkdtemp, realpath, rename, rm, stat, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from \"node:path\";\nimport { createNodeWorkspaceFilesWriteAdapterV1 } from \"./node-adapter.ts\";\nimport type {\n\tNodeWorkspaceFilesWriteHostOptionsV1,\n\tWorkspaceFilesPatchDocumentV1,\n\tWorkspaceFilesPatchOperationV1,\n\tWorkspaceFilesWriteAdapterV1,\n\tWorkspaceFilesWriteRequestV1,\n\tWorkspaceFilesWriteResultV1,\n} from \"./types.ts\";\n\nconst MAX_ARTIFACT_BYTES_V1 = 256 * 1024 * 1024;\nconst MAX_PATCH_OPERATIONS_V1 = 16_384;\nconst MAX_PATCH_REPLACEMENT_CHARS_V1 = 1_048_576;\n\nclass HostWriteFailureV1 extends Error {\n\treadonly code: string;\n\n\tconstructor(code: string, message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"HostWriteFailureV1\";\n\t\tthis.code = code;\n\t}\n}\n\nfunction throwIfAborted(signal: AbortSignal): void {\n\tif (signal.aborted) throw new HostWriteFailureV1(\"cancelled\", \"Workspace write was cancelled\");\n}\n\nfunction digest(bytes: Uint8Array): string {\n\treturn createHash(\"sha256\").update(bytes).digest(\"hex\");\n}\n\nfunction isInside(root: string, target: string): boolean {\n\tconst relativePath = relative(root, target);\n\treturn (\n\t\trelativePath !== \"\" && relativePath !== \".\" && !relativePath.startsWith(`..${sep}`) && !isAbsolute(relativePath)\n\t);\n}\n\nfunction isWithin(root: string, target: string): boolean {\n\treturn target === root || isInside(root, target);\n}\n\nasync function resolveSandboxedPath(\n\troot: string,\n\tfileRef: string,\n\tresolveFileRef: NodeWorkspaceFilesWriteHostOptionsV1[\"resolveFileRef\"],\n\tsignal: AbortSignal,\n): Promise<string> {\n\tthrowIfAborted(signal);\n\tconst rootPath = await realpath(root);\n\tconst requested = await resolveFileRef(fileRef, signal);\n\tif (!isAbsolute(requested))\n\t\tthrow new HostWriteFailureV1(\"invalid_file_ref\", \"Resolved workspace file is not absolute\");\n\tconst candidate = resolve(requested);\n\tconst parent = await realpath(dirname(candidate));\n\tif (!isWithin(rootPath, parent))\n\t\tthrow new HostWriteFailureV1(\"sandbox_violation\", \"Workspace parent is outside the host root\");\n\tconst canonicalCandidate = join(parent, basename(candidate));\n\tlet existing: string | undefined;\n\ttry {\n\t\texisting = await realpath(canonicalCandidate);\n\t} catch {\n\t\texisting = undefined;\n\t}\n\tif (existing !== undefined && !isInside(rootPath, existing))\n\t\tthrow new HostWriteFailureV1(\"sandbox_violation\", \"Workspace file resolves outside the host root\");\n\treturn canonicalCandidate;\n}\n\nasync function readSourceArtifact(\n\trequest: WorkspaceFilesWriteRequestV1,\n\toptions: NodeWorkspaceFilesWriteHostOptionsV1,\n\tsignal: AbortSignal,\n): Promise<Uint8Array> {\n\tthrowIfAborted(signal);\n\tconst bytes = await options.readArtifact(request.sourceArtifactRef, signal);\n\tif (!(bytes instanceof Uint8Array) || bytes.byteLength > MAX_ARTIFACT_BYTES_V1)\n\t\tthrow new HostWriteFailureV1(\"artifact_budget_exceeded\", \"Workspace source artifact exceeds the host budget\");\n\treturn bytes;\n}\n\nfunction parsePatch(bytes: Uint8Array): WorkspaceFilesPatchDocumentV1 {\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes));\n\t} catch {\n\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch artifact is not valid UTF-8 JSON\");\n\t}\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value))\n\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch document must be an object\");\n\tconst record = value as Record<string, unknown>;\n\tif (record.version !== 1 || !Array.isArray(record.operations) || record.operations.length > MAX_PATCH_OPERATIONS_V1)\n\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch document is invalid\");\n\tlet previousEnd = 0;\n\tconst operations: WorkspaceFilesPatchOperationV1[] = [];\n\tfor (const item of record.operations) {\n\t\tif (item === null || typeof item !== \"object\" || Array.isArray(item))\n\t\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch operation is invalid\");\n\t\tconst operation = item as Record<string, unknown>;\n\t\tif (\n\t\t\t!Number.isSafeInteger(operation.start) ||\n\t\t\t!Number.isSafeInteger(operation.end) ||\n\t\t\t(operation.start as number) < 0 ||\n\t\t\t(operation.end as number) < (operation.start as number) ||\n\t\t\ttypeof operation.replacement !== \"string\" ||\n\t\t\t[...(operation.replacement as string)].length > MAX_PATCH_REPLACEMENT_CHARS_V1 ||\n\t\t\t(operation.start as number) < previousEnd\n\t\t)\n\t\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch operation is invalid\");\n\t\tpreviousEnd = operation.end as number;\n\t\toperations.push({\n\t\t\tstart: operation.start as number,\n\t\t\tend: operation.end as number,\n\t\t\treplacement: operation.replacement as string,\n\t\t});\n\t}\n\treturn { version: 1, operations };\n}\n\nfunction applyPatch(source: Uint8Array, patchBytes: Uint8Array): Uint8Array {\n\tconst patch = parsePatch(patchBytes);\n\tconst text = new TextDecoder(\"utf-8\", { fatal: true }).decode(source);\n\tlet output = text;\n\tfor (let index = patch.operations.length - 1; index >= 0; index -= 1) {\n\t\tconst operation = patch.operations[index]!;\n\t\tif (operation.end > output.length)\n\t\t\tthrow new HostWriteFailureV1(\"invalid_patch\", \"Workspace patch range exceeds the file\");\n\t\toutput = `${output.slice(0, operation.start)}${operation.replacement}${output.slice(operation.end)}`;\n\t}\n\treturn new TextEncoder().encode(output);\n}\n\nasync function atomicWrite(path: string, bytes: Uint8Array, signal: AbortSignal): Promise<void> {\n\tthrowIfAborted(signal);\n\tconst directory = await mkdtemp(join(dirname(path), \".agent-forge-write-\"));\n\tconst temporary = join(directory, basename(path));\n\ttry {\n\t\tawait writeFile(temporary, bytes);\n\t\tthrowIfAborted(signal);\n\t\tawait rename(temporary, path);\n\t} finally {\n\t\tawait rm(directory, { recursive: true, force: true }).catch(() => undefined);\n\t}\n}\n\n/**\n * Host-level write: resolves the sandboxed path, then serializes the\n * read-check-commit critical section per resolved canonical path so concurrent\n * requests cannot both pass the expectedVersion check (single-flight). After\n * the rename committed new bytes, a later artifact-record failure or\n * cancellation is reported with `committed: true` and a truthful changed state\n * instead of masking the write that already reached the disk. The timeout and\n * stop race of the full adapter lives in node-adapter; this seam exposes the\n * host mapping itself.\n */\nexport function createNodeWorkspaceFilesWriteHostWriteV1(\n\toptions: NodeWorkspaceFilesWriteHostOptionsV1,\n): (request: WorkspaceFilesWriteRequestV1, signal: AbortSignal) => Promise<WorkspaceFilesWriteResultV1> {\n\tif (!isAbsolute(options.root)) throw new Error(\"root must be an absolute path\");\n\tconst writeGates = new Map<string, Promise<void>>();\n\tconst runSerialized = async <T>(key: string, work: () => Promise<T>): Promise<T> => {\n\t\tconst previous = writeGates.get(key);\n\t\tlet releaseGate: (() => void) | undefined;\n\t\tconst gate = new Promise<void>((resolveGate) => {\n\t\t\treleaseGate = resolveGate;\n\t\t});\n\t\tconst chained =\n\t\t\tprevious === undefined\n\t\t\t\t? gate\n\t\t\t\t: previous.then(\n\t\t\t\t\t\t() => gate,\n\t\t\t\t\t\t() => gate,\n\t\t\t\t\t);\n\t\twriteGates.set(key, chained);\n\t\ttry {\n\t\t\tawait previous;\n\t\t\treturn await work();\n\t\t} finally {\n\t\t\treleaseGate?.();\n\t\t\tif (writeGates.get(key) === chained) writeGates.delete(key);\n\t\t}\n\t};\n\tconst performWrite = async (\n\t\trequest: WorkspaceFilesWriteRequestV1,\n\t\tsignal: AbortSignal,\n\t): Promise<WorkspaceFilesWriteResultV1> => {\n\t\t/** Set only after the rename committed new bytes, so later failures cannot mask the disk state. */\n\t\tconst commit = { committed: false, bytes: 0 };\n\t\ttry {\n\t\t\tthrowIfAborted(signal);\n\t\t\tconst path = await resolveSandboxedPath(options.root, request.fileRef, options.resolveFileRef, signal);\n\t\t\treturn await runSerialized(path, async () => {\n\t\t\t\tthrowIfAborted(signal);\n\t\t\t\tlet current = new Uint8Array();\n\t\t\t\tlet exists = true;\n\t\t\t\ttry {\n\t\t\t\t\tconst information = await stat(path);\n\t\t\t\t\tif (!information.isFile())\n\t\t\t\t\t\tthrow new HostWriteFailureV1(\"invalid_file_ref\", \"Workspace target is not a file\");\n\t\t\t\t\tcurrent = new Uint8Array(\n\t\t\t\t\t\tawait (options.readWorkspaceFile === undefined\n\t\t\t\t\t\t\t? fsReadFile(path)\n\t\t\t\t\t\t\t: options.readWorkspaceFile(path, signal)),\n\t\t\t\t\t);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof HostWriteFailureV1) throw error;\n\t\t\t\t\tif (error === null || typeof error !== \"object\" || (error as { code?: unknown }).code !== \"ENOENT\")\n\t\t\t\t\t\tthrow new HostWriteFailureV1(\"read_failed\", \"Workspace target could not be read\");\n\t\t\t\t\texists = false;\n\t\t\t\t}\n\t\t\t\tif (!exists && request.createIfMissing !== true)\n\t\t\t\t\tthrow new HostWriteFailureV1(\"file_missing\", \"Workspace target does not exist\");\n\t\t\t\tif (request.expectedVersion !== undefined && request.expectedVersion !== digest(current))\n\t\t\t\t\tthrow new HostWriteFailureV1(\n\t\t\t\t\t\t\"version_conflict\",\n\t\t\t\t\t\t\"Workspace target version does not match expectedVersion\",\n\t\t\t\t\t);\n\t\t\t\tconst source = await readSourceArtifact(request, options, signal);\n\t\t\t\tconst next = request.mode === \"replace\" ? source : applyPatch(current, source);\n\t\t\t\tconst changed = digest(current) !== digest(next);\n\t\t\t\tif (changed) {\n\t\t\t\t\tawait atomicWrite(path, next, signal);\n\t\t\t\t\tcommit.committed = true;\n\t\t\t\t\tcommit.bytes = next.byteLength;\n\t\t\t\t}\n\t\t\t\tconst outputArtifactRef =\n\t\t\t\t\toptions.writeArtifact === undefined\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: (\n\t\t\t\t\t\t\t\tawait options.writeArtifact(\n\t\t\t\t\t\t\t\t\t{ operationId: request.operationId, fileRef: request.fileRef, bytes: next },\n\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t).artifactRef;\n\t\t\t\treturn {\n\t\t\t\t\tversion: 1 as const,\n\t\t\t\t\toperationId: request.operationId,\n\t\t\t\t\tstatus: \"succeeded\" as const,\n\t\t\t\t\tfileRef: request.fileRef,\n\t\t\t\t\tmode: request.mode,\n\t\t\t\t\tchanged,\n\t\t\t\t\tbytesWritten: changed ? next.byteLength : 0,\n\t\t\t\t\t...(outputArtifactRef === undefined ? {} : { outputArtifactRef }),\n\t\t\t\t\tversionToken: digest(next),\n\t\t\t\t};\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tconst cancelled = signal.aborted || (error instanceof HostWriteFailureV1 && error.code === \"cancelled\");\n\t\t\tif (commit.committed) {\n\t\t\t\treturn {\n\t\t\t\t\tversion: 1 as const,\n\t\t\t\t\toperationId: request.operationId,\n\t\t\t\t\tstatus: cancelled ? (\"cancelled\" as const) : (\"failed\" as const),\n\t\t\t\t\tfileRef: request.fileRef,\n\t\t\t\t\tmode: request.mode,\n\t\t\t\t\tchanged: true,\n\t\t\t\t\tbytesWritten: commit.bytes,\n\t\t\t\t\tcommitted: true,\n\t\t\t\t\terror: {\n\t\t\t\t\t\tversion: 1 as const,\n\t\t\t\t\t\tcode: cancelled ? \"cancelled\" : \"artifact_record_failed\",\n\t\t\t\t\t\tmessage: cancelled\n\t\t\t\t\t\t\t? \"Workspace write was cancelled\"\n\t\t\t\t\t\t\t: \"Workspace file was committed but the artifact record failed\",\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\t\t\tlet code = \"workspace_write_failed\";\n\t\t\tlet message = \"Workspace write failed\";\n\t\t\tif (cancelled) {\n\t\t\t\tcode = \"cancelled\";\n\t\t\t\tmessage = \"Workspace write was cancelled\";\n\t\t\t} else if (error instanceof HostWriteFailureV1) {\n\t\t\t\t// Host failures carry curated messages that stand alone without the code.\n\t\t\t\tcode = error.code;\n\t\t\t\tmessage = error.message;\n\t\t\t} else {\n\t\t\t\t// Raw fs errors keep only the errno: platform messages embed absolute\n\t\t\t\t// host paths, which must not cross the model boundary.\n\t\t\t\tconst errno = (error as NodeJS.ErrnoException).code;\n\t\t\t\tif (typeof errno === \"string\" && errno !== \"\") message = `Workspace write failed (${errno})`;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tversion: 1 as const,\n\t\t\t\toperationId: request.operationId,\n\t\t\t\tstatus: cancelled ? (\"cancelled\" as const) : (\"failed\" as const),\n\t\t\t\tfileRef: request.fileRef,\n\t\t\t\tmode: request.mode,\n\t\t\t\tchanged: false,\n\t\t\t\tbytesWritten: 0,\n\t\t\t\terror: { version: 1 as const, code, message },\n\t\t\t};\n\t\t}\n\t};\n\treturn performWrite;\n}\n\n/**\n * Real Node host adapter. All local paths and bytes stay inside this host;\n * model-facing requests and results remain opaque and bounded.\n */\nexport function createNodeWorkspaceFilesWriteHostAdapterV1(\n\toptions: NodeWorkspaceFilesWriteHostOptionsV1,\n): WorkspaceFilesWriteAdapterV1 {\n\treturn createNodeWorkspaceFilesWriteAdapterV1({\n\t\tdefaultTimeoutMs: options.defaultTimeoutMs,\n\t\twrite: createNodeWorkspaceFilesWriteHostWriteV1(options),\n\t});\n}\n\nexport { applyPatch, parsePatch, resolveSandboxedPath };\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.26",
|
|
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.26"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"shx": "0.3.4",
|