@dailephd/my-centcom 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/README.md +10 -5
  2. package/apps/daemon/dist/artifacts/returnSnapshots.d.ts +12 -0
  3. package/apps/daemon/dist/artifacts/returnSnapshots.js +41 -0
  4. package/apps/daemon/dist/bootstrap/app.d.ts +21 -0
  5. package/apps/daemon/dist/bootstrap/app.js +27 -0
  6. package/apps/daemon/dist/bootstrap/installLayout.d.ts +81 -0
  7. package/apps/daemon/dist/bootstrap/installLayout.js +164 -0
  8. package/apps/daemon/dist/bootstrap/main.d.ts +14 -0
  9. package/apps/daemon/dist/bootstrap/main.js +141 -0
  10. package/apps/daemon/dist/bootstrap/operatorConsole.d.ts +75 -0
  11. package/apps/daemon/dist/bootstrap/operatorConsole.js +293 -0
  12. package/apps/daemon/dist/bootstrap/privateDataRoot.d.ts +38 -0
  13. package/apps/daemon/dist/bootstrap/privateDataRoot.js +204 -0
  14. package/apps/daemon/dist/bootstrap/secureMain.d.ts +118 -0
  15. package/apps/daemon/dist/bootstrap/secureMain.js +403 -0
  16. package/apps/daemon/dist/bootstrap/setup.d.ts +93 -0
  17. package/apps/daemon/dist/bootstrap/setup.js +738 -0
  18. package/apps/daemon/dist/context/changeProposal.d.ts +97 -0
  19. package/apps/daemon/dist/context/changeProposal.js +259 -0
  20. package/apps/daemon/dist/context/gitEvidence.d.ts +88 -0
  21. package/apps/daemon/dist/context/gitEvidence.js +332 -0
  22. package/apps/daemon/dist/context/gitObservation.d.ts +30 -0
  23. package/apps/daemon/dist/context/gitObservation.js +113 -0
  24. package/apps/daemon/dist/context/projectReadIssuer.d.ts +68 -0
  25. package/apps/daemon/dist/context/projectReadIssuer.js +158 -0
  26. package/apps/daemon/dist/context/projectReadService.d.ts +153 -0
  27. package/apps/daemon/dist/context/projectReadService.js +652 -0
  28. package/apps/daemon/dist/context/projectViewService.d.ts +85 -0
  29. package/apps/daemon/dist/context/projectViewService.js +332 -0
  30. package/apps/daemon/dist/context/proposalRecorder.d.ts +11 -0
  31. package/apps/daemon/dist/context/proposalRecorder.js +19 -0
  32. package/apps/daemon/dist/plugins/drivers/codexMcpConfig.d.ts +40 -0
  33. package/apps/daemon/dist/plugins/drivers/codexMcpConfig.js +73 -0
  34. package/apps/daemon/dist/plugins/drivers/codexModelCompatibility.d.ts +49 -0
  35. package/apps/daemon/dist/plugins/drivers/codexModelCompatibility.js +70 -0
  36. package/apps/daemon/dist/plugins/drivers/fakePluginDriver.d.ts +16 -0
  37. package/apps/daemon/dist/plugins/drivers/fakePluginDriver.js +115 -0
  38. package/apps/daemon/dist/plugins/drivers/finiteCliDriver.d.ts +153 -0
  39. package/apps/daemon/dist/plugins/drivers/finiteCliDriver.js +505 -0
  40. package/apps/daemon/dist/plugins/registry/operationCatalog.d.ts +23 -0
  41. package/apps/daemon/dist/plugins/registry/operationCatalog.js +41 -0
  42. package/apps/daemon/dist/plugins/registry/registryOperationCatalog.d.ts +14 -0
  43. package/apps/daemon/dist/plugins/registry/registryOperationCatalog.js +29 -0
  44. package/apps/daemon/dist/plugins/registry/verifiedCapabilityRegistry.d.ts +151 -0
  45. package/apps/daemon/dist/plugins/registry/verifiedCapabilityRegistry.js +579 -0
  46. package/apps/daemon/dist/projects/codingAuthority.d.ts +102 -0
  47. package/apps/daemon/dist/projects/codingAuthority.js +244 -0
  48. package/apps/daemon/dist/projects/fixtureAuthorization.d.ts +54 -0
  49. package/apps/daemon/dist/projects/fixtureAuthorization.js +172 -0
  50. package/apps/daemon/dist/projects/pairedAuthority.d.ts +158 -0
  51. package/apps/daemon/dist/projects/pairedAuthority.js +273 -0
  52. package/apps/daemon/dist/projects/trustedCliConsent.d.ts +47 -0
  53. package/apps/daemon/dist/projects/trustedCliConsent.js +84 -0
  54. package/apps/daemon/dist/runs/changeApplier.d.ts +59 -0
  55. package/apps/daemon/dist/runs/changeApplier.js +319 -0
  56. package/apps/daemon/dist/runs/codingWorkflowService.d.ts +283 -0
  57. package/apps/daemon/dist/runs/codingWorkflowService.js +785 -0
  58. package/apps/daemon/dist/runs/durableIntentCoordinator.d.ts +72 -0
  59. package/apps/daemon/dist/runs/durableIntentCoordinator.js +160 -0
  60. package/apps/daemon/dist/runs/inMemoryCoordinator.d.ts +55 -0
  61. package/apps/daemon/dist/runs/inMemoryCoordinator.js +375 -0
  62. package/apps/daemon/dist/runs/runExecutor.d.ts +154 -0
  63. package/apps/daemon/dist/runs/runExecutor.js +295 -0
  64. package/apps/daemon/dist/runs/workflowService.d.ts +185 -0
  65. package/apps/daemon/dist/runs/workflowService.js +300 -0
  66. package/apps/daemon/dist/runtime/boundedProcessHost.d.ts +111 -0
  67. package/apps/daemon/dist/runtime/boundedProcessHost.js +752 -0
  68. package/apps/daemon/dist/runtime/evidenceRedaction.d.ts +30 -0
  69. package/apps/daemon/dist/runtime/evidenceRedaction.js +79 -0
  70. package/apps/daemon/dist/runtime/executionDiagnostics.d.ts +134 -0
  71. package/apps/daemon/dist/runtime/executionDiagnostics.js +213 -0
  72. package/apps/daemon/dist/runtime/modelExecutionPolicy.d.ts +22 -0
  73. package/apps/daemon/dist/runtime/modelExecutionPolicy.js +19 -0
  74. package/apps/daemon/dist/runtime/mxcExecution.d.ts +12 -0
  75. package/apps/daemon/dist/runtime/mxcExecution.js +163 -0
  76. package/apps/daemon/dist/runtime/mxcIntegrity.d.ts +24 -0
  77. package/apps/daemon/dist/runtime/mxcIntegrity.js +81 -0
  78. package/apps/daemon/dist/runtime/mxcWorker.d.ts +2 -0
  79. package/apps/daemon/dist/runtime/mxcWorker.js +45 -0
  80. package/apps/daemon/dist/runtime/provisionedExecution.d.ts +150 -0
  81. package/apps/daemon/dist/runtime/provisionedExecution.js +653 -0
  82. package/apps/daemon/dist/runtime/testExecution.d.ts +76 -0
  83. package/apps/daemon/dist/runtime/testExecution.js +106 -0
  84. package/apps/daemon/dist/runtime/testProfiles.d.ts +10 -0
  85. package/apps/daemon/dist/runtime/testProfiles.js +4 -0
  86. package/apps/daemon/dist/runtime/trustedAgentStaging.d.ts +89 -0
  87. package/apps/daemon/dist/runtime/trustedAgentStaging.js +262 -0
  88. package/apps/daemon/dist/runtime/trustedCaBundle.d.ts +77 -0
  89. package/apps/daemon/dist/runtime/trustedCaBundle.js +125 -0
  90. package/apps/daemon/dist/runtime/windows/windowsJobSupervisor.d.ts +166 -0
  91. package/apps/daemon/dist/runtime/windows/windowsJobSupervisor.js +521 -0
  92. package/apps/daemon/dist/storage/diagnosticLog.d.ts +63 -0
  93. package/apps/daemon/dist/storage/diagnosticLog.js +136 -0
  94. package/apps/daemon/dist/storage/executionTelemetry.d.ts +63 -0
  95. package/apps/daemon/dist/storage/executionTelemetry.js +247 -0
  96. package/apps/daemon/dist/storage/protectedSecrets.d.ts +39 -0
  97. package/apps/daemon/dist/storage/protectedSecrets.js +106 -0
  98. package/apps/daemon/dist/storage/sqliteLedger.d.ts +786 -0
  99. package/apps/daemon/dist/storage/sqliteLedger.js +1303 -0
  100. package/apps/daemon/dist/transports/http/dispatch.d.ts +43 -0
  101. package/apps/daemon/dist/transports/http/dispatch.js +405 -0
  102. package/apps/daemon/dist/transports/http/secureRoutes.d.ts +40 -0
  103. package/apps/daemon/dist/transports/http/secureRoutes.js +332 -0
  104. package/apps/daemon/dist/transports/http/workflowRoutes.d.ts +41 -0
  105. package/apps/daemon/dist/transports/http/workflowRoutes.js +473 -0
  106. package/apps/daemon/dist/transports/mcp/localProjectReadServer.d.ts +182 -0
  107. package/apps/daemon/dist/transports/mcp/localProjectReadServer.js +221 -0
  108. package/apps/daemon/dist/transports/native/nativeHost.d.ts +24 -0
  109. package/apps/daemon/dist/transports/native/nativeHost.js +344 -0
  110. package/apps/daemon/package.json +24 -0
  111. package/apps/daemon/src/runtime/benign/referenceEcho.mjs +27 -0
  112. package/apps/daemon/src/runtime/windows/buildSupervisor.mjs +87 -0
  113. package/apps/daemon/src/runtime/windows/supervisorMain.cs +676 -0
  114. package/apps/extension/manifest.secure.json +25 -0
  115. package/apps/extension/scripts/build.mjs +173 -0
  116. package/apps/extension/src/background/secureWorker.ts +1595 -0
  117. package/apps/extension/src/background/serviceWorker.ts +892 -0
  118. package/apps/extension/src/content/captureSelection.ts +64 -0
  119. package/apps/extension/src/content/secureInsert.ts +207 -0
  120. package/apps/extension/src/probe/index.html +41 -0
  121. package/apps/extension/src/probe/main.ts +201 -0
  122. package/apps/extension/src/sidepanel/index.html +203 -0
  123. package/apps/extension/src/sidepanel/main.ts +903 -0
  124. package/package.json +19 -3
  125. package/packages/contracts/dist/artifacts.d.ts +66 -0
  126. package/packages/contracts/dist/artifacts.js +64 -0
  127. package/packages/contracts/dist/automation.d.ts +540 -0
  128. package/packages/contracts/dist/automation.js +191 -0
  129. package/packages/contracts/dist/browser.d.ts +251 -0
  130. package/packages/contracts/dist/browser.js +131 -0
  131. package/packages/contracts/dist/context.d.ts +71 -0
  132. package/packages/contracts/dist/context.js +73 -0
  133. package/packages/contracts/dist/diagnostics.d.ts +99 -0
  134. package/packages/contracts/dist/diagnostics.js +284 -0
  135. package/packages/contracts/dist/effects.d.ts +42 -0
  136. package/packages/contracts/dist/effects.js +42 -0
  137. package/packages/contracts/dist/errors.d.ts +75 -0
  138. package/packages/contracts/dist/errors.js +70 -0
  139. package/packages/contracts/dist/events.d.ts +50 -0
  140. package/packages/contracts/dist/events.js +34 -0
  141. package/packages/contracts/dist/executionDiagnostics.d.ts +212 -0
  142. package/packages/contracts/dist/executionDiagnostics.js +101 -0
  143. package/packages/contracts/dist/identity.d.ts +54 -0
  144. package/packages/contracts/dist/identity.js +40 -0
  145. package/packages/contracts/dist/index.d.ts +20 -0
  146. package/packages/contracts/dist/index.js +20 -0
  147. package/packages/contracts/dist/invocation.d.ts +90 -0
  148. package/packages/contracts/dist/invocation.js +77 -0
  149. package/packages/contracts/dist/lifecycle.d.ts +130 -0
  150. package/packages/contracts/dist/lifecycle.js +135 -0
  151. package/packages/contracts/dist/plugin.d.ts +214 -0
  152. package/packages/contracts/dist/plugin.js +117 -0
  153. package/packages/contracts/dist/projectRead.d.ts +205 -0
  154. package/packages/contracts/dist/projectRead.js +162 -0
  155. package/packages/contracts/dist/secure.d.ts +128 -0
  156. package/packages/contracts/dist/secure.js +99 -0
  157. package/packages/contracts/package.json +32 -0
  158. package/packages/contracts/src/artifacts.ts +83 -0
  159. package/packages/contracts/src/automation.ts +238 -0
  160. package/packages/contracts/src/browser.ts +164 -0
  161. package/packages/contracts/src/context.ts +91 -0
  162. package/packages/contracts/src/diagnostics.ts +318 -0
  163. package/packages/contracts/src/effects.ts +49 -0
  164. package/packages/contracts/src/errors.ts +83 -0
  165. package/packages/contracts/src/events.ts +46 -0
  166. package/packages/contracts/src/executionDiagnostics.ts +116 -0
  167. package/packages/contracts/src/identity.ts +68 -0
  168. package/packages/contracts/src/index.ts +20 -0
  169. package/packages/contracts/src/invocation.ts +96 -0
  170. package/packages/contracts/src/lifecycle.ts +169 -0
  171. package/packages/contracts/src/plugin.ts +174 -0
  172. package/packages/contracts/src/projectRead.ts +179 -0
  173. package/packages/contracts/src/secure.ts +136 -0
  174. package/provenance.json +179 -9
  175. package/source.zip +0 -0
