@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,116 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * SW-068 execution observability contract (shared by C05 coordinator, C06 process host + provider adapters, C09 storage and the presentation layers).
5
+ *
6
+ * Failure taxonomy: ONE generic vocabulary for every external CLI (Codex today; Claude and custom drivers later). A classification always says HOW the category
7
+ * was reached, because "a known exit code" is not "a known reason":
8
+ * OBSERVED_ERROR_TEXT a structured CLI event, stderr or host fact states the problem (the matched evidence is referenced by sequence number);
9
+ * OBSERVED_HOST_FACT the process host/supervisor itself observed it (timeout, cancel, spawn failure, stdin not delivered, tree not confirmed);
10
+ * INFERRED a cause is suggested by circumstances only (never presented as proven);
11
+ * NOT_DETERMINED the failure is real but its cause is not known (for example: exit code 1 and nothing explanatory was emitted).
12
+ */
13
+ export const EXECUTION_FAILURE_CATEGORIES = [
14
+ 'EXECUTABLE_INVALID',
15
+ 'AUTHENTICATION_FAILURE',
16
+ 'AUTHORIZATION_FAILURE',
17
+ 'NETWORK_OR_TLS_FAILURE',
18
+ 'PROVIDER_REJECTION',
19
+ 'RATE_OR_USAGE_LIMIT',
20
+ 'SANDBOX_FAILURE',
21
+ 'PROCESS_START_FAILURE',
22
+ 'PROCESS_EXIT_FAILURE',
23
+ 'TIMEOUT',
24
+ 'CANCELLED',
25
+ 'EVENT_PROTOCOL_ERROR',
26
+ 'UNKNOWN_OUTCOME',
27
+ 'UNCLASSIFIED_FAILURE',
28
+ ] as const;
29
+ export const ExecutionFailureCategorySchema = z.enum(EXECUTION_FAILURE_CATEGORIES);
30
+ export type ExecutionFailureCategory = z.infer<typeof ExecutionFailureCategorySchema>;
31
+
32
+ export const CLASSIFICATION_BASES = ['OBSERVED_ERROR_TEXT', 'OBSERVED_HOST_FACT', 'INFERRED', 'NOT_DETERMINED'] as const;
33
+ export const ClassificationBasisSchema = z.enum(CLASSIFICATION_BASES);
34
+ export type ClassificationBasis = z.infer<typeof ClassificationBasisSchema>;
35
+
36
+ export const ExecutionClassificationSchema = z.strictObject({
37
+ /** null = the execution did not fail (no category applies). */
38
+ category: ExecutionFailureCategorySchema.nullable(),
39
+ basis: ClassificationBasisSchema,
40
+ /** True only when an observed message or host fact names the cause. A bare exit code never makes this true. */
41
+ causeDetermined: z.boolean(),
42
+ /** Stable rule id that matched (for example "text:tls-certificate") or the host fact ("host:timeout"). */
43
+ rule: z.string().regex(/^[A-Za-z0-9:_.-]{1,64}$/),
44
+ /** Sequence numbers of the evidence events that support the classification (bounded). */
45
+ evidenceSeq: z.array(z.number().int().min(1)).max(8),
46
+ /** The last stage confirmed to have succeeded before the failure. */
47
+ lastConfirmedStage: z.string().regex(/^[A-Z][A-Z0-9_]{1,40}$/),
48
+ /** Provider-specific, already redacted, bounded detail (never a generic field: the category is the contract). */
49
+ providerDetail: z.string().max(300).nullable(),
50
+ });
51
+ export type ExecutionClassification = z.infer<typeof ExecutionClassificationSchema>;
52
+
53
+ /** What the application shows about a failed execution, directly: the category and the correlation id under which the evidence is stored. */
54
+ export const ExecutionFailureViewSchema = z.strictObject({
55
+ category: ExecutionFailureCategorySchema,
56
+ basis: ClassificationBasisSchema,
57
+ causeDetermined: z.boolean(),
58
+ correlationId: z.string().regex(/^corr\.[A-Za-z0-9_-]{8,40}$/),
59
+ });
60
+ export type ExecutionFailureView = z.infer<typeof ExecutionFailureViewSchema>;
61
+
62
+ export const EVIDENCE_EVENT_KINDS = ['LIFECYCLE', 'STDOUT', 'STDERR', 'PARSER', 'NOTE'] as const;
63
+ export type EvidenceEventKind = (typeof EVIDENCE_EVENT_KINDS)[number];
64
+
65
+ /** Hard bounds of the evidence store (per run). Output beyond them is COUNTED, never silently dropped, and the truncation is itself evidence. */
66
+ export const EVIDENCE_LIMITS = Object.freeze({
67
+ maxEventsPerRun: 400,
68
+ maxLineChars: 600,
69
+ maxStreamCharsPerRun: 32_768,
70
+ maxConfigJsonChars: 4096,
71
+ /** Retention: evidence older than this is deleted by the daemon at start. */
72
+ retentionDays: 30,
73
+ });
74
+
75
+ /** The shareable (redacted) export of one execution's evidence. */
76
+ export const ExecutionEvidenceExportSchema = z.strictObject({
77
+ schemaVersion: z.literal(1),
78
+ correlationId: z.string(),
79
+ runId: z.string(),
80
+ exportedAt: z.string(),
81
+ driver: z.string(),
82
+ outputProfile: z.string().nullable(),
83
+ operationId: z.string(),
84
+ executableSha256: z.string(),
85
+ launch: z.record(z.string(), z.unknown()),
86
+ lifecycleState: z.string(),
87
+ lastStage: z.string(),
88
+ classification: ExecutionClassificationSchema.nullable(),
89
+ classificationComputedAt: z.enum(['FINALIZATION', 'EXPORT']),
90
+ events: z.array(z.strictObject({ seq: z.number(), ts: z.string(), kind: z.string(), stage: z.string().nullable(), data: z.string(), truncated: z.boolean() })).max(EVIDENCE_LIMITS.maxEventsPerRun),
91
+ notes: z.array(z.string()).max(20),
92
+ });
93
+ export type ExecutionEvidenceExport = z.infer<typeof ExecutionEvidenceExportSchema>;
94
+
95
+ /**
96
+ * SW-071 TASK VERDICT: four SEPARATE dimensions that must never be collapsed into one "success". An exit code of 0 proves only that the process ended; it does not prove the model
97
+ * finished the task, that a tool request was permitted, or that the answer is right. `repositoryInspection` is PROVEN only when a tool call that read the repository actually
98
+ * completed AND the independently computed answer matches; a refused tool call can never be reported as an inspection, whatever the answer says.
99
+ */
100
+ export const TASK_VERDICT_PROCESS = ['SUCCEEDED', 'FAILED', 'NOT_OBSERVED'] as const;
101
+ export const TASK_VERDICT_MODEL = ['COMPLETED', 'NO_FINAL_MESSAGE', 'NOT_OBSERVED'] as const;
102
+ export const TASK_VERDICT_TOOL = ['NOT_REQUESTED', 'SUCCEEDED', 'PARTIAL', 'REFUSED', 'FAILED', 'NOT_OBSERVED'] as const;
103
+ export const TASK_VERDICT_ANSWER = ['CORRECT', 'INCORRECT', 'NOT_CHECKED'] as const;
104
+ export const TASK_VERDICT_INSPECTION = ['PROVEN', 'REFUSED', 'NOT_PROVEN'] as const;
105
+
106
+ export const TaskVerdictSchema = z.strictObject({
107
+ process: z.enum(TASK_VERDICT_PROCESS),
108
+ model: z.enum(TASK_VERDICT_MODEL),
109
+ tool: z.enum(TASK_VERDICT_TOOL),
110
+ answer: z.enum(TASK_VERDICT_ANSWER),
111
+ repositoryInspection: z.enum(TASK_VERDICT_INSPECTION),
112
+ toolCounts: z.strictObject({ requested: z.number().int().min(0), completed: z.number().int().min(0), refused: z.number().int().min(0), failed: z.number().int().min(0) }),
113
+ /** Evidence sequence numbers behind the tool dimension (bounded). */
114
+ toolEvidenceSeq: z.array(z.number().int().min(1)).max(8),
115
+ });
116
+ export type TaskVerdict = z.infer<typeof TaskVerdictSchema>;
@@ -0,0 +1,68 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Explicit schema version 1 for initial transport and persisted payload contracts.
5
+ */
6
+ export const SCHEMA_VERSION_V1 = 1 as const;
7
+ export const SchemaVersionV1Schema = z.literal(SCHEMA_VERSION_V1);
8
+ export type SchemaVersionV1 = z.infer<typeof SchemaVersionV1Schema>;
9
+
10
+ /**
11
+ * Distinct identity schemas and branded types.
12
+ * Invariant: Never reuse one identity type to represent another.
13
+ */
14
+ export const ProjectIdSchema = z.string().min(1).brand<'ProjectId'>();
15
+ export type ProjectId = z.infer<typeof ProjectIdSchema>;
16
+
17
+ export const PluginIdSchema = z.string().min(1).brand<'PluginId'>();
18
+ export type PluginId = z.infer<typeof PluginIdSchema>;
19
+
20
+ export const OperationIdSchema = z.string().min(1).brand<'OperationId'>();
21
+ export type OperationId = z.infer<typeof OperationIdSchema>;
22
+
23
+ export const AuthorizationGrantIdSchema = z.string().min(1).brand<'AuthorizationGrantId'>();
24
+ export type AuthorizationGrantId = z.infer<typeof AuthorizationGrantIdSchema>;
25
+
26
+ export const BrowserRequestIdSchema = z.string().min(1).brand<'BrowserRequestId'>();
27
+ export type BrowserRequestId = z.infer<typeof BrowserRequestIdSchema>;
28
+
29
+ export const IdempotencyKeySchema = z.string().min(1).brand<'IdempotencyKey'>();
30
+ export type IdempotencyKey = z.infer<typeof IdempotencyKeySchema>;
31
+
32
+ export const RunIdSchema = z.string().min(1).brand<'RunId'>();
33
+ export type RunId = z.infer<typeof RunIdSchema>;
34
+
35
+ export const AgentSessionIdSchema = z.string().min(1).brand<'AgentSessionId'>();
36
+ export type AgentSessionId = z.infer<typeof AgentSessionIdSchema>;
37
+
38
+ export const AgentTurnIdSchema = z.string().min(1).brand<'AgentTurnId'>();
39
+ export type AgentTurnId = z.infer<typeof AgentTurnIdSchema>;
40
+
41
+ export const EventIdSchema = z.string().min(1).brand<'EventId'>();
42
+ export type EventId = z.infer<typeof EventIdSchema>;
43
+
44
+ export const ArtifactIdSchema = z.string().min(1).brand<'ArtifactId'>();
45
+ export type ArtifactId = z.infer<typeof ArtifactIdSchema>;
46
+
47
+ export const ShipmentIdSchema = z.string().min(1).brand<'ShipmentId'>();
48
+ export type ShipmentId = z.infer<typeof ShipmentIdSchema>;
49
+
50
+ export const PromptSnapshotIdSchema = z.string().min(1).brand<'PromptSnapshotId'>();
51
+ export type PromptSnapshotId = z.infer<typeof PromptSnapshotIdSchema>;
52
+
53
+ /**
54
+ * Helper builders with runtime validation.
55
+ */
56
+ export const createProjectId = (id: string): ProjectId => ProjectIdSchema.parse(id);
57
+ export const createPluginId = (id: string): PluginId => PluginIdSchema.parse(id);
58
+ export const createOperationId = (id: string): OperationId => OperationIdSchema.parse(id);
59
+ export const createAuthorizationGrantId = (id: string): AuthorizationGrantId => AuthorizationGrantIdSchema.parse(id);
60
+ export const createBrowserRequestId = (id: string): BrowserRequestId => BrowserRequestIdSchema.parse(id);
61
+ export const createIdempotencyKey = (id: string): IdempotencyKey => IdempotencyKeySchema.parse(id);
62
+ export const createRunId = (id: string): RunId => RunIdSchema.parse(id);
63
+ export const createAgentSessionId = (id: string): AgentSessionId => AgentSessionIdSchema.parse(id);
64
+ export const createAgentTurnId = (id: string): AgentTurnId => AgentTurnIdSchema.parse(id);
65
+ export const createEventId = (id: string): EventId => EventIdSchema.parse(id);
66
+ export const createArtifactId = (id: string): ArtifactId => ArtifactIdSchema.parse(id);
67
+ export const createShipmentId = (id: string): ShipmentId => ShipmentIdSchema.parse(id);
68
+ export const createPromptSnapshotId = (id: string): PromptSnapshotId => PromptSnapshotIdSchema.parse(id);
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Shared cross-component contract authority for my-centcom.
3
+ * Governs all K01-K12 connection boundaries.
4
+ */
5
+
6
+ export * from './identity.js';
7
+ export * from './effects.js';
8
+ export * from './errors.js';
9
+ export * from './plugin.js';
10
+ export * from './invocation.js';
11
+ export * from './events.js';
12
+ export * from './lifecycle.js';
13
+ export * from './browser.js';
14
+ export * from './context.js';
15
+ export * from './artifacts.js';
16
+ export * from './secure.js';
17
+ export * from './diagnostics.js';
18
+ export * from './automation.js';
19
+ export * from './executionDiagnostics.js';
20
+ export * from './projectRead.js';
@@ -0,0 +1,96 @@
1
+ import { z } from 'zod';
2
+ import {
3
+ SchemaVersionV1Schema,
4
+ ProjectIdSchema,
5
+ PluginIdSchema,
6
+ OperationIdSchema,
7
+ AuthorizationGrantIdSchema,
8
+ BrowserRequestIdSchema,
9
+ IdempotencyKeySchema,
10
+ RunIdSchema,
11
+ } from './identity.js';
12
+ import { SecurityTierSchema, EffectClassSchema } from './effects.js';
13
+
14
+ /**
15
+ * Unauthorized operation request submitted by user/browser.
16
+ * Invariant: Must not be treated as an authorized invocation without an explicit grant.
17
+ */
18
+ export const OperationRequestV1Schema = z.object({
19
+ schemaVersion: SchemaVersionV1Schema,
20
+ requestId: BrowserRequestIdSchema,
21
+ projectId: ProjectIdSchema,
22
+ pluginId: PluginIdSchema,
23
+ operationId: OperationIdSchema,
24
+ idempotencyKey: IdempotencyKeySchema,
25
+ params: z.record(z.string(), z.unknown()),
26
+ requestedAt: z.string().datetime(),
27
+ requiresUserApproval: z.boolean(),
28
+ });
29
+ export type OperationRequestV1 = z.infer<typeof OperationRequestV1Schema>;
30
+
31
+ /**
32
+ * Authorized invocation approved by the project authorization authority.
33
+ * Invariant: Contains an authentic AuthorizationGrantId and assigned RunId.
34
+ */
35
+ export const AuthorizedInvocationSchema = z.object({
36
+ schemaVersion: SchemaVersionV1Schema,
37
+ runId: RunIdSchema,
38
+ projectId: ProjectIdSchema,
39
+ pluginId: PluginIdSchema,
40
+ operationId: OperationIdSchema,
41
+ authorizationGrantId: AuthorizationGrantIdSchema,
42
+ idempotencyKey: IdempotencyKeySchema,
43
+ params: z.record(z.string(), z.unknown()),
44
+ workingDirectory: z.string().min(1),
45
+ securityTier: SecurityTierSchema,
46
+ timeoutMs: z.number().int().positive(),
47
+ createdAt: z.string().datetime(),
48
+ });
49
+ export type AuthorizedInvocation = z.infer<typeof AuthorizedInvocationSchema>;
50
+
51
+ /**
52
+ * Validates whether an untrusted payload satisfies the AuthorizedInvocation contract.
53
+ */
54
+ export const isAuthorizedInvocation = (payload: unknown): payload is AuthorizedInvocation => {
55
+ return AuthorizedInvocationSchema.safeParse(payload).success;
56
+ };
57
+
58
+ /**
59
+ * Security Principal Kind.
60
+ * Enforces boundary separation between browser extension, MCP client, and local CLI.
61
+ */
62
+ export const SecurityPrincipalKindSchema = z.enum([
63
+ 'browser_extension',
64
+ 'mcp_client',
65
+ 'local_cli',
66
+ ]);
67
+ export type SecurityPrincipalKind = z.infer<typeof SecurityPrincipalKindSchema>;
68
+
69
+ /**
70
+ * Security Principal Record.
71
+ */
72
+ export const SecurityPrincipalV1Schema = z.object({
73
+ id: z.string().min(1),
74
+ kind: SecurityPrincipalKindSchema,
75
+ authenticated: z.boolean(),
76
+ pairingTokenHash: z.string().optional(),
77
+ });
78
+ export type SecurityPrincipalV1 = z.infer<typeof SecurityPrincipalV1Schema>;
79
+
80
+ /**
81
+ * Project Grant Contract.
82
+ * Invariant: Operations are authorized only when a specific principal and project grant permits an operation.
83
+ */
84
+ export const ProjectGrantV1Schema = z.object({
85
+ schemaVersion: SchemaVersionV1Schema,
86
+ grantId: AuthorizationGrantIdSchema,
87
+ projectId: ProjectIdSchema,
88
+ principalId: z.string().min(1),
89
+ pluginId: PluginIdSchema,
90
+ allowedOperations: z.array(OperationIdSchema),
91
+ maxEffectClass: EffectClassSchema,
92
+ grantedAt: z.string().datetime(),
93
+ expiresAt: z.string().datetime().optional(),
94
+ requiresConfirmation: z.boolean().default(true),
95
+ });
96
+ export type ProjectGrantV1 = z.infer<typeof ProjectGrantV1Schema>;
@@ -0,0 +1,169 @@
1
+ import { z } from 'zod';
2
+ import {
3
+ SchemaVersionV1Schema,
4
+ RunIdSchema,
5
+ ProjectIdSchema,
6
+ PluginIdSchema,
7
+ OperationIdSchema,
8
+ IdempotencyKeySchema,
9
+ ArtifactIdSchema,
10
+ } from './identity.js';
11
+ import { NormalizedResultSchema } from './plugin.js';
12
+
13
+ /**
14
+ * The 11 canonical run lifecycle states.
15
+ */
16
+ export const RunLifecycleStateSchema = z.enum([
17
+ 'CREATED',
18
+ 'AWAITING_USER_APPROVAL',
19
+ 'QUEUED',
20
+ 'STARTING',
21
+ 'RUNNING',
22
+ 'WAITING_AGENT_APPROVAL',
23
+ 'CANCEL_REQUESTED',
24
+ 'COMPLETED',
25
+ 'FAILED',
26
+ 'CANCELLED',
27
+ 'UNKNOWN',
28
+ ]);
29
+ export type RunLifecycleState = z.infer<typeof RunLifecycleStateSchema>;
30
+
31
+ /**
32
+ * Valid lifecycle transitions frozen consistent with ARCHITECTURE.md.
33
+ */
34
+ export const VALID_LIFECYCLE_TRANSITIONS: Readonly<
35
+ Record<RunLifecycleState, ReadonlySet<RunLifecycleState>>
36
+ > = {
37
+ CREATED: new Set(['AWAITING_USER_APPROVAL', 'QUEUED', 'CANCELLED']),
38
+ AWAITING_USER_APPROVAL: new Set(['QUEUED', 'CANCELLED', 'FAILED']),
39
+ QUEUED: new Set(['STARTING', 'CANCEL_REQUESTED', 'CANCELLED']),
40
+ STARTING: new Set(['RUNNING', 'CANCEL_REQUESTED', 'FAILED', 'UNKNOWN']),
41
+ RUNNING: new Set([
42
+ 'WAITING_AGENT_APPROVAL',
43
+ 'CANCEL_REQUESTED',
44
+ 'COMPLETED',
45
+ 'FAILED',
46
+ 'UNKNOWN',
47
+ ]),
48
+ WAITING_AGENT_APPROVAL: new Set([
49
+ 'RUNNING',
50
+ 'CANCEL_REQUESTED',
51
+ 'CANCELLED',
52
+ 'FAILED',
53
+ 'UNKNOWN', // Planner-authorized additive edge (SW-032): uncertain execution lost across a restart
54
+ ]),
55
+ CANCEL_REQUESTED: new Set([
56
+ 'CANCELLED',
57
+ 'COMPLETED', // Allowed when process completion races with cancellation intent
58
+ 'FAILED',
59
+ 'UNKNOWN',
60
+ ]),
61
+ COMPLETED: new Set([]),
62
+ FAILED: new Set([]),
63
+ CANCELLED: new Set([]),
64
+ UNKNOWN: new Set([]),
65
+ };
66
+
67
+ export const TERMINAL_LIFECYCLE_STATES: ReadonlySet<RunLifecycleState> = new Set([
68
+ 'COMPLETED',
69
+ 'FAILED',
70
+ 'CANCELLED',
71
+ 'UNKNOWN',
72
+ ]);
73
+
74
+ /**
75
+ * Core Invariants:
76
+ * 1. UNKNOWN is not equivalent to failure or successful completion.
77
+ * 2. Successful process exit does NOT prove application validation PASS.
78
+ */
79
+ export const isTerminalLifecycleState = (state: RunLifecycleState): boolean => {
80
+ return TERMINAL_LIFECYCLE_STATES.has(state);
81
+ };
82
+
83
+ export const isValidLifecycleTransition = (
84
+ from: RunLifecycleState,
85
+ to: RunLifecycleState
86
+ ): boolean => {
87
+ const allowed = VALID_LIFECYCLE_TRANSITIONS[from];
88
+ return allowed ? allowed.has(to) : false;
89
+ };
90
+
91
+ export class InvalidLifecycleTransitionError extends Error {
92
+ readonly fromState: RunLifecycleState;
93
+ readonly toState: RunLifecycleState;
94
+
95
+ constructor(from: RunLifecycleState, to: RunLifecycleState) {
96
+ super(`Invalid run lifecycle transition from ${from} to ${to}`);
97
+ this.name = 'InvalidLifecycleTransitionError';
98
+ this.fromState = from;
99
+ this.toState = to;
100
+ }
101
+ }
102
+
103
+ export const assertValidLifecycleTransition = (
104
+ from: RunLifecycleState,
105
+ to: RunLifecycleState
106
+ ): void => {
107
+ if (!isValidLifecycleTransition(from, to)) {
108
+ throw new InvalidLifecycleTransitionError(from, to);
109
+ }
110
+ };
111
+
112
+ /**
113
+ * Durable Run Record contract.
114
+ */
115
+ export const RunLifecycleRecordV1Schema = z.object({
116
+ schemaVersion: SchemaVersionV1Schema,
117
+ runId: RunIdSchema,
118
+ projectId: ProjectIdSchema,
119
+ pluginId: PluginIdSchema,
120
+ operationId: OperationIdSchema,
121
+ idempotencyKey: IdempotencyKeySchema,
122
+ currentState: RunLifecycleStateSchema,
123
+ history: z.array(
124
+ z.object({
125
+ state: RunLifecycleStateSchema,
126
+ timestamp: z.string().datetime(),
127
+ reason: z.string().optional(),
128
+ })
129
+ ),
130
+ cancellationRacingWithCompletion: z.boolean().default(false),
131
+ });
132
+ export type RunLifecycleRecordV1 = z.infer<typeof RunLifecycleRecordV1Schema>;
133
+
134
+ /**
135
+ * Implementation validation statuses.
136
+ * Invariant: Process exit code 0 or driver completion does NOT prove implementation validation PASS.
137
+ * Grounded solely in actual tests, reports, and verifiable evidence.
138
+ */
139
+ export const ImplementationValidationStatusSchema = z.enum([
140
+ 'PASS',
141
+ 'NEEDS_CORRECTION',
142
+ 'BLOCKED',
143
+ 'NOT_VERIFIED',
144
+ ]);
145
+ export type ImplementationValidationStatus = z.infer<
146
+ typeof ImplementationValidationStatusSchema
147
+ >;
148
+
149
+ /**
150
+ * Standard externally visible run outcome record separating:
151
+ * 1. Process outcome: whether CLI exited 0, failed, timed out, or was canceled.
152
+ * 2. Implementation validation: PASS, NEEDS_CORRECTION, BLOCKED, or NOT_VERIFIED.
153
+ * 3. Evidence: immutable artifact digests, Git baselines, and executed commands.
154
+ */
155
+ export const RunOutcomeRecordV1Schema = z.object({
156
+ schemaVersion: SchemaVersionV1Schema,
157
+ runId: RunIdSchema,
158
+ projectId: ProjectIdSchema,
159
+ processOutcome: NormalizedResultSchema,
160
+ validationStatus: ImplementationValidationStatusSchema,
161
+ evidence: z.object({
162
+ artifactIds: z.array(ArtifactIdSchema),
163
+ gitBaselineCommit: z.string().optional(),
164
+ gitCurrentCommit: z.string().optional(),
165
+ executedCommands: z.array(z.string()).optional(),
166
+ }),
167
+ recordedAt: z.string().datetime(),
168
+ });
169
+ export type RunOutcomeRecordV1 = z.infer<typeof RunOutcomeRecordV1Schema>;
@@ -0,0 +1,174 @@
1
+ import { z } from 'zod';
2
+ import {
3
+ SchemaVersionV1Schema,
4
+ PluginIdSchema,
5
+ OperationIdSchema,
6
+ RunIdSchema,
7
+ RunId,
8
+ AgentSessionId,
9
+ } from './identity.js';
10
+ import {
11
+ EffectClassSchema,
12
+ ExecutablePolicyV1Schema,
13
+ OutputBoundsV1Schema,
14
+ } from './effects.js';
15
+ import { AuthorizedInvocation } from './invocation.js';
16
+ import { NormalizedEvent } from './events.js';
17
+
18
+ export const PluginKindSchema = z.enum(['command', 'agent']);
19
+ export type PluginKind = z.infer<typeof PluginKindSchema>;
20
+
21
+ /**
22
+ * Distinct lifecycle states of a plugin registration.
23
+ * Invariant: Registered, verified, enabled, and authorized are distinct states.
24
+ * A registered plugin does NOT automatically receive execution permission.
25
+ */
26
+ export const PluginStateSchema = z.enum([
27
+ 'registered',
28
+ 'verified',
29
+ 'enabled',
30
+ 'authorized',
31
+ ]);
32
+ export type PluginState = z.infer<typeof PluginStateSchema>;
33
+
34
+ /**
35
+ * Hard ceiling (UTF-8 bytes) for a prompt delivered on a supervised process's stdin (SW-052).
36
+ */
37
+ export const STDIN_MAX_BYTES_V1 = 32768;
38
+
39
+ /**
40
+ * OPTIONAL, additive input transport for an operation (SW-052). Absent means V1 behaviour: the target's stdin is 'ignore' and
41
+ * ExecutablePolicyV1.stdio is unchanged. When present the trusted driver delivers the approved prompt (UTF-8 bytes, at most maxBytes,
42
+ * never more than STDIN_MAX_BYTES_V1) on a private pipe, written once and closed. It is a declaration inside the pinned manifest, so
43
+ * it is covered by the manifest fingerprint; it is never read from a run request.
44
+ */
45
+ export const InputTransportV1Schema = z.object({
46
+ kind: z.literal('stdin_utf8'),
47
+ maxBytes: z.number().int().positive().max(STDIN_MAX_BYTES_V1),
48
+ });
49
+ export type InputTransportV1 = z.infer<typeof InputTransportV1Schema>;
50
+
51
+ /**
52
+ * Declaration of a single plugin operation.
53
+ */
54
+ export const PluginOperationV1Schema = z.object({
55
+ id: OperationIdSchema,
56
+ name: z.string().min(1),
57
+ description: z.string().min(1),
58
+ effectClass: EffectClassSchema,
59
+ inputSchema: z.record(z.string(), z.unknown()),
60
+ executablePolicy: ExecutablePolicyV1Schema,
61
+ timeoutMs: z.number().int().positive(),
62
+ outputBounds: OutputBoundsV1Schema,
63
+ projectCwdRequired: z.boolean(),
64
+ inputTransport: InputTransportV1Schema.optional(),
65
+ });
66
+ export type PluginOperationV1 = z.infer<typeof PluginOperationV1Schema>;
67
+
68
+ /**
69
+ * Advanced agent driver capabilities.
70
+ * Invariant: Advertised only when empirically verified.
71
+ */
72
+ export const DriverCapabilitiesV1Schema = z.object({
73
+ supportsSession: z.boolean(),
74
+ supportsApproval: z.boolean(),
75
+ supportsResume: z.boolean(),
76
+ supportsStreaming: z.boolean(),
77
+ });
78
+ export type DriverCapabilitiesV1 = z.infer<typeof DriverCapabilitiesV1Schema>;
79
+
80
+ /**
81
+ * Manifest defining a registered plugin and its operations.
82
+ */
83
+ export const PluginManifestV1Schema = z.object({
84
+ schemaVersion: SchemaVersionV1Schema,
85
+ id: PluginIdSchema,
86
+ kind: PluginKindSchema,
87
+ name: z.string().min(1),
88
+ version: z.string().min(1),
89
+ description: z.string().min(1),
90
+ state: PluginStateSchema,
91
+ operations: z.record(OperationIdSchema, PluginOperationV1Schema),
92
+ capabilities: DriverCapabilitiesV1Schema.optional(),
93
+ });
94
+ export type PluginManifestV1 = z.infer<typeof PluginManifestV1Schema>;
95
+
96
+ /**
97
+ * Probe capability report emitted by a plugin driver.
98
+ */
99
+ export const CapabilityReportSchema = z.object({
100
+ pluginId: PluginIdSchema,
101
+ installed: z.boolean(),
102
+ installedVersion: z.string().optional(),
103
+ capabilities: DriverCapabilitiesV1Schema,
104
+ details: z.record(z.string(), z.unknown()).optional(),
105
+ });
106
+ export type CapabilityReport = z.infer<typeof CapabilityReportSchema>;
107
+
108
+ /**
109
+ * Run receipt returned upon driver invocation.
110
+ */
111
+ export const RunReceiptSchema = z.object({
112
+ runId: RunIdSchema,
113
+ pluginId: PluginIdSchema,
114
+ operationId: OperationIdSchema,
115
+ startedAt: z.string().datetime(),
116
+ processId: z.number().int().positive().optional(),
117
+ });
118
+ export type RunReceipt = z.infer<typeof RunReceiptSchema>;
119
+
120
+ /**
121
+ * Cancel receipt returned upon cancellation request.
122
+ */
123
+ export const CancelReceiptSchema = z.object({
124
+ runId: RunIdSchema,
125
+ cancelledAt: z.string().datetime(),
126
+ acknowledged: z.boolean(),
127
+ processTerminated: z.boolean(),
128
+ reason: z.string().min(1),
129
+ });
130
+ export type CancelReceipt = z.infer<typeof CancelReceiptSchema>;
131
+
132
+ /**
133
+ * Normalized result collected after run completes or halts.
134
+ */
135
+ export const NormalizedResultSchema = z.object({
136
+ runId: RunIdSchema,
137
+ exitCode: z.number().int(),
138
+ durationMs: z.number().int().nonnegative(),
139
+ outputSummary: z.string(),
140
+ tokenUsage: z
141
+ .object({
142
+ inputTokens: z.number().int().nonnegative().optional(),
143
+ outputTokens: z.number().int().nonnegative().optional(),
144
+ cachedTokens: z.number().int().nonnegative().optional(),
145
+ costUsd: z.number().nonnegative().optional(),
146
+ })
147
+ .optional(),
148
+ completedAt: z.string().datetime(),
149
+ });
150
+ export type NormalizedResult = z.infer<typeof NormalizedResultSchema>;
151
+
152
+ /**
153
+ * Required standard driver interface.
154
+ * Baseline invariant: Five methods, non-renegotiable responsibilities.
155
+ * The driver does NOT own project authorization, durable run truth, or artifact shipment policy.
156
+ */
157
+ export interface PluginDriver {
158
+ probe(): Promise<CapabilityReport>;
159
+ invoke(request: AuthorizedInvocation): Promise<RunReceipt>;
160
+ observe(runId: RunId): AsyncIterable<NormalizedEvent>;
161
+ cancel(runId: RunId, reason: string): Promise<CancelReceipt>;
162
+ collect(runId: RunId): Promise<NormalizedResult>;
163
+ }
164
+
165
+ /**
166
+ * Advanced agent driver interface extending PluginDriver.
167
+ * Advertises conditional session, turn, and approval operations.
168
+ * Basic CLI drivers and command plugins implement only PluginDriver.
169
+ */
170
+ export interface AgentDriver extends PluginDriver {
171
+ submitTurn?(sessionId: AgentSessionId, prompt: string): Promise<RunReceipt>;
172
+ respondToApproval?(runId: RunId, approved: boolean, reason?: string): Promise<void>;
173
+ resumeSession?(sessionId: AgentSessionId): Promise<RunReceipt>;
174
+ }