@dailephd/my-centcom 0.1.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,97 @@
1
+ /**
2
+ * C07 CHANGE PROPOSAL (SW-080). Provider-neutral, Node built-ins only (it is used by the small MCP adapter closure AND by the daemon's trusted workflow).
3
+ *
4
+ * A proposal is DATA: a bounded list of file operations with exact target paths and the SHA-256 of every file it expects to replace. It contains no command, no script to run, no
5
+ * executable path and no argument for any process. Submitting one never modifies the project; it only yields a canonical form and a digest that every later step (approval, apply,
6
+ * test, commit) is bound to. The same validator runs twice: at submission (feedback to the model, against the run's private view) and again, independently, in the daemon against
7
+ * the live project when the proposal is ingested and when it is applied. Nothing the model says about a proposal is trusted.
8
+ *
9
+ * Operations (whole-file, so that the result is exactly the bytes that were approved):
10
+ * create path, content the path must not exist; its parent directory must already exist
11
+ * modify path, preimageSha256, content replaces a regular file whose current SHA-256 equals preimageSha256
12
+ * delete path, preimageSha256 removes such a file
13
+ * rename path, to, preimageSha256 moves such a file unchanged to a path that does not exist
14
+ */
15
+ export declare const CP_SCHEMA = "my-centcom.change-proposal/1";
16
+ export declare const CP_LIMITS: Readonly<{
17
+ maxOperations: 20;
18
+ maxFileContentBytes: 65536;
19
+ maxTotalContentBytes: 262144;
20
+ maxSummaryChars: 500;
21
+ maxCanonicalBytes: 450000;
22
+ }>;
23
+ /** Extensions a proposal may create or modify (source and documentation only; nothing a loader or shell would execute by itself). */
24
+ export declare const CP_ALLOWED_EXTENSIONS: readonly string[];
25
+ /** Independent acceptance tests are the oracle for a change: a proposal may not edit them. Policy value, replaceable only by the trusted caller. */
26
+ export declare const CP_DEFAULT_PROTECTED_PREFIXES: readonly string[];
27
+ export type CpOp = {
28
+ readonly op: 'create';
29
+ readonly path: string;
30
+ readonly content: string;
31
+ } | {
32
+ readonly op: 'modify';
33
+ readonly path: string;
34
+ readonly preimageSha256: string;
35
+ readonly content: string;
36
+ } | {
37
+ readonly op: 'delete';
38
+ readonly path: string;
39
+ readonly preimageSha256: string;
40
+ } | {
41
+ readonly op: 'rename';
42
+ readonly path: string;
43
+ readonly to: string;
44
+ readonly preimageSha256: string;
45
+ };
46
+ export interface CpNormalizedOp {
47
+ readonly op: 'create' | 'modify' | 'delete' | 'rename';
48
+ readonly path: string;
49
+ readonly to?: string;
50
+ readonly preimageSha256?: string;
51
+ readonly content?: string;
52
+ readonly contentSha256?: string;
53
+ readonly contentBytes: number;
54
+ }
55
+ export interface CpProposal {
56
+ readonly schema: typeof CP_SCHEMA;
57
+ readonly summary: string;
58
+ readonly operations: readonly CpNormalizedOp[];
59
+ }
60
+ export interface CpEffect {
61
+ readonly classification: 'write_project';
62
+ readonly destructive: boolean;
63
+ readonly operations: number;
64
+ readonly creates: number;
65
+ readonly modifies: number;
66
+ readonly deletes: number;
67
+ readonly renames: number;
68
+ readonly totalContentBytes: number;
69
+ readonly paths: readonly string[];
70
+ }
71
+ export type CpDenied = 'PROPOSAL_INVALID' | 'TOO_MANY_OPERATIONS' | 'TOO_LARGE' | 'CONTENT_INVALID' | 'EXTENSION_NOT_ALLOWED' | 'PATH_PROTECTED' | 'PATH_EXECUTION_CONFIG' | 'DUPLICATE_PATH' | 'PREIMAGE_REQUIRED' | 'PREIMAGE_MISMATCH' | 'TARGET_MISSING' | 'TARGET_EXISTS' | 'PARENT_MISSING' | 'RENAME_INVALID' | 'NO_CHANGE' | 'EMPTY_PROPOSAL' | 'PATH_REJECTED';
72
+ export type CpResult = {
73
+ readonly ok: true;
74
+ readonly proposal: CpProposal;
75
+ readonly canonicalJson: string;
76
+ readonly digest: string;
77
+ readonly effect: CpEffect;
78
+ } | {
79
+ readonly ok: false;
80
+ readonly code: CpDenied | string;
81
+ readonly message: string;
82
+ readonly index?: number;
83
+ };
84
+ export interface CpContext {
85
+ /** Physical root against which preimages and targets are checked (the run's private view at submission, the live project in the daemon). */
86
+ readonly root: string;
87
+ readonly protectedPrefixes?: readonly string[];
88
+ }
89
+ /** Validates an untrusted proposal against `ctx.root` and returns its canonical form, digest and effect classification. Reads only; never writes. */
90
+ export declare function validateProposal(input: unknown, ctx: CpContext): CpResult;
91
+ /** Fixed key order per operation: the same logical proposal always has the same bytes and the same digest. */
92
+ export declare function canonicalize(p: CpProposal): string;
93
+ /** Rebuilds the derived fields (content digests and sizes) that the canonical form deliberately omits, from the stored bytes themselves. The input must already be canonical. */
94
+ export declare function hydrateStored(canonicalJson: string): CpProposal;
95
+ /** Re-reads a stored canonical proposal as untrusted input (it is validated again, and must reproduce exactly the same canonical bytes). */
96
+ export declare function revalidateStored(canonicalJson: string, ctx: CpContext): CpResult;
97
+ //# sourceMappingURL=changeProposal.d.ts.map
@@ -0,0 +1,259 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { PR_LIMITS, readProjectFileWhole, validateRelativePath, walkProjectPath } from './projectReadService.js';
3
+ /**
4
+ * C07 CHANGE PROPOSAL (SW-080). Provider-neutral, Node built-ins only (it is used by the small MCP adapter closure AND by the daemon's trusted workflow).
5
+ *
6
+ * A proposal is DATA: a bounded list of file operations with exact target paths and the SHA-256 of every file it expects to replace. It contains no command, no script to run, no
7
+ * executable path and no argument for any process. Submitting one never modifies the project; it only yields a canonical form and a digest that every later step (approval, apply,
8
+ * test, commit) is bound to. The same validator runs twice: at submission (feedback to the model, against the run's private view) and again, independently, in the daemon against
9
+ * the live project when the proposal is ingested and when it is applied. Nothing the model says about a proposal is trusted.
10
+ *
11
+ * Operations (whole-file, so that the result is exactly the bytes that were approved):
12
+ * create path, content the path must not exist; its parent directory must already exist
13
+ * modify path, preimageSha256, content replaces a regular file whose current SHA-256 equals preimageSha256
14
+ * delete path, preimageSha256 removes such a file
15
+ * rename path, to, preimageSha256 moves such a file unchanged to a path that does not exist
16
+ */
17
+ export const CP_SCHEMA = 'my-centcom.change-proposal/1';
18
+ export const CP_LIMITS = Object.freeze({ maxOperations: 20, maxFileContentBytes: 65_536, maxTotalContentBytes: 262_144, maxSummaryChars: 500, maxCanonicalBytes: 450_000 });
19
+ /** Extensions a proposal may create or modify (source and documentation only; nothing a loader or shell would execute by itself). */
20
+ export const CP_ALLOWED_EXTENSIONS = Object.freeze(['.js', '.mjs', '.cjs', '.ts', '.tsx', '.jsx', '.json', '.md', '.txt', '.css', '.html']);
21
+ /** Names that give a project executable authority (script runners, package manifests, Git configuration, CI). Never writable through a proposal. */
22
+ const EXEC_CONFIG_NAMES = new Set(['package.json', 'package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'tsconfig.json', 'jsconfig.json']);
23
+ const EXEC_CONFIG_DIRS = new Set(['node_modules', '.github', '.husky', '.vscode', '.idea', '.circleci', '.gitlab']);
24
+ /** Independent acceptance tests are the oracle for a change: a proposal may not edit them. Policy value, replaceable only by the trusted caller. */
25
+ export const CP_DEFAULT_PROTECTED_PREFIXES = Object.freeze(['test/', 'tests/', '__tests__/', 'spec/']);
26
+ const sha = (b) => createHash('sha256').update(b).digest('hex');
27
+ const SHA_RE = /^[a-f0-9]{64}$/;
28
+ const WIN = process.platform === 'win32';
29
+ const fold = (s) => s.toLowerCase();
30
+ const fail = (code, message, index) => ({ ok: false, code, message, ...(index === undefined ? {} : { index }) });
31
+ const CONTROL_OK = /[\u0000-\u0008\u000b\u000e-\u001f\u007f]/; // C0 controls other than \t \n \f \r, and DEL
32
+ const HI = '[' + String.fromCharCode(0xd800) + '-' + String.fromCharCode(0xdbff) + ']';
33
+ const LO = '[' + String.fromCharCode(0xdc00) + '-' + String.fromCharCode(0xdfff) + ']';
34
+ const LONE_SURROGATE = new RegExp(HI + '(?!' + LO + ')|(?<!' + HI + ')' + LO);
35
+ const hasLoneSurrogate = (s) => LONE_SURROGATE.test(s);
36
+ function extOf(name) { const i = name.lastIndexOf('.'); return i <= 0 ? '' : name.slice(i).toLowerCase(); }
37
+ /** Write-policy on a single validated relative path (read policy is already applied by validateRelativePath). */
38
+ function writePolicy(segs, protectedPrefixes) {
39
+ const lower = segs.map(fold);
40
+ const rel = lower.join('/');
41
+ if (protectedPrefixes.some((p) => rel.startsWith(fold(p)) || rel + '/' === fold(p)))
42
+ return 'PATH_PROTECTED';
43
+ if (lower.some((s) => EXEC_CONFIG_DIRS.has(s)) || EXEC_CONFIG_NAMES.has(lower[lower.length - 1]) || lower.some((s) => s.startsWith('.git')))
44
+ return 'PATH_EXECUTION_CONFIG';
45
+ if (!CP_ALLOWED_EXTENSIONS.includes(extOf(lower[lower.length - 1])))
46
+ return 'EXTENSION_NOT_ALLOWED';
47
+ return undefined;
48
+ }
49
+ function textOk(content) {
50
+ if (typeof content !== 'string')
51
+ return 'content must be a string';
52
+ if (CONTROL_OK.test(content))
53
+ return 'content contains control characters';
54
+ if (hasLoneSurrogate(content))
55
+ return 'content is not valid Unicode text';
56
+ return undefined;
57
+ }
58
+ function ownKeys(o, required) {
59
+ if (o === null || typeof o !== 'object' || Array.isArray(o))
60
+ return false;
61
+ const proto = Object.getPrototypeOf(o);
62
+ if (proto !== Object.prototype && proto !== null)
63
+ return false;
64
+ const ks = Object.keys(o);
65
+ return ks.length === required.length && required.every((k) => ks.includes(k));
66
+ }
67
+ const ORDER = Object.freeze({
68
+ create: ['op', 'path', 'content'], modify: ['op', 'path', 'preimageSha256', 'content'], delete: ['op', 'path', 'preimageSha256'], rename: ['op', 'path', 'to', 'preimageSha256'],
69
+ });
70
+ /** Validates an untrusted proposal against `ctx.root` and returns its canonical form, digest and effect classification. Reads only; never writes. */
71
+ export function validateProposal(input, ctx) {
72
+ if (!ownKeys(input, ['summary', 'operations']))
73
+ return fail('PROPOSAL_INVALID', 'a proposal has exactly the keys summary and operations');
74
+ const summary = input.summary;
75
+ if (typeof summary !== 'string' || summary.length < 1 || summary.length > CP_LIMITS.maxSummaryChars || /[\u0000-\u001f\u007f]/.test(summary))
76
+ return fail('PROPOSAL_INVALID', 'summary must be 1-500 printable characters');
77
+ const opsIn = input.operations;
78
+ if (!Array.isArray(opsIn))
79
+ return fail('PROPOSAL_INVALID', 'operations must be an array');
80
+ if (opsIn.length === 0)
81
+ return fail('EMPTY_PROPOSAL', 'a proposal needs at least one operation');
82
+ if (opsIn.length > CP_LIMITS.maxOperations)
83
+ return fail('TOO_MANY_OPERATIONS', `at most ${CP_LIMITS.maxOperations} operations`);
84
+ const prot = ctx.protectedPrefixes ?? CP_DEFAULT_PROTECTED_PREFIXES;
85
+ const out = [];
86
+ const seen = new Map(); // case-folded path -> operation index (Windows and macOS file systems are case-insensitive)
87
+ let total = 0;
88
+ const segsOf = (p, i) => {
89
+ const v = validateRelativePath(p, { allowRoot: false });
90
+ if (!v.ok)
91
+ return fail(v.code, v.message, i);
92
+ const w = writePolicy(v.value, prot);
93
+ if (w)
94
+ return fail(w, w === 'PATH_PROTECTED' ? 'this path is protected from proposals' : w === 'PATH_EXECUTION_CONFIG' ? 'this file gives the project executable authority and cannot be changed by a proposal' : 'this file type cannot be changed by a proposal', i);
95
+ return { segs: v.value };
96
+ };
97
+ const claim = (rel, i) => {
98
+ const k = fold(rel);
99
+ if (seen.has(k))
100
+ return fail('DUPLICATE_PATH', `path is used by more than one operation (also operation ${seen.get(k)})`, i);
101
+ seen.set(k, i);
102
+ return undefined;
103
+ };
104
+ const stat = (segs, i) => {
105
+ const n = walkProjectPath(ctx.root, segs, 'file');
106
+ if (!n.ok)
107
+ return n.code === 'PATH_NOT_FOUND' ? fail('TARGET_MISSING', 'the target file does not exist', i) : fail(n.code, n.message, i);
108
+ const w = readProjectFileWhole(n.value, ctx.root, segs, PR_LIMITS.maxFileBytes);
109
+ if (!w.ok)
110
+ return fail(w.code, w.message, i);
111
+ return { sha: sha(w.value.bytes), size: w.value.bytes.length };
112
+ };
113
+ const exists = (segs) => {
114
+ const n = walkProjectPath(ctx.root, segs, 'file');
115
+ if (n.ok)
116
+ return true;
117
+ if (n.code === 'PATH_NOT_FOUND')
118
+ return false;
119
+ if (n.code === 'NOT_A_FILE')
120
+ return true; // a directory (or other object) is there
121
+ return { ok: false, code: n.code, message: n.message };
122
+ };
123
+ const parentOk = (segs, i) => {
124
+ if (segs.length === 1)
125
+ return undefined;
126
+ const d = walkProjectPath(ctx.root, segs.slice(0, -1), 'directory');
127
+ return d.ok ? undefined : fail('PARENT_MISSING', 'the parent directory must already exist inside the project', i);
128
+ };
129
+ for (let i = 0; i < opsIn.length; i += 1) {
130
+ const raw = opsIn[i];
131
+ const kind = raw !== null && typeof raw === 'object' && !Array.isArray(raw) ? raw.op : undefined;
132
+ if (typeof kind !== 'string' || !(kind in ORDER))
133
+ return fail('PROPOSAL_INVALID', 'unknown operation kind', i);
134
+ if (!ownKeys(raw, ORDER[kind]))
135
+ return fail('PROPOSAL_INVALID', `a ${kind} operation has exactly the keys ${ORDER[kind].join(', ')}`, i);
136
+ const o = raw;
137
+ const s = segsOf(o.path, i);
138
+ if (!('segs' in s))
139
+ return s;
140
+ const rel = s.segs.join('/');
141
+ const dup = claim(rel, i);
142
+ if (dup)
143
+ return dup;
144
+ let pre;
145
+ if (kind !== 'create') {
146
+ if (typeof o.preimageSha256 !== 'string' || !SHA_RE.test(o.preimageSha256))
147
+ return fail('PREIMAGE_REQUIRED', 'preimageSha256 must be the 64-hex SHA-256 of the file being replaced', i);
148
+ pre = o.preimageSha256;
149
+ }
150
+ if (kind === 'create' || kind === 'modify') {
151
+ const bad = textOk(o.content);
152
+ if (bad)
153
+ return fail('CONTENT_INVALID', bad, i);
154
+ const bytes = Buffer.byteLength(o.content, 'utf8');
155
+ if (bytes > CP_LIMITS.maxFileContentBytes)
156
+ return fail('TOO_LARGE', `content of one file is limited to ${CP_LIMITS.maxFileContentBytes} bytes`, i);
157
+ total += bytes;
158
+ if (total > CP_LIMITS.maxTotalContentBytes)
159
+ return fail('TOO_LARGE', `total content is limited to ${CP_LIMITS.maxTotalContentBytes} bytes`, i);
160
+ }
161
+ if (kind === 'create') {
162
+ const e = exists(s.segs);
163
+ if (typeof e !== 'boolean')
164
+ return { ...e, index: i };
165
+ if (e)
166
+ return fail('TARGET_EXISTS', 'the path already exists; use modify', i);
167
+ const p = parentOk(s.segs, i);
168
+ if (p)
169
+ return p;
170
+ out.push({ op: 'create', path: rel, content: o.content, contentSha256: sha(o.content), contentBytes: Buffer.byteLength(o.content, 'utf8') });
171
+ continue;
172
+ }
173
+ const cur = stat(s.segs, i);
174
+ if (!('sha' in cur))
175
+ return cur;
176
+ if (cur.sha !== pre)
177
+ return fail('PREIMAGE_MISMATCH', 'the file changed or the preimage hash is wrong; read the file again', i);
178
+ if (kind === 'modify') {
179
+ if (sha(o.content) === cur.sha)
180
+ return fail('NO_CHANGE', 'the new content equals the current content', i);
181
+ out.push({ op: 'modify', path: rel, preimageSha256: pre, content: o.content, contentSha256: sha(o.content), contentBytes: Buffer.byteLength(o.content, 'utf8') });
182
+ }
183
+ else if (kind === 'delete') {
184
+ out.push({ op: 'delete', path: rel, preimageSha256: pre, contentBytes: 0 });
185
+ }
186
+ else {
187
+ const t = segsOf(o.to, i);
188
+ if (!('segs' in t))
189
+ return t;
190
+ const trel = t.segs.join('/');
191
+ if (fold(trel) === fold(rel))
192
+ return fail('RENAME_INVALID', 'a rename must change the path (case-only renames are not supported)', i);
193
+ const d2 = claim(trel, i);
194
+ if (d2)
195
+ return d2;
196
+ const e = exists(t.segs);
197
+ if (typeof e !== 'boolean')
198
+ return { ...e, index: i };
199
+ if (e)
200
+ return fail('TARGET_EXISTS', 'the rename target already exists', i);
201
+ const p = parentOk(t.segs, i);
202
+ if (p)
203
+ return p;
204
+ out.push({ op: 'rename', path: rel, to: trel, preimageSha256: pre, contentBytes: 0 });
205
+ }
206
+ }
207
+ // canonical form: operations ordered by (folded path, kind); keys in fixed order; nothing optional is omitted or reordered
208
+ const ordered = [...out].sort((a, b) => (fold(a.path) < fold(b.path) ? -1 : fold(a.path) > fold(b.path) ? 1 : a.op < b.op ? -1 : 1));
209
+ const proposal = { schema: CP_SCHEMA, summary, operations: ordered };
210
+ const canonicalJson = canonicalize(proposal);
211
+ if (Buffer.byteLength(canonicalJson, 'utf8') > CP_LIMITS.maxCanonicalBytes)
212
+ return fail('TOO_LARGE', 'the proposal is too large');
213
+ const count = (k) => ordered.filter((x) => x.op === k).length;
214
+ const effect = { classification: 'write_project', destructive: count('delete') > 0, operations: ordered.length, creates: count('create'), modifies: count('modify'), deletes: count('delete'), renames: count('rename'),
215
+ totalContentBytes: total, paths: ordered.flatMap((x) => (x.to ? [x.path, x.to] : [x.path])) };
216
+ void WIN;
217
+ return { ok: true, proposal, canonicalJson, digest: sha(canonicalJson), effect };
218
+ }
219
+ /** Fixed key order per operation: the same logical proposal always has the same bytes and the same digest. */
220
+ export function canonicalize(p) {
221
+ const op = (x) => {
222
+ const base = { op: x.op, path: x.path };
223
+ if (x.to !== undefined)
224
+ base.to = x.to;
225
+ if (x.preimageSha256 !== undefined)
226
+ base.preimageSha256 = x.preimageSha256;
227
+ if (x.content !== undefined)
228
+ base.content = x.content;
229
+ return base;
230
+ };
231
+ return JSON.stringify({ schema: p.schema, summary: p.summary, operations: p.operations.map(op) });
232
+ }
233
+ /** Rebuilds the derived fields (content digests and sizes) that the canonical form deliberately omits, from the stored bytes themselves. The input must already be canonical. */
234
+ export function hydrateStored(canonicalJson) {
235
+ const o = JSON.parse(canonicalJson);
236
+ return { schema: o.schema, summary: o.summary, operations: o.operations.map((x) => {
237
+ const content = typeof x.content === 'string' ? x.content : undefined;
238
+ return { ...x, ...(content !== undefined ? { contentSha256: sha(content) } : {}), contentBytes: content !== undefined ? Buffer.byteLength(content, 'utf8') : 0 };
239
+ }) };
240
+ }
241
+ /** Re-reads a stored canonical proposal as untrusted input (it is validated again, and must reproduce exactly the same canonical bytes). */
242
+ export function revalidateStored(canonicalJson, ctx) {
243
+ let o;
244
+ try {
245
+ o = JSON.parse(canonicalJson);
246
+ }
247
+ catch {
248
+ return fail('PROPOSAL_INVALID', 'stored proposal is not JSON');
249
+ }
250
+ if (o === null || typeof o !== 'object' || o.schema !== CP_SCHEMA)
251
+ return fail('PROPOSAL_INVALID', 'stored proposal has the wrong schema');
252
+ const r = validateProposal({ summary: o.summary, operations: o.operations }, ctx);
253
+ if (!r.ok)
254
+ return r;
255
+ if (r.canonicalJson !== canonicalJson)
256
+ return fail('PROPOSAL_INVALID', 'stored proposal is not in canonical form');
257
+ return r;
258
+ }
259
+ //# sourceMappingURL=changeProposal.js.map
@@ -0,0 +1,88 @@
1
+ import type { CpProposal } from './changeProposal.js';
2
+ export interface GitChange {
3
+ readonly path: string;
4
+ readonly sha256: string | null;
5
+ readonly xy: string;
6
+ }
7
+ export interface GitEvidence {
8
+ readonly baseHead: string;
9
+ readonly headNow: string;
10
+ readonly headUnchanged: boolean;
11
+ readonly clean: boolean;
12
+ readonly changes: readonly GitChange[];
13
+ readonly diffSha256: string;
14
+ readonly treeSha256: string;
15
+ readonly match: boolean;
16
+ readonly expected: readonly {
17
+ path: string;
18
+ sha256: string | null;
19
+ }[];
20
+ readonly unexpected: readonly string[];
21
+ readonly missing: readonly string[];
22
+ readonly mismatched: readonly string[];
23
+ readonly unreadable: readonly string[];
24
+ }
25
+ export type GitFail = {
26
+ readonly ok: false;
27
+ readonly code: 'GIT_UNAVAILABLE' | 'GIT_FAILED' | 'ROOT_INVALID' | 'DIRTY' | 'HEAD_CHANGED' | 'WORKSPACE_EXISTS' | 'OUTPUT_INVALID';
28
+ readonly detail?: string;
29
+ };
30
+ export interface GitEvidenceService {
31
+ branchOf(root: string): string;
32
+ prepareCommit(i: {
33
+ root: string;
34
+ baseHead: string;
35
+ proposal: CpProposal;
36
+ indexFile: string;
37
+ message: string;
38
+ }): {
39
+ branch: string;
40
+ candidate: string;
41
+ tree: string;
42
+ message: string;
43
+ parent: string;
44
+ indexSha256: string;
45
+ };
46
+ finishCommit(i: {
47
+ root: string;
48
+ branch: string;
49
+ candidate: string;
50
+ parent: string;
51
+ tree: string;
52
+ message: string;
53
+ proposal: CpProposal;
54
+ indexSha256: string;
55
+ }, update: boolean): void;
56
+ headOf(root: string): string | undefined;
57
+ statusOf(root: string): {
58
+ ok: true;
59
+ entries: readonly {
60
+ xy: string;
61
+ path: string;
62
+ }[];
63
+ } | GitFail;
64
+ createWorkspace(srcRoot: string, destRoot: string): {
65
+ ok: true;
66
+ head: string;
67
+ } | GitFail;
68
+ observe(root: string, baseHead: string, proposal?: CpProposal): {
69
+ ok: true;
70
+ evidence: GitEvidence;
71
+ } | GitFail;
72
+ commit(i: {
73
+ root: string;
74
+ baseHead: string;
75
+ paths: readonly string[];
76
+ message: string;
77
+ }): {
78
+ ok: true;
79
+ commit: string;
80
+ parent: string;
81
+ files: readonly string[];
82
+ } | GitFail;
83
+ }
84
+ export declare function createGitEvidence(cfg: {
85
+ gitExecutablePath: string;
86
+ timeoutMs?: number;
87
+ }): GitEvidenceService;
88
+ //# sourceMappingURL=gitEvidence.d.ts.map