@@ -0,0 +1,99 @@
1
+ import { z } from 'zod';
2
+ import { SchemaVersionV1Schema, BrowserRequestIdSchema, ProjectIdSchema, PluginIdSchema, OperationIdSchema, IdempotencyKeySchema, RunIdSchema, } from './identity.js';
3
+ import { RunLifecycleStateSchema } from './lifecycle.js';
4
+ /**
5
+ * B02-A secure pairing and durable-intent contracts (additive; schema version 1).
6
+ * These are used only by the secure daemon mode, which authenticates with an
7
+ * Authorization header; the legacy LoopbackHttpRequestV1 body-token contract is unchanged.
8
+ */
9
+ export const PROMPT_MAX_UTF8_BYTES = 16384;
10
+ /** chrome-extension:// followed by exactly 32 letters in [a-p]; no path, query, userinfo or fragment. */
11
+ export const EXTENSION_ORIGIN_PATTERN = /^chrome-extension:\/\/[a-p]{32}$/;
12
+ export const ExtensionOriginSchema = z.string().regex(EXTENSION_ORIGIN_PATTERN);
13
+ export const PairCompleteRequestV1Schema = z.strictObject({
14
+ schemaVersion: SchemaVersionV1Schema,
15
+ challengeId: z.string().min(1).max(128),
16
+ code: z.string().min(1).max(128),
17
+ });
18
+ export const PairCompleteResponseV1Schema = z.strictObject({
19
+ schemaVersion: SchemaVersionV1Schema,
20
+ principalId: z.string().min(1),
21
+ bearerToken: z.string().min(1),
22
+ pairedOrigin: z.string().min(1),
23
+ expiresAt: z.string().datetime(),
24
+ });
25
+ const promptSchemaWithCap = (maxBytes) => z
26
+ .string()
27
+ .refine((s) => s.trim().length > 0, { message: 'prompt must not be whitespace-only' })
28
+ .refine((s) => {
29
+ const n = Buffer.byteLength(s, 'utf8');
30
+ return n >= 1 && n <= maxBytes;
31
+ }, { message: `prompt must be 1..${maxBytes} UTF-8 bytes` });
32
+ /**
33
+ * SW-053: the HTTP ceiling for an operation that declares the stdin_utf8 input transport (equals STDIN_MAX_BYTES_V1). The default
34
+ * ceiling above is unchanged; the route applies this larger one ONLY when trusted composition says the operation allows it.
35
+ */
36
+ export const PROMPT_MAX_UTF8_BYTES_STDIN_V1 = 32768;
37
+ const prepareIntentShape = (maxBytes) => ({
38
+ schemaVersion: SchemaVersionV1Schema,
39
+ requestId: BrowserRequestIdSchema,
40
+ projectId: ProjectIdSchema,
41
+ pluginId: PluginIdSchema,
42
+ operationId: OperationIdSchema,
43
+ idempotencyKey: IdempotencyKeySchema,
44
+ params: z.strictObject({ prompt: promptSchemaWithCap(maxBytes) }),
45
+ requestedAt: z.string().datetime(),
46
+ requiresUserApproval: z.literal(true),
47
+ });
48
+ export const PrepareIntentRequestV1Schema = z.strictObject(prepareIntentShape(PROMPT_MAX_UTF8_BYTES));
49
+ /** Same envelope with the larger stdin-operation prompt ceiling; the route still enforces the per-operation cap. */
50
+ export const PrepareIntentRequestStdinV1Schema = z.strictObject(prepareIntentShape(PROMPT_MAX_UTF8_BYTES_STDIN_V1));
51
+ export const PrepareIntentResponseV1Schema = z.strictObject({
52
+ schemaVersion: SchemaVersionV1Schema,
53
+ requestId: BrowserRequestIdSchema,
54
+ runId: RunIdSchema,
55
+ lifecycleState: z.literal('AWAITING_USER_APPROVAL'),
56
+ duplicate: z.boolean(),
57
+ createdAt: z.string().datetime(),
58
+ });
59
+ export const RunStatusResponseV1Schema = z.strictObject({
60
+ schemaVersion: SchemaVersionV1Schema,
61
+ runId: RunIdSchema,
62
+ lifecycleState: RunLifecycleStateSchema,
63
+ createdAt: z.string().datetime(),
64
+ updatedAt: z.string().datetime(),
65
+ });
66
+ /**
67
+ * B02-D: read-only status lookup by POST. Chromium sends no Origin header on a GET from an extension
68
+ * worker but does on a JSON POST, so POST /v1/runs/:runId/status carries the exact-Origin binding.
69
+ * The body is only the schema version; the run id is in the path. The response is RunStatusResponseV1.
70
+ */
71
+ export const RunStatusReadRequestV1Schema = z.strictObject({
72
+ schemaVersion: SchemaVersionV1Schema,
73
+ });
74
+ /** B02-B: one-time trusted-challenge approval (queues a run; never launches anything). */
75
+ export const ApproveRunRequestV1Schema = z.strictObject({
76
+ schemaVersion: SchemaVersionV1Schema,
77
+ approvalId: z.string().min(1).max(128),
78
+ approvalCode: z.string().min(1).max(128),
79
+ });
80
+ /** B02-B: cancellation of a pending or queued run. The reason is validated but never persisted or echoed. */
81
+ export const CancelPendingRunRequestV1Schema = z.strictObject({
82
+ schemaVersion: SchemaVersionV1Schema,
83
+ reason: z.string().trim().min(1).max(128),
84
+ });
85
+ export const RunDecisionResponseV1Schema = z.strictObject({
86
+ schemaVersion: SchemaVersionV1Schema,
87
+ runId: RunIdSchema,
88
+ lifecycleState: z.enum(['QUEUED', 'CANCELLED']),
89
+ updatedAt: z.string().datetime(),
90
+ duplicate: z.boolean(),
91
+ });
92
+ /** SW-053: cancel of a run that is already starting/running was accepted and persisted; the terminal state arrives via status. */
93
+ export const RunCancelAcceptedResponseV1Schema = z.strictObject({
94
+ schemaVersion: SchemaVersionV1Schema,
95
+ runId: RunIdSchema,
96
+ lifecycleState: z.literal('CANCEL_REQUESTED'),
97
+ updatedAt: z.string().datetime(),
98
+ });
99
+ //# sourceMappingURL=secure.js.map
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@my-centcom/contracts",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "description": "Shared cross-component contract authority and runtime schemas for my-centcom",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./diagnostics": {
15
+ "types": "./dist/diagnostics.d.ts",
16
+ "import": "./dist/diagnostics.js"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "build": "tsc --project tsconfig.json",
21
+ "typecheck": "tsc --noEmit --project tsconfig.json",
22
+ "pretest": "tsc --project tsconfig.json",
23
+ "test": "node --test tests/*.test.ts"
24
+ },
25
+ "dependencies": {
26
+ "zod": "4.6.7"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^22.13.1",
30
+ "typescript": "^5.7.3"
31
+ }
32
+ }
@@ -0,0 +1,83 @@
1
+ import { z } from 'zod';
2
+ import {
3
+ SchemaVersionV1Schema,
4
+ ArtifactIdSchema,
5
+ RunIdSchema,
6
+ ProjectIdSchema,
7
+ ShipmentIdSchema,
8
+ } from './identity.js';
9
+
10
+ export const EvidenceSourceSchema = z.enum([
11
+ 'run_output',
12
+ 'report_file',
13
+ 'git_diff',
14
+ 'telemetry',
15
+ 'test_receipt',
16
+ ]);
17
+ export type EvidenceSource = z.infer<typeof EvidenceSourceSchema>;
18
+
19
+ /**
20
+ * Durable Artifact Record.
21
+ * Invariant: Must strictly distinguish mutable source paths from immutable content snapshots.
22
+ */
23
+ export const ArtifactRecordV1Schema = z.object({
24
+ schemaVersion: SchemaVersionV1Schema,
25
+ artifactId: ArtifactIdSchema,
26
+ runId: RunIdSchema,
27
+ projectId: ProjectIdSchema,
28
+ mutableSourcePath: z.string().min(1),
29
+ immutableSnapshotSha256: z.string().regex(/^[a-f0-9]{64}$/i),
30
+ contentSnapshot: z.string(),
31
+ sizeBytes: z.number().int().nonnegative(),
32
+ evidenceSource: EvidenceSourceSchema,
33
+ snapshotObservedAt: z.string().datetime(),
34
+ mimeType: z.string().default('text/plain'),
35
+ });
36
+ export type ArtifactRecordV1 = z.infer<typeof ArtifactRecordV1Schema>;
37
+
38
+ /**
39
+ * Item within a shipment selection.
40
+ */
41
+ export const ShipmentItemV1Schema = z.object({
42
+ artifactId: ArtifactIdSchema,
43
+ sha256: z.string().regex(/^[a-f0-9]{64}$/i),
44
+ sourcePathAtSnapshot: z.string().min(1),
45
+ });
46
+ export type ShipmentItemV1 = z.infer<typeof ShipmentItemV1Schema>;
47
+
48
+ /**
49
+ * Shipment Selection Contract.
50
+ * Invariant: No artifact shipment may depend solely on a mutable pathname or an agent's unverified prose claim.
51
+ */
52
+ export const ShipmentSelectionV1Schema = z.object({
53
+ schemaVersion: SchemaVersionV1Schema,
54
+ shipmentId: ShipmentIdSchema,
55
+ runId: RunIdSchema,
56
+ selectedItems: z.array(ShipmentItemV1Schema).min(1),
57
+ markdownPresentation: z.string().min(1),
58
+ selectedAt: z.string().datetime(),
59
+ selectionApprovedByUser: z.boolean(),
60
+ });
61
+ export type ShipmentSelectionV1 = z.infer<typeof ShipmentSelectionV1Schema>;
62
+
63
+ /**
64
+ * Verification helper: Validates that every item in the shipment is backed by an
65
+ * immutable, hash-verified snapshot and not merely a mutable pathname.
66
+ */
67
+ export const verifyShipmentProvenance = (
68
+ selection: ShipmentSelectionV1,
69
+ availableArtifacts: Map<string, ArtifactRecordV1>
70
+ ): boolean => {
71
+ for (const item of selection.selectedItems) {
72
+ const artifact = availableArtifacts.get(item.artifactId);
73
+ if (!artifact) {
74
+ throw new Error(`Shipment error: Artifact ${item.artifactId} not found in durable store`);
75
+ }
76
+ if (artifact.immutableSnapshotSha256.toLowerCase() !== item.sha256.toLowerCase()) {
77
+ throw new Error(
78
+ `Shipment error: Artifact ${item.artifactId} SHA-256 digest mismatch. Snapshot is tampered or stale.`
79
+ );
80
+ }
81
+ }
82
+ return true;
83
+ };
@@ -0,0 +1,238 @@
1
+ import { z } from 'zod';
2
+ import { SchemaVersionV1Schema } from './identity.js';
3
+ import { RunLifecycleStateSchema } from './lifecycle.js';
4
+ import { ExecutionFailureViewSchema } from './executionDiagnostics.js';
5
+
6
+ /**
7
+ * SW-062 (integrated automation and recovery) contracts. Additive, schema version 1.
8
+ *
9
+ * K-native : extension service worker <-> per-user native messaging bootstrap host (C02 platform adapter). Tiny, length-bounded, two message types.
10
+ * K-boot : native host -> daemon, POST /v1/bootstrap/session. Requires NO Origin header (a browser page can never present it) and the installation secret.
11
+ * K-capture : worker -> daemon durable capture store / capture-run / workflow resume / long-poll wait / return receipts and explicit rebind.
12
+ *
13
+ * Nothing here carries an executable, path, argument or environment. A browser click can never choose an effect class or a consent mode.
14
+ */
15
+
16
+ /** Chrome native messaging host name (lowercase alphanumerics, dots and underscores only). */
17
+ export const NATIVE_HOST_NAME = 'com.my_centcom.bridge';
18
+ /** Hard ceiling of ONE inbound native message (the extension only ever sends a few dozen bytes). */
19
+ export const NATIVE_MAX_INBOUND_BYTES = 4096;
20
+ /** Hard ceiling of ONE outbound native message (well under Chrome's 1 MiB limit). */
21
+ export const NATIVE_MAX_OUTBOUND_BYTES = 8192;
22
+
23
+ const ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
24
+ const IdString = z.string().regex(ID);
25
+ const Sha256Hex = z.string().regex(/^[a-f0-9]{64}$/);
26
+ const Iso = z.string().datetime();
27
+
28
+ export const NativeRequestV1Schema = z.discriminatedUnion('type', [
29
+ z.strictObject({ v: z.literal(1), type: z.literal('PING') }),
30
+ z.strictObject({ v: z.literal(1), type: z.literal('CONNECT') }),
31
+ ]);
32
+ export type NativeRequestV1 = z.infer<typeof NativeRequestV1Schema>;
33
+
34
+ /** Fixed host refusal vocabulary (the host never forwards free text). */
35
+ export const NATIVE_HOST_ERROR_CODES = [
36
+ 'HOST_MESSAGE_INVALID', 'HOST_MESSAGE_TOO_LARGE', 'HOST_ORIGIN_MISMATCH', 'HOST_NOT_INSTALLED', 'HOST_CONFIG_INVALID', 'HOST_CONFIG_TAMPERED',
37
+ 'INSTALL_INTEGRITY_FAILED', 'UPDATE_REQUIRES_RECONSENT', 'INSTALLATION_REVOKED', 'DAEMON_START_FAILED', 'DAEMON_NOT_RESPONDING', 'SESSION_REFUSED', 'HOST_INTERNAL_ERROR',
38
+ ] as const;
39
+ export type NativeHostErrorCode = (typeof NATIVE_HOST_ERROR_CODES)[number];
40
+
41
+ export const NativeResponseV1Schema = z.union([
42
+ z.strictObject({ v: z.literal(1), ok: z.literal(true), type: z.literal('PONG'), installed: z.boolean(), hostVersion: z.string().max(32) }),
43
+ z.strictObject({
44
+ v: z.literal(1), ok: z.literal(true), type: z.literal('CONNECTED'),
45
+ port: z.number().int().min(1).max(65535), bearerToken: z.string().regex(/^[A-Za-z0-9_-]{16,512}$/), expiresAt: Iso, installationId: IdString, daemonStarted: z.boolean(),
46
+ }),
47
+ z.strictObject({ v: z.literal(1), ok: z.literal(false), code: z.enum(NATIVE_HOST_ERROR_CODES) }),
48
+ ]);
49
+ export type NativeResponseV1 = z.infer<typeof NativeResponseV1Schema>;
50
+
51
+ /** Coding effects name a stored proposal and its exact reviewed identity; executable and command arguments are never accepted. */
52
+ export const CodingReadRequestV1Schema = z.strictObject({ schemaVersion: z.literal(1) });
53
+ export const CodingActionRequestV1Schema = z.strictObject({ schemaVersion: z.literal(1), proposalId: z.string().regex(/^prop\.[A-Za-z0-9_-]{16,64}$/), digest: z.string().regex(/^[a-f0-9]{64}$/), action: z.enum(['apply', 'reject', 'test', 'git', 'commit', 'finalize', 'proposal']) });
54
+ export type CodingActionRequestV1 = z.infer<typeof CodingActionRequestV1Schema>;
55
+ /** Distinct immutable coding deliveries; proposal-only never implies TEST. */
56
+ export const CodingResultKindV1Schema = z.enum(['VERIFIED_CODING_RESULT', 'PROPOSAL_ONLY_UNVERIFIED', 'APPLIED_UNTESTED_RESULT', 'COMMITTED_UNTESTED_RESULT']);
57
+ export const ReviewedCommitRequestSchema = z.strictObject({schemaVersion:z.literal(1),proposalId:z.string().regex(/^prop\.[A-Za-z0-9_-]{16,64}$/),message:z.string().trim().min(1).max(1000),challenge:Sha256Hex});
58
+ export type CodingResultKindV1 = z.infer<typeof CodingResultKindV1Schema>;
59
+ /** Separate non-model transaction. Both displayed authorities must be approved. */
60
+ export const ReviewedPatchRequestV1Schema = z.strictObject({ schemaVersion: z.literal(1), proposalId: z.string().regex(/^prop\.[A-Za-z0-9_-]{16,64}$/),
61
+ projectId: IdString, digest: Sha256Hex, baseHead: z.string().regex(/^[a-f0-9]{40,64}$/), challenge: Sha256Hex, action: z.enum(['apply', 'cancel']) });
62
+ export const ModelExecutionModeSchema = z.enum(['STRICT_ISOLATED', 'TRUSTED_LOCAL_CLI_PROPOSAL_ONLY']);
63
+ export type ModelExecutionMode = z.infer<typeof ModelExecutionModeSchema>;
64
+ export const TRUSTED_CLI_WARNING = 'Trusted proposal-only CLI: Codex is a trusted local program. It can have your normal OS-level file and network access. The current shared restricted token does not isolate sibling credentials or other agent storage. MCP tool limits are product controls, not OS confidentiality. Only inspection and proposals are authorized; tests, application and commits are not.';
65
+ export const TRUSTED_CLI_WARNING_VERSION = 'trusted-cli-proposal-v1';
66
+ export const TrustedCliConsentRequestSchema = z.strictObject({ schemaVersion: z.literal(1), projectId: IdString, pluginId: IdString, operationId: IdString,
67
+ action: z.enum(['status', 'accept', 'revoke']), challenge: Sha256Hex.optional(), warningVersion: z.literal(TRUSTED_CLI_WARNING_VERSION).optional() });
68
+
69
+ // ---- K-boot ------------------------------------------------------------------------------------------------------------------------------
70
+
71
+ export const BootstrapSessionRequestV1Schema = z.strictObject({
72
+ schemaVersion: SchemaVersionV1Schema,
73
+ installationId: IdString,
74
+ secret: z.string().regex(/^[A-Za-z0-9_-]{32,128}$/),
75
+ extensionOrigin: z.string().regex(/^chrome-extension:\/\/[a-p]{32}$/),
76
+ });
77
+ export type BootstrapSessionRequestV1 = z.infer<typeof BootstrapSessionRequestV1Schema>;
78
+
79
+ export const BootstrapSessionResponseV1Schema = z.strictObject({
80
+ schemaVersion: SchemaVersionV1Schema,
81
+ installationId: IdString,
82
+ bearerToken: z.string().min(16).max(512),
83
+ expiresAt: Iso,
84
+ });
85
+ export type BootstrapSessionResponseV1 = z.infer<typeof BootstrapSessionResponseV1Schema>;
86
+
87
+ /** Daemon instance identity, published only into the private data root (never over a browser-reachable route). */
88
+ export interface DaemonRuntimeRecordV1 { schemaVersion: 1; port: number; pid: number; instanceId: string; startedAt: string }
89
+
90
+ // ---- K-capture ---------------------------------------------------------------------------------------------------------------------------
91
+
92
+ export const CAPTURE_MAX_UTF8_BYTES = 32768;
93
+ export const CAPTURE_TTL_MS = 30 * 60_000;
94
+
95
+ /** What the worker learned about the page at the user's gesture. Identity fields are opaque browser values; nothing here is page HTML. */
96
+ export const TabBindingV1Schema = z.strictObject({
97
+ tabId: z.number().int().min(0).max(0x7fffffff),
98
+ windowId: z.number().int().min(-1).max(0x7fffffff),
99
+ frameId: z.literal(0),
100
+ documentId: z.string().regex(/^[A-Za-z0-9_-]{1,128}$/),
101
+ nonce: z.string().regex(/^[A-Za-z0-9-]{1,64}$/),
102
+ sourceUrl: z.string().url().max(2048).refine((u) => u.startsWith('https://') || u.startsWith('http://127.0.0.1:'), 'source must be https (or the loopback test origin)'),
103
+ });
104
+ export type TabBindingV1 = z.infer<typeof TabBindingV1Schema>;
105
+
106
+ /**
107
+ * What the captured bytes ARE (SW-065). Neither value is verified to be an assistant message; the user's explicit action is the only attestation.
108
+ * CAPTURED_RENDERED_TEXT the rendered text of the user's DOM selection on the page (formatting such as code fences may be missing);
109
+ * PASTED_PLAIN_TEXT the text/plain flavor of what the USER pasted into the side panel (Ctrl+V), line breaks normalized to LF and nothing else
110
+ * changed. Text copied with ChatGPT's own Copy button is normally the message's Markdown source, but that is not verified.
111
+ */
112
+ export const CAPTURE_FIDELITIES = ['CAPTURED_RENDERED_TEXT', 'PASTED_PLAIN_TEXT', 'EDITED_TASK_TEXT'] as const;
113
+ export const CaptureFidelitySchema = z.enum(CAPTURE_FIDELITIES);
114
+ export type CaptureFidelity = z.infer<typeof CaptureFidelitySchema>;
115
+
116
+ export const CaptureStoreRequestV1Schema = z.strictObject({
117
+ editOf: z.string().regex(/^cap\.[a-f0-9]{32}$/).optional(),
118
+ schemaVersion: SchemaVersionV1Schema,
119
+ text: z.string().min(1),
120
+ sha256: Sha256Hex,
121
+ bytes: z.number().int().min(1).max(CAPTURE_MAX_UTF8_BYTES),
122
+ fidelity: CaptureFidelitySchema,
123
+ /**
124
+ * SW-066: how many CRLF/CR line breaks the producer turned into LF before sending (the one deliberate, disclosed text change on the pasted path; always 0 for a
125
+ * rendered selection). Absent = 0. It is the producer's own count: the daemon cannot recover the original bytes and does not claim to have verified it.
126
+ */
127
+ lineEndingsNormalized: z.number().int().min(0).max(CAPTURE_MAX_UTF8_BYTES).optional(),
128
+ binding: TabBindingV1Schema,
129
+ });
130
+ export type CaptureStoreRequestV1 = z.infer<typeof CaptureStoreRequestV1Schema>;
131
+
132
+ export const CaptureStoreResponseV1Schema = z.strictObject({
133
+ schemaVersion: SchemaVersionV1Schema,
134
+ captureId: z.string().regex(/^cap\.[a-f0-9]{32}$/),
135
+ sha256: Sha256Hex,
136
+ bytes: z.number().int(),
137
+ createdAt: Iso,
138
+ expiresAt: Iso,
139
+ duplicate: z.boolean(),
140
+ });
141
+
142
+ export const CaptureRunRequestV1Schema = z.strictObject({
143
+ schemaVersion: SchemaVersionV1Schema,
144
+ projectId: IdString,
145
+ pluginId: IdString,
146
+ operationId: IdString,
147
+ });
148
+ export type CaptureRunRequestV1 = z.infer<typeof CaptureRunRequestV1Schema>;
149
+ export const CodingCaptureRunRequestV1Schema = CaptureRunRequestV1Schema.extend({ executionMode: ModelExecutionModeSchema.optional() });
150
+
151
+ /** RUN_CLICK: a trusted local grant made the user's own Run click the per-run consent (read-only, verified operations only). */
152
+ export const ConsentModeSchema = z.enum(['RUN_CLICK', 'LOCAL_CONFIRM']);
153
+ export type ConsentMode = z.infer<typeof ConsentModeSchema>;
154
+
155
+ export const CaptureRunResponseV1Schema = z.strictObject({
156
+ schemaVersion: SchemaVersionV1Schema,
157
+ runId: z.string().regex(/^run\.[a-f0-9]{32}$/),
158
+ lifecycleState: RunLifecycleStateSchema,
159
+ duplicate: z.boolean(),
160
+ consent: ConsentModeSchema,
161
+ effectClass: z.enum(['read', 'write_project', 'external_network', 'destructive']),
162
+ });
163
+
164
+ export const RunWaitRequestV1Schema = z.strictObject({
165
+ schemaVersion: SchemaVersionV1Schema,
166
+ sinceUpdatedAt: Iso.nullable(),
167
+ timeoutMs: z.number().int().min(0).max(25_000),
168
+ });
169
+
170
+ export const RETURN_STATES = ['RETURN_READY', 'INSERTED_UNSENT', 'RETURN_STALE', 'INSERT_FAILED'] as const;
171
+ export const ReturnStateSchema = z.enum(RETURN_STATES);
172
+ export type ReturnState = z.infer<typeof ReturnStateSchema>;
173
+
174
+ export const ReturnReceiptRequestV1Schema = z.strictObject({
175
+ schemaVersion: SchemaVersionV1Schema,
176
+ state: z.enum(['INSERTED_UNSENT', 'RETURN_STALE', 'INSERT_FAILED']),
177
+ code: z.string().regex(/^[A-Z][A-Z0-9_]{1,40}$/).optional(),
178
+ editor: z.enum(['TEXTAREA', 'CONTENTEDITABLE', 'PROSEMIRROR']).optional(),
179
+ sha256: Sha256Hex,
180
+ });
181
+ export const ReturnRebindRequestV1Schema = z.strictObject({ schemaVersion: SchemaVersionV1Schema, sha256: Sha256Hex, binding: TabBindingV1Schema });
182
+
183
+ export const WorkflowPreferenceRequestV1Schema = z.strictObject({ schemaVersion: SchemaVersionV1Schema, projectId: IdString, pluginId: IdString, operationId: IdString });
184
+ export const WorkflowDismissRequestV1Schema = z.strictObject({ schemaVersion: SchemaVersionV1Schema, captureId: z.string().regex(/^cap\.[a-f0-9]{32}$/) });
185
+ export const WorkflowReadRequestV1Schema = z.strictObject({ schemaVersion: SchemaVersionV1Schema,
186
+ watchOnly: z.literal(true).optional(), sinceRevision: Sha256Hex.optional(), timeoutMs: z.number().int().min(0).max(25_000).optional(),
187
+ });
188
+ /** Conditional notification on the existing authenticated workflow channel; no prompt/result duplication on a quiet connection. */
189
+ export const WorkflowWatchResponseSchema = z.strictObject({schemaVersion:z.literal(1), revision:Sha256Hex, changed:z.boolean(), observedAt:Iso, daemonVersion:z.string().max(40)});
190
+
191
+ const OperationOptionSchema = z.strictObject({
192
+ projectLabel: z.string().max(120).optional(), agentLabel: z.string().max(120).optional(), coding: z.boolean().optional(), strictReady: z.boolean().optional(),
193
+ projectId: IdString, pluginId: IdString, operationId: IdString,
194
+ effectClass: z.enum(['read', 'write_project', 'external_network', 'destructive']),
195
+ consent: ConsentModeSchema,
196
+ expiresAt: Iso,
197
+ });
198
+ export type OperationOptionV1 = z.infer<typeof OperationOptionSchema>;
199
+
200
+ export const WorkflowCurrentResponseV1Schema = z.strictObject({
201
+ revision: Sha256Hex.optional(), daemonVersion:z.string().max(40).optional(), observedAt:Iso.optional(),
202
+ schemaVersion: SchemaVersionV1Schema,
203
+ operations: z.array(OperationOptionSchema).max(32),
204
+ preferred: z.strictObject({ projectId: IdString, pluginId: IdString, operationId: IdString }).nullable(),
205
+ capture: z.strictObject({
206
+ captureId: z.string(), text: z.string(), sha256: Sha256Hex, bytes: z.number().int(), createdAt: Iso, expiresAt: Iso,
207
+ state: z.enum(['CAPTURED', 'DISPATCHED', 'EXPIRED']), binding: TabBindingV1Schema, fidelity: CaptureFidelitySchema,
208
+ lineEndingsNormalized: z.number().int().min(0).default(0),
209
+ }).nullable(),
210
+ run: z.strictObject({ runId: z.string(), lifecycleState: RunLifecycleStateSchema, updatedAt: Iso, consent: ConsentModeSchema, failure: ExecutionFailureViewSchema.nullable().optional() }).nullable(),
211
+ ret: z.strictObject({
212
+ returnId: z.string(), sha256: Sha256Hex, bytes: z.number().int(), text: z.string(), state: ReturnStateSchema, code: z.string().nullable(), binding: TabBindingV1Schema, rebinds: z.number().int(),
213
+ }).nullable(),
214
+ });
215
+ export type WorkflowCurrentResponseV1 = z.infer<typeof WorkflowCurrentResponseV1Schema>;
216
+
217
+ /** Workflow phases shown by the panel (C11). Derived, never stored. */
218
+ export const WORKFLOW_PHASES = [
219
+ 'CONNECTING', 'REPAIR', 'NO_CAPTURE', 'CAPTURED', 'AWAITING_RISK_APPROVAL', 'QUEUED', 'RUNNING', 'COMPLETED', 'FAILED', 'UNKNOWN', 'CANCELLED',
220
+ 'RETURN_READY', 'INSERTED_UNSENT', 'RETURN_STALE', 'INSERT_FAILED',
221
+ ] as const;
222
+ export type WorkflowPhase = (typeof WORKFLOW_PHASES)[number];
223
+
224
+ /** SW-097: projections of existing C09 rows, never a second event store. */
225
+ export const ActivityRequestSchema = z.strictObject({ schemaVersion: z.literal(1),
226
+ cursor: z.string().max(100).regex(/^\d+:\d+:\d+$/), timeoutMs: z.number().int().min(0).max(8000),
227
+ });
228
+ export const ActivityEventSchema = z.strictObject({
229
+ id: z.string().regex(/^(?:[LEC]:[1-9][0-9]{0,14}|D:[a-f0-9]{16})$/), ts: Iso, component: z.enum(['C02', 'C05', 'C06', 'C07']),
230
+ severity: z.enum(['INFO', 'WARN', 'ERROR']), status: z.enum(['OBSERVED', 'RECONSTRUCTED', 'STALE', 'UNKNOWN']),
231
+ kind: z.string().max(64), summary: z.string().max(240), runId: IdString,
232
+ });
233
+ export const ActivityResponseSchema = z.strictObject({ schemaVersion: z.literal(1), runId: IdString,
234
+ cursor: z.string().max(100), collectedAt: Iso, daemonVersion: z.string().max(40),
235
+ phase: z.string().max(64), startedAt: Iso, truncated: z.boolean(),
236
+ events: z.array(ActivityEventSchema).max(80),
237
+ });
238
+ export type ActivityResponse = z.infer<typeof ActivityResponseSchema>;
@@ -0,0 +1,164 @@
1
+ import { z } from 'zod';
2
+ import {
3
+ SchemaVersionV1Schema,
4
+ BrowserRequestIdSchema,
5
+ ProjectIdSchema,
6
+ PluginIdSchema,
7
+ OperationIdSchema,
8
+ IdempotencyKeySchema,
9
+ RunIdSchema,
10
+ ShipmentIdSchema,
11
+ ArtifactIdSchema,
12
+ } from './identity.js';
13
+ import { ContractErrorV1Schema } from './errors.js';
14
+
15
+ export const BrowserActionTypeSchema = z.enum([
16
+ 'DISPATCH_PROMPT',
17
+ 'QUERY_STATUS',
18
+ 'GET_CONTEXT',
19
+ 'CANCEL_RUN',
20
+ 'INJECT_RETURN_CARGO',
21
+ ]);
22
+ export type BrowserActionType = z.infer<typeof BrowserActionTypeSchema>;
23
+
24
+ /**
25
+ * Transport contract: Page -> Content Script -> Service Worker.
26
+ */
27
+ export const BrowserRequestV1Schema = z.object({
28
+ schemaVersion: SchemaVersionV1Schema,
29
+ requestId: BrowserRequestIdSchema,
30
+ action: BrowserActionTypeSchema,
31
+ projectId: ProjectIdSchema,
32
+ pluginId: PluginIdSchema.optional(),
33
+ operationId: OperationIdSchema.optional(),
34
+ payload: z.record(z.string(), z.unknown()),
35
+ conversationId: z.string().min(1),
36
+ timestamp: z.string().datetime(),
37
+ });
38
+ export type BrowserRequestV1 = z.infer<typeof BrowserRequestV1Schema>;
39
+
40
+ /**
41
+ * Transport contract: Response back to extension content script and page.
42
+ */
43
+ export const BrowserResponseV1Schema = z.object({
44
+ schemaVersion: SchemaVersionV1Schema,
45
+ requestId: BrowserRequestIdSchema,
46
+ status: z.enum(['OK', 'ERROR']),
47
+ data: z.record(z.string(), z.unknown()).optional(),
48
+ error: ContractErrorV1Schema.optional(),
49
+ timestamp: z.string().datetime(),
50
+ });
51
+ export type BrowserResponseV1 = z.infer<typeof BrowserResponseV1Schema>;
52
+
53
+ /**
54
+ * Transport contract: Service Worker -> Authenticated Loopback HTTP.
55
+ */
56
+ export const LoopbackHttpRequestV1Schema = z.object({
57
+ schemaVersion: SchemaVersionV1Schema,
58
+ requestId: BrowserRequestIdSchema,
59
+ authToken: z.string().min(1),
60
+ action: BrowserActionTypeSchema,
61
+ projectId: ProjectIdSchema,
62
+ pluginId: PluginIdSchema.optional(),
63
+ operationId: OperationIdSchema.optional(),
64
+ payload: z.record(z.string(), z.unknown()),
65
+ idempotencyKey: IdempotencyKeySchema.optional(),
66
+ });
67
+ export type LoopbackHttpRequestV1 = z.infer<typeof LoopbackHttpRequestV1Schema>;
68
+
69
+ /**
70
+ * Transport contract: Loopback HTTP Response from Daemon.
71
+ */
72
+ export const LoopbackHttpResponseV1Schema = z.object({
73
+ schemaVersion: SchemaVersionV1Schema,
74
+ requestId: BrowserRequestIdSchema,
75
+ statusCode: z.number().int().min(200).max(599),
76
+ data: z.record(z.string(), z.unknown()).optional(),
77
+ error: ContractErrorV1Schema.optional(),
78
+ });
79
+ export type LoopbackHttpResponseV1 = z.infer<typeof LoopbackHttpResponseV1Schema>;
80
+
81
+ /**
82
+ * User-approved return cargo targeted for ChatGPT Web composer insertion.
83
+ * Invariant: Browser sandbox security blocks programmatic file attachments;
84
+ * return cargo must be formatted as non-submitting markdown text snippets.
85
+ */
86
+ export const ReturnCargoV1Schema = z.object({
87
+ schemaVersion: SchemaVersionV1Schema,
88
+ shipmentId: ShipmentIdSchema,
89
+ runId: RunIdSchema,
90
+ conversationId: z.string().min(1),
91
+ userApproved: z.boolean(),
92
+ markdownSnippet: z.string().min(1),
93
+ selectedArtifactIds: z.array(ArtifactIdSchema),
94
+ generatedAt: z.string().datetime(),
95
+ });
96
+ export type ReturnCargoV1 = z.infer<typeof ReturnCargoV1Schema>;
97
+
98
+ /**
99
+ * Transport contract: Optional ChatGPT MCP Tool Invocation (K04).
100
+ * Governs conditional remote MCP transport to daemon gateway (C10).
101
+ * Invariant: Model-initiated execution remains unverified on local workstation (M12).
102
+ */
103
+ export const McpToolInvocationRequestV1Schema = z.object({
104
+ schemaVersion: SchemaVersionV1Schema,
105
+ requestId: z.string().min(1),
106
+ mcpPrincipalId: z.string().min(1),
107
+ toolName: z.string().min(1),
108
+ arguments: z.record(z.string(), z.unknown()),
109
+ requestedAt: z.string().datetime(),
110
+ });
111
+ export type McpToolInvocationRequestV1 = z.infer<typeof McpToolInvocationRequestV1Schema>;
112
+
113
+ export const McpToolInvocationResponseV1Schema = z.object({
114
+ schemaVersion: SchemaVersionV1Schema,
115
+ requestId: z.string().min(1),
116
+ status: z.enum(['SUCCESS', 'ERROR', 'UNSUPPORTED']),
117
+ result: z.record(z.string(), z.unknown()).optional(),
118
+ error: ContractErrorV1Schema.optional(),
119
+ timestamp: z.string().datetime(),
120
+ });
121
+ export type McpToolInvocationResponseV1 = z.infer<typeof McpToolInvocationResponseV1Schema>;
122
+
123
+ /**
124
+ * Transport contract: ChatGPT Composer Insertion Boundary (K12).
125
+ * Governs presentation of approved cargo into the ChatGPT Web composer DOM or clipboard.
126
+ * Invariant: Web sandbox prevents synthetic file drops; actual DOM auto-fill remains unverified (M10).
127
+ */
128
+ export const ComposerInsertionV1Schema = z.object({
129
+ schemaVersion: SchemaVersionV1Schema,
130
+ cargo: ReturnCargoV1Schema,
131
+ insertionMode: z.enum(['DOM_TEXTAREA', 'CLIPBOARD_FALLBACK']),
132
+ status: z.enum(['PENDING_USER_APPROVAL', 'INSERTED', 'COPIED_TO_CLIPBOARD', 'FAILED']),
133
+ timestamp: z.string().datetime(),
134
+ });
135
+ export type ComposerInsertionV1 = z.infer<typeof ComposerInsertionV1Schema>;
136
+
137
+ /**
138
+ * SW-058 (B05): immutable final-text return snapshot over the secure daemon. Additive; schema version 1. The text is the agent's REPORTED final
139
+ * message of one completed run, stored once (digest-bound, byte-capped) and handed back to the paired requester only. It is untrusted prose:
140
+ * provenance is RUN_FINAL_MESSAGE_AGENT_REPORTED, never verified output or source Markdown. The cap counts UTF-8 BYTES.
141
+ */
142
+ export const RETURN_TEXT_MAX_UTF8_BYTES = 16384;
143
+
144
+ export const PrepareReturnRequestV1Schema = z.strictObject({
145
+ schemaVersion: SchemaVersionV1Schema,
146
+ });
147
+ export type PrepareReturnRequestV1 = z.infer<typeof PrepareReturnRequestV1Schema>;
148
+
149
+ const utf8Length = (s: string): number => new TextEncoder().encode(s).length;
150
+
151
+ export const ReturnSnapshotResponseV1Schema = z
152
+ .strictObject({
153
+ schemaVersion: SchemaVersionV1Schema,
154
+ returnId: z.string().regex(/^ret\.[a-f0-9]{32}$/),
155
+ runId: RunIdSchema,
156
+ text: z.string().min(1),
157
+ sha256: z.string().regex(/^[a-f0-9]{64}$/),
158
+ bytes: z.number().int().min(1).max(RETURN_TEXT_MAX_UTF8_BYTES),
159
+ provenance: z.literal('RUN_FINAL_MESSAGE_AGENT_REPORTED'),
160
+ createdAt: z.string().datetime(),
161
+ duplicate: z.boolean(),
162
+ })
163
+ .refine((v) => utf8Length(v.text) === v.bytes, { message: 'bytes must equal the UTF-8 length of text' });
164
+ export type ReturnSnapshotResponseV1 = z.infer<typeof ReturnSnapshotResponseV1Schema>;