@mogragsigma/dsh-dual-host-plugin 0.0.0-stage → 0.33.2

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 (271) hide show
  1. package/LICENSE +58 -0
  2. package/LICENSE.en.md +94 -0
  3. package/README.md +88 -2
  4. package/bundle/ASSET_NOTICE.md +19 -0
  5. package/bundle/LICENSE +58 -0
  6. package/bundle/LICENSE.en.md +94 -0
  7. package/bundle/README.md +75 -0
  8. package/bundle/THIRD_PARTY_NOTICES.md +94 -0
  9. package/bundle/a2a-dispatches.js +38 -0
  10. package/bundle/a2a-endpoint.js +112 -0
  11. package/bundle/a2a-tools.js +11 -0
  12. package/bundle/a2a-worker.js +63 -0
  13. package/bundle/approval-auth.js +5 -0
  14. package/bundle/approval-chat.js +150 -0
  15. package/bundle/approval-feishu.js +52 -0
  16. package/bundle/approval-guidance.js +68 -0
  17. package/bundle/approval-http.js +8 -0
  18. package/bundle/approval-ledger.js +142 -0
  19. package/bundle/approval-local-relay.js +86 -0
  20. package/bundle/approval-receipts.js +62 -0
  21. package/bundle/approval-reference.js +33 -0
  22. package/bundle/approval-semantic-model.js +26 -0
  23. package/bundle/approval-semantics.js +51 -0
  24. package/bundle/approval-ui/app.js +1 -0
  25. package/bundle/approval-ui/index.html +1 -0
  26. package/bundle/approval-ui/style.css +1 -0
  27. package/bundle/approval-workbench.js +45 -0
  28. package/bundle/artifact-media.js +34 -0
  29. package/bundle/bounded-text.js +44 -0
  30. package/bundle/compatibility.json +980 -0
  31. package/bundle/cordis.patch.yml +5 -0
  32. package/bundle/delivery-approval.js +133 -0
  33. package/bundle/delivery-artifacts.js +52 -0
  34. package/bundle/delivery-commit.js +125 -0
  35. package/bundle/delivery-contract.js +42 -0
  36. package/bundle/delivery-git-read.js +217 -0
  37. package/bundle/delivery-index.js +23 -0
  38. package/bundle/delivery-journal.js +207 -0
  39. package/bundle/delivery-object-plan.js +138 -0
  40. package/bundle/delivery-preview.js +153 -0
  41. package/bundle/delivery-process-receipts.js +90 -0
  42. package/bundle/delivery-process.js +46 -0
  43. package/bundle/delivery-process.py +228 -0
  44. package/bundle/delivery-push-approval.js +89 -0
  45. package/bundle/delivery-push-plan.js +98 -0
  46. package/bundle/delivery-push-recovery.js +32 -0
  47. package/bundle/delivery-push.js +83 -0
  48. package/bundle/delivery-recovery.js +143 -0
  49. package/bundle/delivery-runtime.js +182 -0
  50. package/bundle/delivery-ssh.js +64 -0
  51. package/bundle/delivery-state.js +106 -0
  52. package/bundle/development-attention.js +35 -0
  53. package/bundle/development-bridge.js +136 -0
  54. package/bundle/development-command-review.js +110 -0
  55. package/bundle/development-container.js +110 -0
  56. package/bundle/development-contract.js +17 -0
  57. package/bundle/development-files.js +101 -0
  58. package/bundle/development-gate.js +236 -0
  59. package/bundle/development-model-budget.js +48 -0
  60. package/bundle/development-peer.js +155 -0
  61. package/bundle/development-plan.js +43 -0
  62. package/bundle/development-reconciliation.js +62 -0
  63. package/bundle/development-review.js +81 -0
  64. package/bundle/development-rules/AGENTS.md +51 -0
  65. package/bundle/development-runtime.js +68 -0
  66. package/bundle/development-source.js +48 -0
  67. package/bundle/development-test-runner.js +13 -0
  68. package/bundle/development-tools.js +45 -0
  69. package/bundle/development-worker-review.js +110 -0
  70. package/bundle/development-worker.js +68 -0
  71. package/bundle/development-workspace.js +54 -0
  72. package/bundle/diagnostics.js +78 -0
  73. package/bundle/distribution-lock.json +773 -0
  74. package/bundle/drained-process.js +26 -0
  75. package/bundle/durable-inbox.js +294 -0
  76. package/bundle/feishu-policy.js +24 -0
  77. package/bundle/gateway-maintenance.js +55 -0
  78. package/bundle/global-rules/AGENTS.md +83 -0
  79. package/bundle/im-delivery.js +60 -0
  80. package/bundle/index.js +445 -0
  81. package/bundle/intervention-actions.js +135 -0
  82. package/bundle/intervention-job-control.js +28 -0
  83. package/bundle/intervention-state.js +43 -0
  84. package/bundle/job-version.js +15 -0
  85. package/bundle/legacy-feishu-adapter.js +89 -0
  86. package/bundle/link-contract.js +80 -0
  87. package/bundle/maintenance-process-identity.js +93 -0
  88. package/bundle/model-selection.js +71 -0
  89. package/bundle/native-context.js +14 -0
  90. package/bundle/native-entry-admission.js +2 -0
  91. package/bundle/native-entry.js +58 -0
  92. package/bundle/native-file-reference.js +32 -0
  93. package/bundle/native-owner-origin.js +12 -0
  94. package/bundle/native-rules/AGENTS.md +199 -0
  95. package/bundle/native-tools.js +108 -0
  96. package/bundle/notification-artifacts.js +70 -0
  97. package/bundle/notification-contract.js +29 -0
  98. package/bundle/notification-defaults.js +81 -0
  99. package/bundle/notification-discovery.js +65 -0
  100. package/bundle/notification-endpoint.js +54 -0
  101. package/bundle/notification-feishu.js +51 -0
  102. package/bundle/notification-media-endpoint.js +94 -0
  103. package/bundle/notification-review.js +27 -0
  104. package/bundle/notification-targets.js +54 -0
  105. package/bundle/onboarding-activity.js +66 -0
  106. package/bundle/onboarding-agent-hold.js +94 -0
  107. package/bundle/onboarding-boundary.js +20 -0
  108. package/bundle/onboarding-cloud-contract.js +29 -0
  109. package/bundle/onboarding-cloud-file-review.js +58 -0
  110. package/bundle/onboarding-cloud-files.js +100 -0
  111. package/bundle/onboarding-cloud-im.js +34 -0
  112. package/bundle/onboarding-cloud-model-probe.js +53 -0
  113. package/bundle/onboarding-cloud-models.js +68 -0
  114. package/bundle/onboarding-cloud-operation.js +276 -0
  115. package/bundle/onboarding-cloud-package.js +38 -0
  116. package/bundle/onboarding-cloud-repositories.js +89 -0
  117. package/bundle/onboarding-cloud-retirement.js +59 -0
  118. package/bundle/onboarding-cloud-task-runtime.js +90 -0
  119. package/bundle/onboarding-cloud-web.js +85 -0
  120. package/bundle/onboarding-cloud.js +110 -0
  121. package/bundle/onboarding-coordinated-hold.js +94 -0
  122. package/bundle/onboarding-exclusive-rename.js +16 -0
  123. package/bundle/onboarding-existing-host.js +63 -0
  124. package/bundle/onboarding-existing-setup.js +123 -0
  125. package/bundle/onboarding-file-contract.js +31 -0
  126. package/bundle/onboarding-file-review-contract.js +38 -0
  127. package/bundle/onboarding-file-transfer.js +133 -0
  128. package/bundle/onboarding-handoff-remote.js +98 -0
  129. package/bundle/onboarding-handoff.js +112 -0
  130. package/bundle/onboarding-host-stop-observation.js +44 -0
  131. package/bundle/onboarding-host.js +254 -0
  132. package/bundle/onboarding-identity.js +9 -0
  133. package/bundle/onboarding-im-maintenance-native.js +30 -0
  134. package/bundle/onboarding-im-maintenance.js +70 -0
  135. package/bundle/onboarding-im.js +31 -0
  136. package/bundle/onboarding-inspection-guard.js +15 -0
  137. package/bundle/onboarding-install-fs.js +58 -0
  138. package/bundle/onboarding-installer.js +157 -0
  139. package/bundle/onboarding-local-pair-native.js +21 -0
  140. package/bundle/onboarding-local-pair.js +99 -0
  141. package/bundle/onboarding-maintenance-fs.js +69 -0
  142. package/bundle/onboarding-maintenance-plan.js +213 -0
  143. package/bundle/onboarding-maintenance-record.js +169 -0
  144. package/bundle/onboarding-maintenance.js +163 -0
  145. package/bundle/onboarding-model-probe.js +119 -0
  146. package/bundle/onboarding-models.js +107 -0
  147. package/bundle/onboarding-native-host.js +101 -0
  148. package/bundle/onboarding-native-probe.js +56 -0
  149. package/bundle/onboarding-native-runner.js +29 -0
  150. package/bundle/onboarding-node-bootstrap.py +678 -0
  151. package/bundle/onboarding-node.js +77 -0
  152. package/bundle/onboarding-notification-defaults.js +93 -0
  153. package/bundle/onboarding-package-source.js +33 -0
  154. package/bundle/onboarding-paths.js +58 -0
  155. package/bundle/onboarding-peer-binding.js +61 -0
  156. package/bundle/onboarding-peer-contract.js +12 -0
  157. package/bundle/onboarding-plugin-repair.js +116 -0
  158. package/bundle/onboarding-plugin-version.js +143 -0
  159. package/bundle/onboarding-remote-control.js +140 -0
  160. package/bundle/onboarding-remote-probe.js +40 -0
  161. package/bundle/onboarding-repositories.js +88 -0
  162. package/bundle/onboarding-repository.js +49 -0
  163. package/bundle/onboarding-runtime-activation.js +83 -0
  164. package/bundle/onboarding-runtime-artifacts-client.js +87 -0
  165. package/bundle/onboarding-runtime-artifacts.js +126 -0
  166. package/bundle/onboarding-runtime-extension.js +400 -0
  167. package/bundle/onboarding-runtime-inventory.js +88 -0
  168. package/bundle/onboarding-runtime-program.js +42 -0
  169. package/bundle/onboarding-runtime-reclaim-client.js +94 -0
  170. package/bundle/onboarding-runtime-reclaim-worker.js +63 -0
  171. package/bundle/onboarding-runtime-reclaim.js +132 -0
  172. package/bundle/onboarding-runtime-repair-client.js +50 -0
  173. package/bundle/onboarding-runtime-repair.js +88 -0
  174. package/bundle/onboarding-runtime-stop.js +90 -0
  175. package/bundle/onboarding-runtime-uninstall-client.js +88 -0
  176. package/bundle/onboarding-runtime-uninstall.js +167 -0
  177. package/bundle/onboarding-runtime-version-client.js +138 -0
  178. package/bundle/onboarding-runtime-version.js +145 -0
  179. package/bundle/onboarding-schema.js +42 -0
  180. package/bundle/onboarding-self-disable.js +3 -0
  181. package/bundle/onboarding-self-lifecycle.js +95 -0
  182. package/bundle/onboarding-self-maintenance.js +52 -0
  183. package/bundle/onboarding-self-remove.js +3 -0
  184. package/bundle/onboarding-self-stop.js +85 -0
  185. package/bundle/onboarding-ssh-forward.js +48 -0
  186. package/bundle/onboarding-ssh.js +105 -0
  187. package/bundle/onboarding-state.js +95 -0
  188. package/bundle/onboarding-task-runtime-contract.js +38 -0
  189. package/bundle/onboarding-task-runtime-native.js +80 -0
  190. package/bundle/onboarding-task-runtime.js +66 -0
  191. package/bundle/onboarding-token-plan.js +52 -0
  192. package/bundle/onboarding-version-activation-client.js +48 -0
  193. package/bundle/onboarding-version-candidate.js +96 -0
  194. package/bundle/onboarding-version-repair.js +128 -0
  195. package/bundle/package-lock.json +773 -0
  196. package/bundle/package.json +99 -0
  197. package/bundle/peer-file-fs.js +62 -0
  198. package/bundle/peer-file-migration.js +59 -0
  199. package/bundle/peer-file-review.js +107 -0
  200. package/bundle/peer-files.js +157 -0
  201. package/bundle/peer-mailbox.js +75 -0
  202. package/bundle/protocol.js +17 -0
  203. package/bundle/recovery.js +40 -0
  204. package/bundle/repository-catalog.js +85 -0
  205. package/bundle/repository-gitee.js +76 -0
  206. package/bundle/repository-managed.js +46 -0
  207. package/bundle/repository-writer.js +43 -0
  208. package/bundle/rules/AGENTS.md +22 -0
  209. package/bundle/runtime-im-lock.json +11577 -0
  210. package/bundle/runtime-im-package.json +18 -0
  211. package/bundle/runtime-lock.json +10152 -0
  212. package/bundle/runtime-package.json +17 -0
  213. package/bundle/scheduler-migration.js +45 -0
  214. package/bundle/search-contract.js +19 -0
  215. package/bundle/skills/dsh-dual-end/SKILL.md +12 -0
  216. package/bundle/skills/task-a2a/SKILL.md +55 -0
  217. package/bundle/skills/task-a2a-worker/SKILL.md +23 -0
  218. package/bundle/skills/task-approval/SKILL.md +128 -0
  219. package/bundle/skills/task-artifacts/SKILL.md +46 -0
  220. package/bundle/skills/task-development/SKILL.md +144 -0
  221. package/bundle/skills/task-diagnostics/SKILL.md +41 -0
  222. package/bundle/skills/task-direct-link/SKILL.md +143 -0
  223. package/bundle/skills/task-file-transfer/SKILL.md +107 -0
  224. package/bundle/skills/task-handoff/SKILL.md +23 -0
  225. package/bundle/skills/task-intake/SKILL.md +13 -0
  226. package/bundle/skills/task-notify/SKILL.md +102 -0
  227. package/bundle/skills/task-onboarding/SKILL.md +708 -0
  228. package/bundle/skills/task-recovery/SKILL.md +54 -0
  229. package/bundle/skills/task-repository/SKILL.md +145 -0
  230. package/bundle/skills/task-research/SKILL.md +43 -0
  231. package/bundle/skills/task-schedule/SKILL.md +79 -0
  232. package/bundle/skills/task-sidebar/SKILL.md +122 -0
  233. package/bundle/skills/task-workbench/SKILL.md +30 -0
  234. package/bundle/skills/task-worker/SKILL.md +88 -0
  235. package/bundle/source-search.js +89 -0
  236. package/bundle/source-web.js +17 -0
  237. package/bundle/ssh-connector.js +24 -0
  238. package/bundle/store.js +102 -0
  239. package/bundle/task-a2a.js +298 -0
  240. package/bundle/task-artifacts.js +179 -0
  241. package/bundle/task-board-a2a.js +55 -0
  242. package/bundle/task-board-development.js +83 -0
  243. package/bundle/task-board-planning.js +84 -0
  244. package/bundle/task-board.js +132 -0
  245. package/bundle/task-branch.js +2 -0
  246. package/bundle/task-catalog.js +77 -0
  247. package/bundle/task-context.js +40 -0
  248. package/bundle/task-envelope.js +96 -0
  249. package/bundle/task-interventions.js +54 -0
  250. package/bundle/task-jobs.js +156 -0
  251. package/bundle/task-notifications.js +132 -0
  252. package/bundle/task-results.js +16 -0
  253. package/bundle/task-scheduler.js +77 -0
  254. package/bundle/task-sources.js +101 -0
  255. package/bundle/task-trigger-time.js +46 -0
  256. package/bundle/task-triggers.js +157 -0
  257. package/bundle/task-worker.js +73 -0
  258. package/bundle/task-workflows.js +117 -0
  259. package/bundle/tools.js +13 -0
  260. package/bundle/workbench-assets/asset-provenance.json +26 -0
  261. package/bundle/workbench-assets/whale-ui-states.png +0 -0
  262. package/bundle/workbench-client.js +811 -0
  263. package/bundle/workbench-decisions.js +48 -0
  264. package/bundle/workbench-host.js +122 -0
  265. package/bundle/workbench-im-identity.js +51 -0
  266. package/bundle/workbench-proxy.js +127 -0
  267. package/bundle/worker-rules/AGENTS.md +84 -0
  268. package/bundle/worker-tools.js +13 -0
  269. package/compatibility.json +980 -0
  270. package/cordis.patch.yml +3 -0
  271. package/package.json +57 -4
@@ -0,0 +1,23 @@
1
+ // Pure private index-v2 compiler. No filesystem or Git invocation.
2
+ import {createHash} from 'node:crypto';
3
+ import {verifyObjects,indexTree} from './delivery-object-plan.js';
4
+ export function compileIndex(plan,objects){
5
+ verifyObjects(plan,objects);const byId=new Map(objects.map(o=>[o.oid,o])),entries=[],oidBytes=plan.format==='sha1'?20:32;
6
+ const walk=(id,prefix='')=>{
7
+ const raw=byId.get(id).data;let at=0;
8
+ while(at<raw.length){
9
+ const nul=raw.indexOf(0,at),header=raw.subarray(at,nul).toString('utf8'),space=header.indexOf(' '),mode=header.slice(0,space),name=header.slice(space+1),oid=raw.subarray(nul+1,nul+1+oidBytes).toString('hex');at=nul+1+oidBytes;
10
+ if(mode==='40000')walk(oid,prefix+name+'/');else entries.push({path:prefix+name,mode:mode==='100755'?0o755:0o644,oid});
11
+ }
12
+ };walk(plan.tree_oid);entries.sort((a,b)=>Buffer.compare(Buffer.from(a.path),Buffer.from(b.path)));
13
+ if(indexTree(entries,plan.format)!==plan.tree_oid)throw Error('DELIVERY_INDEX_TREE_MISMATCH');
14
+ const header=Buffer.alloc(12);header.write('DIRC');header.writeUInt32BE(2,4);header.writeUInt32BE(entries.length,8);
15
+ const chunks=[header];for(const e of entries){
16
+ const name=Buffer.from(e.path),prefix=40+oidBytes+2,raw=Buffer.alloc(Math.ceil((prefix+name.length+1)/8)*8);
17
+ // Zero stat cache deliberately forces Git to recheck filesystem content; no assume-valid flag.
18
+ raw.writeUInt32BE(e.mode===0o755?0o100755:0o100644,24);Buffer.from(e.oid,'hex').copy(raw,40);
19
+ raw.writeUInt16BE(Math.min(name.length,0xfff),40+oidBytes);name.copy(raw,prefix);chunks.push(raw);
20
+ }
21
+ const body=Buffer.concat(chunks),checksum=createHash(plan.format).update(body).digest();
22
+ return {bytes:Buffer.concat([body,checksum]),entries,tree_oid:plan.tree_oid,format:plan.format};
23
+ }
@@ -0,0 +1,207 @@
1
+ // Internal, disabled-by-default commit journal. It never calls Git or executes an effect.
2
+ // Only the opt-in cloud runtime constructs this class; tools never supply adapters.
3
+ import {deliveryWaiting} from './delivery-state.js';
4
+ import {randomUUID} from 'node:crypto';
5
+ import {canonical,digest} from './approval-ledger.js';
6
+ import {verifyObjects} from './delivery-object-plan.js';
7
+ import {repositoryURL} from './repository-gitee.js';
8
+ import {validateGitBaseline} from './delivery-git-read.js';
9
+ import {pushIntent,validatePushIntent,validatePushReadiness,pushReadback} from './delivery-push-plan.js';
10
+ const fail=code=>{throw Error('DELIVERY_'+code);};
11
+ const denied=()=>fail('ADAPTER_REQUIRED');
12
+ const id=x=>typeof x==='string'&&x.length>0&&x.length<=256&&!/[\x00-\x1f\x7f]/.test(x);
13
+ const sync=x=>{if(x&&typeof x.then==='function')fail('ASYNC_ADAPTER_DENIED');return x;};
14
+ const table=(db,name)=>!!db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name=?").get(name);
15
+ function workspace(v,plan,resource){
16
+ if(!v||Object.keys(v).sort().join(',')!=='base_sha,branch,directory,git_directory,root,url'||
17
+ typeof v.root!=='string'||!v.root.startsWith('/')||v.root.length>2048||/[\x00-\x1f\x7f]/.test(v.root)||
18
+ v.url!==resource||v.branch!==plan.branch||v.base_sha!==plan.parent)fail('WORKSPACE_BINDING');
19
+ for(const k of ['directory','git_directory'])if(!v[k]||Object.keys(v[k]).sort().join(',')!=='device,inode'||
20
+ !/^[0-9]{1,30}$/.test(v[k].device)||!/^[0-9]{1,30}$/.test(v[k].inode))fail('WORKSPACE_BINDING');
21
+ return structuredClone(v);
22
+ }
23
+ export class DeliveryJournal {
24
+ constructor({store,enabled=false,pushEnabled=false,authorize=denied,preflight=denied,observe=denied,observeUnapplied=denied,exclusive=()=>false,now=Date.now}){
25
+ Object.assign(this,{store,db:store.db,enabled,pushEnabled,authorize,preflight,observe,observeUnapplied,exclusive,now});
26
+ this.db.exec(`CREATE TABLE IF NOT EXISTS delivery_actions(
27
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,id TEXT UNIQUE NOT NULL,event_id TEXT UNIQUE NOT NULL,fingerprint TEXT NOT NULL,
28
+ task_id TEXT NOT NULL,approval_id TEXT NOT NULL,authority_hash TEXT NOT NULL,resource TEXT NOT NULL,intent TEXT NOT NULL,
29
+ development_cutoff INTEGER NOT NULL,state TEXT NOT NULL,epoch INTEGER,dispatched INTEGER NOT NULL DEFAULT 0,
30
+ created INTEGER NOT NULL,error TEXT,result TEXT);
31
+ CREATE UNIQUE INDEX IF NOT EXISTS delivery_resource_owner ON delivery_actions(resource) WHERE state IN ('active','needs_review');
32
+ CREATE UNIQUE INDEX IF NOT EXISTS delivery_approval_once ON delivery_actions(approval_id);
33
+ CREATE TABLE IF NOT EXISTS delivery_events(seq INTEGER PRIMARY KEY AUTOINCREMENT,action_id TEXT NOT NULL,type TEXT NOT NULL,data TEXT NOT NULL,created INTEGER NOT NULL);`);
34
+ this.db.exec(`CREATE TABLE IF NOT EXISTS delivery_operations(id TEXT PRIMARY KEY,action_id TEXT NOT NULL,epoch INTEGER NOT NULL,
35
+ kind TEXT NOT NULL,detail TEXT NOT NULL,state TEXT NOT NULL,pid INTEGER,started INTEGER NOT NULL,closed INTEGER,code INTEGER,signal TEXT);`);
36
+ if(!this.db.prepare('PRAGMA table_info(delivery_actions)').all().some(x=>x.name==='before_snapshot'))this.db.exec('ALTER TABLE delivery_actions ADD COLUMN before_snapshot TEXT');
37
+ }
38
+ enabledCheck(){if(this.enabled!==true)fail('DISABLED');}
39
+ owner(){this.enabledCheck();if(sync(this.exclusive())!==true)fail('EXCLUSIVE_OWNER_REQUIRED');}
40
+ row(id){const r=this.db.prepare('SELECT * FROM delivery_actions WHERE id=?').get(id);if(!r)fail('NOT_FOUND');return r;}
41
+ intent(r){
42
+ const value=JSON.parse(r.intent),{fingerprint,...body}=value,plan=value.plan;
43
+ const {fingerprint:planFingerprint,...planBody}=plan??{};
44
+ if(value.kind==='push-execution-intent-v1'){
45
+ validatePushIntent(value);if(value.task_id!==r.task_id||value.resource!==r.resource||digest({event_id:r.event_id,approval_id:r.approval_id,intent:value})!==r.fingerprint)fail('INTENT_CHANGED');return value;
46
+ }
47
+ if(digest(body)!==fingerprint||digest(planBody)!==planFingerprint||value.kind!=='commit-execution-intent-v1'||
48
+ value.task_id!==r.task_id||value.resource!==r.resource||plan.kind!=='commit-objects-v1'||plan.persisted!==false||plan.grants_execution!==false||
49
+ digest({event_id:r.event_id,approval_id:r.approval_id,intent:value})!==r.fingerprint)fail('INTENT_CHANGED');
50
+ return value;
51
+ }
52
+ event(id,type,data={}){this.db.prepare('INSERT INTO delivery_events(action_id,type,data,created) VALUES (?,?,?,?)').run(id,type,canonical(data),this.now());}
53
+ prepare({task_id,resource,workspace_identity,plan,objects}){
54
+ if(plan?.kind==='push-commit-v1'){if(this.pushEnabled!==true)fail('PUSH_DISABLED');return pushIntent(this.store,{task_id,resource,workspace_identity,plan});}
55
+ verifyObjects(plan,objects);if(repositoryURL(resource).url!==resource)fail('RESOURCE');
56
+ const task=this.store.task(task_id),identity=workspace(workspace_identity,plan,resource);
57
+ const intent={schema:1,kind:'commit-execution-intent-v1',task_id,task_revision:task.revision,resource,workspace_identity:identity,plan:structuredClone(plan)};
58
+ return {...intent,fingerprint:digest(intent)};
59
+ }
60
+ authority(approval_id,intent){
61
+ this.enabledCheck();const scope=intent.kind==='push-execution-intent-v1'?'push':'commit';
62
+ if(scope==='push'){
63
+ if(this.pushEnabled!==true)fail('PUSH_DISABLED');
64
+ if(canonical(pushIntent(this.store,{task_id:intent.task_id,resource:intent.resource,workspace_identity:intent.workspace_identity,plan:intent.plan}))!==canonical(intent))fail('SOURCE_CHANGED');
65
+ }const task=this.store.task(intent.task_id);
66
+ if(task.revision!==intent.task_revision)fail('TASK_REVISION_CHANGED');
67
+ const a=sync(this.authorize({approval_id,intent:structuredClone(intent)}));
68
+ // An old commit-preview-v1 or model-supplied "approved" flag never satisfies this contract.
69
+ if(!a||a.kind!=='delivery-execution-v1'||a.scope!==scope||a.execution!==true||a.approval_id!==approval_id||
70
+ a.task_id!==intent.task_id||a.task_revision!==intent.task_revision||a.intent_fingerprint!==intent.fingerprint||
71
+ !/^[a-f0-9]{64}$/.test(a.authority_hash??''))fail('EXECUTION_APPROVAL_REQUIRED');
72
+ return a.authority_hash;
73
+ }
74
+ readiness(intent){
75
+ const r=sync(this.preflight(structuredClone(intent)));
76
+ if(intent.kind==='push-execution-intent-v1')return validatePushReadiness(intent,r,this.now());
77
+ if(!r||r.intent_fingerprint!==intent.fingerprint||r.drained!==true||r.manifest_sha256!==intent.plan.manifest_sha256||
78
+ canonical(r.workspace_identity)!==canonical(intent.workspace_identity)||r.branch!==intent.plan.branch||r.parent!==intent.plan.parent)fail('PREFLIGHT_REQUIRED');
79
+ return validateGitBaseline(intent,r.baseline);
80
+ }
81
+ enqueue(input){
82
+ this.enabledCheck();if(!id(input.event_id)||!id(input.approval_id))fail('INVALID_REQUEST');
83
+ return this.store.tx(()=>{
84
+ const intent=this.prepare(input),fp=digest({event_id:input.event_id,approval_id:input.approval_id,intent});
85
+ const old=this.db.prepare('SELECT * FROM delivery_actions WHERE event_id=?').get(input.event_id);
86
+ if(old){if(old.fingerprint!==fp)fail('EVENT_CONFLICT');return this.view(old.id);}
87
+ if(this.db.prepare('SELECT 1 FROM delivery_actions WHERE approval_id=?').get(input.approval_id))fail('APPROVAL_ALREADY_USED');
88
+ const authority=this.authority(input.approval_id,intent);
89
+ const cutoff=table(this.db,'development_requests')?this.db.prepare('SELECT COALESCE(MAX(seq),0) n FROM development_requests').get().n:0;
90
+ const action='delivery-'+randomUUID();
91
+ this.db.prepare(`INSERT INTO delivery_actions(id,event_id,fingerprint,task_id,approval_id,authority_hash,resource,intent,development_cutoff,state,created)
92
+ VALUES (?,?,?,?,?,?,?,?,?,'queued',?)`).run(action,input.event_id,fp,intent.task_id,input.approval_id,authority,intent.resource,canonical(intent),cutoff,this.now());
93
+ this.event(action,'queued');return this.view(action);
94
+ });
95
+ }
96
+ view(id){const r=this.row(id);return {id:r.id,task_id:r.task_id,state:r.state,epoch:r.epoch,dispatched:r.dispatched===1,error:r.error,
97
+ computed_commit_oid:this.intent(r).plan.computed_commit_oid??null,result:r.result?JSON.parse(r.result):null,
98
+ ...(this.intent(r).kind==='push-execution-intent-v1'?{kind:'push',source_commit_oid:this.intent(r).plan.commit_oid}: {})};}
99
+ waiting(id){const r=this.row(id);return deliveryWaiting(this.db,r,this.store.task(r.task_id));}
100
+ acquire(id){return this.store.tx(()=>{
101
+ this.owner();const r=this.row(id);if(r.state!=='queued')fail('NOT_QUEUED');
102
+ const intent=this.intent(r);if(this.authority(r.approval_id,intent)!==r.authority_hash)fail('APPROVAL_CHANGED');
103
+ const reason=this.waiting(id);if(reason)return {acquired:false,reason};const baseline=this.readiness(intent);
104
+ const epoch=this.store.task(r.task_id).epoch+1;
105
+ this.db.prepare("UPDATE tasks SET owner='cloud',epoch=?,busy=1 WHERE id=?").run(epoch,r.task_id);
106
+ this.db.prepare("UPDATE delivery_actions SET state='active',epoch=?,before_snapshot=? WHERE id=?").run(epoch,canonical(baseline),id);
107
+ this.event(id,'acquired',{epoch});return {acquired:true,...this.view(id)};
108
+ });}
109
+ fence(id,epoch,states=['active']){
110
+ this.owner();const r=this.row(id);if(!states.includes(r.state)||r.epoch!==epoch)fail('STALE_FENCE');
111
+ const t=this.store.fence('cloud',r.task_id,epoch);if(!t.busy)fail('NOT_BUSY');return r;
112
+ }
113
+ markDispatched(id,epoch){return this.store.tx(()=>{
114
+ const r=this.fence(id,epoch);if(r.dispatched)fail('ALREADY_DISPATCHED');const intent=this.intent(r);
115
+ if(this.unfinished(id))fail('DRAIN_REQUIRED');
116
+ if(this.authority(r.approval_id,intent)!==r.authority_hash)fail('APPROVAL_CHANGED');
117
+ if(!r.before_snapshot||canonical(this.readiness(intent))!==r.before_snapshot)fail('BEFORE_SNAPSHOT_CHANGED');
118
+ // Must commit this record BEFORE a future trusted adapter is allowed to touch Git.
119
+ this.db.prepare('UPDATE delivery_actions SET dispatched=1 WHERE id=?').run(id);this.event(id,'dispatched',{epoch});
120
+ return {id,epoch,intent:structuredClone(intent)};
121
+ });}
122
+ #review(id,error='EFFECT_UNKNOWN'){
123
+ const r=this.row(id);this.db.prepare("UPDATE delivery_actions SET state='needs_review',error=? WHERE id=?").run(error,id);
124
+ // Do not clear or steal the task fence, and do not reset a possibly live process.
125
+ this.event(id,'needs_review',{epoch:r.epoch,error});return this.view(id);
126
+ }
127
+ markUnknown(id,epoch){return this.store.tx(()=>{this.fence(id,epoch);return this.#review(id);});}
128
+ recordFailure(id,epoch){return this.store.tx(()=>{
129
+ this.owner();const r=this.row(id);if(r.epoch!==epoch||!['active','needs_review'].includes(r.state))fail('STALE_FENCE');
130
+ // Reporting the old action's uncertainty does not modify or reacquire a task fence.
131
+ return this.#review(id);
132
+ });}
133
+ unfinished(id){return !!this.db.prepare("SELECT 1 FROM delivery_operations WHERE action_id=? AND state<>'closed'").get(id);}
134
+ effectAuthority(id,epoch,{cleanup=false}={}){
135
+ const r=this.fence(id,epoch,cleanup?['active','needs_review']:['active']);if(!r.dispatched)fail('NOT_DISPATCHED');
136
+ const intent=this.intent(r);if(!cleanup&&this.authority(r.approval_id,intent)!==r.authority_hash)fail('APPROVAL_CHANGED');return intent;
137
+ }
138
+ startOperation(id,epoch,kind,detail={}){return this.store.tx(()=>{
139
+ const push=this.intent(this.row(id)).kind==='push-execution-intent-v1';
140
+ if(!(push?['push']:['lock','object','reference','index','unlock']).includes(kind))fail('OPERATION_KIND');
141
+ if(push&&this.db.prepare("SELECT 1 FROM delivery_operations WHERE action_id=? AND kind='push'").get(id))fail('PUSH_ALREADY_STARTED');
142
+ this.effectAuthority(id,epoch,{cleanup:kind==='unlock'});if(this.unfinished(id))fail('DRAIN_REQUIRED');
143
+ if(!detail||typeof detail!=='object'||Array.isArray(detail)||canonical(detail).length>2000)fail('OPERATION_DETAIL');
144
+ const op='delivery-op-'+randomUUID();this.db.prepare("INSERT INTO delivery_operations(id,action_id,epoch,kind,detail,state,started) VALUES (?,?,?,?,?,'intent',?)").run(op,id,epoch,kind,canonical(detail),this.now());
145
+ this.event(id,'operation_intent',{operation:op,epoch,kind});return op;
146
+ });}
147
+ operation(id){const r=this.db.prepare('SELECT * FROM delivery_operations WHERE id=?').get(id);if(!r)fail('OPERATION_NOT_FOUND');return r;}
148
+ spawned(op,pid){return this.store.tx(()=>{
149
+ const r=this.operation(op);if(r.state!=='intent'||r.pid!==null||!Number.isSafeInteger(pid)||pid<1)fail('OPERATION_SPAWN_INVALID');
150
+ this.db.prepare("UPDATE delivery_operations SET state='spawned',pid=? WHERE id=?").run(pid,op);this.event(r.action_id,'operation_spawned',{operation:op,pid});
151
+ });}
152
+ closed(op,{code=null,signal=null,evidence}={}){return this.store.tx(()=>{
153
+ if(code!==null&&!Number.isSafeInteger(code)||signal!==null&&(typeof signal!=='string'||!/^[A-Z0-9_-]{1,32}$/.test(signal)))fail('OPERATION_CLOSE_INVALID');
154
+ if(evidence!==undefined&&(!evidence||Object.keys(evidence).sort().join(',')!=='binding_hash,kind,receipt_sha256'||evidence.kind!=='sealed-process-receipt-v1'||
155
+ !/^[a-f0-9]{64}$/.test(evidence.binding_hash??'')||!/^[a-f0-9]{64}$/.test(evidence.receipt_sha256??'')))fail('OPERATION_CLOSE_INVALID');
156
+ const r=this.operation(op);if(r.state==='closed'){if(r.code!==code||r.signal!==signal)fail('OPERATION_CLOSE_CONFLICT');return;}
157
+ this.db.prepare("UPDATE delivery_operations SET state='closed',closed=?,code=?,signal=? WHERE id=?").run(this.now(),code,signal,op);
158
+ this.event(r.action_id,'operation_drained',{operation:op,code,signal,...(evidence?{evidence}: {})});
159
+ });}
160
+ finish(id,epoch){return this.store.tx(()=>{
161
+ this.owner();const prior=this.row(id);
162
+ if(prior.state==='completed'&&prior.epoch===epoch)return {...this.view(id),replayed:true};
163
+ const r=this.fence(id,epoch,['active','needs_review']);if(!r.dispatched)fail('NOT_DISPATCHED');
164
+ if(this.unfinished(id))return this.#review(id,'DRAIN_REQUIRED');
165
+ const intent=this.intent(r),p=intent.plan;let proof;
166
+ try{proof=sync(this.observe(structuredClone(intent)));}catch{return this.#review(id,'READBACK_UNKNOWN');}
167
+ if(intent.kind==='push-execution-intent-v1'){
168
+ let result;try{result=pushReadback(intent,proof,this.now());}catch{return this.#review(id,'READBACK_MISMATCH');}
169
+ this.db.prepare("UPDATE delivery_actions SET state='completed',error=NULL,result=? WHERE id=?").run(canonical(result),id);
170
+ this.db.prepare('UPDATE tasks SET busy=0 WHERE id=?').run(r.task_id);this.event(id,'readback_completed',{epoch,result});return this.view(id);
171
+ }
172
+ if(!proof||proof.kind!=='commit-readback-v1'||proof.intent_fingerprint!==intent.fingerprint||proof.drained!==true||
173
+ proof.object_exists!==true||proof.head_oid!==p.computed_commit_oid||proof.ref_oid!==p.computed_commit_oid||
174
+ proof.commit_oid!==p.computed_commit_oid||proof.tree_oid!==p.tree_oid||proof.index_tree_oid!==p.tree_oid||
175
+ proof.branch!==p.branch||proof.parent!==p.parent||proof.manifest_sha256!==p.manifest_sha256||
176
+ canonical(proof.workspace_identity)!==canonical(intent.workspace_identity))return this.#review(id,'READBACK_MISMATCH');
177
+ const result={kind:'commit-readback-v1',commit_oid:p.computed_commit_oid,tree_oid:p.tree_oid,branch:p.branch,manifest_sha256:p.manifest_sha256,
178
+ intent_fingerprint:intent.fingerprint,tested_content:structuredClone(p.tested_content),drained:true,remote_acceptance:'not_observed',runtime_adoption:'not_observed'};
179
+ this.db.prepare("UPDATE delivery_actions SET state='completed',error=NULL,result=? WHERE id=?").run(canonical(result),id);
180
+ this.db.prepare('UPDATE tasks SET busy=0 WHERE id=?').run(r.task_id);this.event(id,'readback_completed',{epoch,result});return this.view(id);
181
+ });}
182
+ settleUnapplied(id,epoch){return this.store.tx(()=>{
183
+ this.owner();const prior=this.row(id);if(prior.state==='not_applied'&&prior.epoch===epoch)return {...this.view(id),replayed:true};
184
+ const r=this.fence(id,epoch,['needs_review']),intent=this.intent(r);
185
+ // An unchanged ref cannot prove no push: objects may have arrived, or the ref may have moved back.
186
+ if(intent.kind==='push-execution-intent-v1')fail('PUSH_UNAPPLIED_NOT_PROVEN');
187
+ if(this.unfinished(id))return this.#review(id,'DRAIN_REQUIRED');
188
+ if(!r.before_snapshot)fail('BEFORE_SNAPSHOT_REQUIRED');const baseline=validateGitBaseline(intent,JSON.parse(r.before_snapshot));let proof;
189
+ try{proof=sync(this.observeUnapplied(structuredClone(intent),structuredClone(baseline)));}catch{return this.#review(id,'UNAPPLIED_READBACK_UNKNOWN');}
190
+ if(!proof||proof.kind!=='commit-not-applied-v1'||proof.intent_fingerprint!==intent.fingerprint||proof.baseline_fingerprint!==baseline.fingerprint||
191
+ proof.drained!==true||proof.unchanged!==true||proof.object_presence_unchanged!==true)return this.#review(id,'UNAPPLIED_READBACK_MISMATCH');
192
+ const result={kind:'commit-not-applied-v1',intent_fingerprint:intent.fingerprint,baseline_fingerprint:baseline.fingerprint,
193
+ drained:true,unchanged:true,object_presence_unchanged:true,retry_authorized:false};
194
+ this.db.prepare("UPDATE delivery_actions SET state='not_applied',error=NULL,result=? WHERE id=?").run(canonical(result),id);
195
+ this.db.prepare('UPDATE tasks SET busy=0 WHERE id=?').run(r.task_id);this.event(id,'not_applied_confirmed',{epoch,result});return this.view(id);
196
+ });}
197
+ cancelQueued(id,reason){return this.store.tx(()=>{
198
+ this.owner();if(!['user_cancelled','superseded','preflight_failed'].includes(reason))fail('INVALID_CANCEL');const r=this.row(id);
199
+ if(r.state!=='queued')fail('NOT_QUEUED');
200
+ this.db.prepare("UPDATE delivery_actions SET state='cancelled',error=? WHERE id=?").run(reason,id);this.event(id,'cancelled',{reason});return this.view(id);
201
+ });}
202
+ recover(){return this.store.tx(()=>{
203
+ this.owner();const rows=this.db.prepare("SELECT id FROM delivery_actions WHERE state='active' ORDER BY seq").all();
204
+ // No dispatch, retry, unlock or automatic "no effect" inference, even before dispatch.
205
+ for(const r of rows)this.#review(r.id,'HOST_RESTART_REVIEW');return {needs_review:rows.map(r=>r.id),retried:0};
206
+ });}
207
+ }
@@ -0,0 +1,138 @@
1
+ import {managedTaskBranch} from './task-branch.js';
2
+ // Pure Git object compiler. No filesystem, child process, network or repository writes.
3
+ // A computed OID is NOT evidence an object exists or a branch was committed.
4
+ import {createHash} from 'node:crypto';
5
+ import {developmentPath} from './development-plan.js';
6
+ import {digest,canonical} from './approval-ledger.js';
7
+ const fail=code=>{throw Error('DELIVERY_OBJECT_'+code);};
8
+ const formats=new Map([['sha1',40],['sha256',64]]);
9
+ const text=(s,n)=>typeof s==='string'&&s.length>0&&Buffer.byteLength(s)<=n;
10
+ const oid=(x,format)=>typeof x==='string'&&new RegExp('^[a-f0-9]{'+formats.get(format)+'}$').test(x);
11
+ export function gitObject(type,data,format='sha1'){
12
+ if(!formats.has(format)||!['blob','tree','commit'].includes(type)||!Buffer.isBuffer(data))fail('INVALID');
13
+ const bytes=Buffer.from(data),id=createHash(format).update(type+' '+bytes.length+'\0').update(bytes).digest('hex');
14
+ return {oid:id,type,data:bytes};
15
+ }
16
+ function files(input,format){
17
+ if(!Array.isArray(input)||input.length>4096)fail('LIMIT');const out=new Map(),names=new Map();let total=0;
18
+ for(const f of input){
19
+ if(!f||Object.keys(f).some(k=>!['path','mode','bytes'].includes(k))||![0o644,0o755].includes(f.mode)||!Buffer.isBuffer(f.bytes)||f.bytes.length>8388608)fail('FILE_INVALID');
20
+ developmentPath(f.path);if(Buffer.from(f.path).toString('utf8')!==f.path)fail('PATH_CONFLICT');if(out.has(f.path))fail('PATH_CONFLICT');
21
+ const parts=f.path.split('/');for(let i=1;i<=parts.length;i++){
22
+ const path=parts.slice(0,i).join('/'),key=path.normalize('NFC').toLowerCase();
23
+ if(names.has(key)&&names.get(key)!==path)fail('PATH_CONFLICT');names.set(key,path);
24
+ }
25
+ total+=f.bytes.length;if(total>33554432)fail('LIMIT');const b=gitObject('blob',f.bytes,format);
26
+ out.set(f.path,{path:f.path,mode:f.mode,blob:b,sha256:createHash('sha256').update(b.data).digest('hex')});
27
+ }
28
+ for(const path of out.keys())for(let i=path.indexOf('/');i!==-1;i=path.indexOf('/',i+1))if(out.has(path.slice(0,i)))fail('PATH_CONFLICT');
29
+ return out;
30
+ }
31
+ function treeOf(all,format,objects){
32
+ const root=new Map();
33
+ for(const f of [...all.values()].sort((a,b)=>Buffer.compare(Buffer.from(a.path),Buffer.from(b.path)))){
34
+ let at=root;const parts=f.path.split('/');for(const name of parts.slice(0,-1)){if(!at.has(name))at.set(name,new Map());at=at.get(name);}
35
+ at.set(parts.at(-1),f);objects.set(f.blob.oid,f.blob);
36
+ }
37
+ const visit=dir=>{
38
+ // Git compares a directory as name + '/', not as the bare directory name.
39
+ const entries=[...dir].map(([name,v])=>({name,dir:v instanceof Map,value:v})).sort((a,b)=>Buffer.compare(Buffer.from(a.name+(a.dir?'/':'')),Buffer.from(b.name+(b.dir?'/':''))));
40
+ const chunks=entries.map(e=>{
41
+ const obj=e.dir?visit(e.value):e.value.blob,mode=e.dir?'40000':e.value.mode===0o755?'100755':'100644';
42
+ return Buffer.concat([Buffer.from(mode+' '+e.name+'\0'),Buffer.from(obj.oid,'hex')]);
43
+ });
44
+ const result=gitObject('tree',Buffer.concat(chunks),format);objects.set(result.oid,result);return result;
45
+ };return visit(root);
46
+ }
47
+ // Compute a tree from index entries without creating objects or reading their bytes.
48
+ export function indexTree(entries,format='sha1'){
49
+ if(!formats.has(format)||!Array.isArray(entries))fail('INVALID');
50
+ const normalized=files(entries.map(e=>({path:e.path,mode:e.mode,bytes:Buffer.alloc(0)})),format);
51
+ for(const e of entries){if(!oid(e.oid,format))fail('INVALID');normalized.get(e.path).blob={oid:e.oid,type:'blob',data:Buffer.alloc(0)};}
52
+ return treeOf(normalized,format,new Map()).oid;
53
+ }
54
+ function identity(v){
55
+ if(!v||Object.keys(v).some(k=>!['name','email'].includes(k))||!text(v.name,256)||v.name.trim()!==v.name||/[<>\x00-\x1f\x7f]/.test(v.name)||!text(v.email,254)||!/^[A-Za-z0-9._+\-]+@[A-Za-z0-9.-]+$/.test(v.email))fail('IDENTITY');
56
+ return {...v};
57
+ }
58
+ export function compileCommit(v){
59
+ if(!v||Object.keys(v).some(k=>!['format','parent','branch','baseline','files','changes','tested_content','author','committer','when','message'].includes(k)))fail('INVALID');
60
+ const format=v.format??'sha1';if(!formats.has(format)||!oid(v.parent,format)||!managedTaskBranch(v.branch))fail('REFERENCE');
61
+ if(!Number.isSafeInteger(v.when)||v.when<0||v.when>253402300799||!text(v.message,2000)||!v.message.trim()||/[\x00-\x09\x0b-\x1f\x7f]/.test(v.message))fail('METADATA');
62
+ const author=identity(v.author),committer=identity(v.committer),before=files(v.baseline,format),after=files(v.files,format);
63
+ // Large assets may pass through unchanged; new/modified blobs keep the 1 MiB cap.
64
+ for(const [path,f] of after)if(f.blob.data.length>1048576&&before.get(path)?.blob.oid!==f.blob.oid)fail('FILE_INVALID');
65
+ if(!Array.isArray(v.changes)||!v.changes.length||v.changes.length>128)fail('CHANGES');const allowed=new Map();
66
+ for(const f of v.changes){
67
+ if(!f||Object.keys(f).some(k=>!['path','action','before_sha256','after_sha256'].includes(k))||!['create','modify','delete'].includes(f.action))fail('CHANGES');developmentPath(f.path);
68
+ if([...allowed.keys()].some(p=>p.normalize('NFC').toLowerCase()===f.path.normalize('NFC').toLowerCase())||f.before_sha256!==(before.get(f.path)?.sha256??null)||f.after_sha256!==(after.get(f.path)?.sha256??null))fail('CONTENT_MISMATCH');
69
+ if(f.action==='create'?(before.has(f.path)||!after.has(f.path)):f.action==='modify'?(!before.has(f.path)||!after.has(f.path)):(!before.has(f.path)||after.has(f.path)))fail('CHANGES');allowed.set(f.path,f);
70
+ }
71
+ for(const path of new Set([...before.keys(),...after.keys()])){
72
+ const a=before.get(path),b=after.get(path),f=allowed.get(path);
73
+ if(!f&&(a?.blob.oid!==b?.blob.oid||a?.mode!==b?.mode))fail('OUT_OF_SCOPE');
74
+ if(f&&Math.max(a?.blob.data.length??0,b?.blob.data.length??0)>1048576)fail('CHANGED_FILE_LIMIT');
75
+ if(f&&b&&b.mode!==(a?.mode??0o644))fail('MODE_CHANGED');
76
+ }
77
+ if(![...allowed.values()].some(x=>x.before_sha256!==x.after_sha256))fail('NO_CHANGES');
78
+ const manifest=Object.fromEntries([...after.keys()].sort().map(p=>[p,{sha256:after.get(p).sha256,mode:after.get(p).mode}])),content=digest(manifest);
79
+ const tested=v.tested_content;
80
+ if(!tested||Object.keys(tested).some(k=>!['kind','sha256'].includes(k))||
81
+ (tested.kind==='workspace_manifest_sha256'?tested.sha256!==content:tested.kind==='file_sha256'?allowed.size!==1||[...allowed.values()][0].action!=='create'||tested.sha256!==[...allowed.values()][0].after_sha256:true))fail('TEST_CONTENT_MISMATCH');
82
+ const objects=new Map(),tree=treeOf(after,format,objects),line=p=>`${p.name} <${p.email}> ${v.when} +0000`,message=v.message.endsWith('\n')?v.message:v.message+'\n';
83
+ const commit=gitObject('commit',Buffer.from(`tree ${tree.oid}\nparent ${v.parent}\nauthor ${line(author)}\ncommitter ${line(committer)}\n\n${message}`),format);objects.set(commit.oid,commit);
84
+ const body={schema:1,kind:'commit-objects-v1',format,parent:v.parent,branch:v.branch,tree_oid:tree.oid,computed_commit_oid:commit.oid,manifest_sha256:content,tested_content:{...tested},author,committer,when:v.when,message,
85
+ changes:[...allowed.values()].map(x=>({...x})).sort((a,b)=>a.path<b.path?-1:a.path>b.path?1:0),objects:[...objects.values()].map(o=>({oid:o.oid,type:o.type,bytes:o.data.length})),persisted:false,grants_execution:false,remote_acceptance:'not_observed',runtime_adoption:'not_observed'};
86
+ return {plan:{...body,fingerprint:digest(body)},objects:[...objects.values()]};
87
+ }
88
+ export function verifyObjects(plan,objects){
89
+ const {fingerprint,...body}=plan??{};
90
+ if(!fingerprint||digest(body)!==fingerprint||plan.schema!==1||plan.kind!=='commit-objects-v1'||
91
+ plan.persisted!==false||plan.grants_execution!==false||plan.remote_acceptance!=='not_observed'||plan.runtime_adoption!=='not_observed'||
92
+ !Array.isArray(plan.objects)||!Array.isArray(objects)||objects.length!==plan.objects.length||!objects.length||objects.length>65536)fail('PLAN_CHANGED');
93
+ if(!formats.has(plan.format)||!oid(plan.parent,plan.format)||!managedTaskBranch(plan.branch))fail('PLAN_CHANGED');
94
+ identity(plan.author);identity(plan.committer);
95
+ if(!Number.isSafeInteger(plan.when)||plan.when<0||plan.when>253402300799||!text(plan.message,2001)||
96
+ !plan.message.trim()||!plan.message.endsWith('\n')||/[\x00-\x09\x0b-\x1f\x7f]/.test(plan.message))fail('PLAN_CHANGED');
97
+ const byId=new Map(),used=new Set();let size=0;
98
+ for(let i=0;i<objects.length;i++){
99
+ const o=objects[i],expected=plan.objects[i],fresh=gitObject(o.type,o.data,plan.format);
100
+ if(o.oid!==fresh.oid||byId.has(o.oid)||canonical(expected)!==canonical({oid:fresh.oid,type:fresh.type,bytes:fresh.data.length}))fail('PLAN_CHANGED');
101
+ byId.set(o.oid,fresh);size+=fresh.data.length;if(size>40000000)fail('LIMIT');
102
+ }
103
+ const get=(id,type)=>{const o=byId.get(id);if(!o||o.type!==type)fail('PLAN_CHANGED');used.add(id);return o;};
104
+ const line=p=>`${p.name} <${p.email}> ${plan.when} +0000`;
105
+ const expected=Buffer.from(`tree ${plan.tree_oid}\nparent ${plan.parent}\nauthor ${line(plan.author)}\ncommitter ${line(plan.committer)}\n\n${plan.message}`);
106
+ if(!get(plan.computed_commit_oid,'commit').data.equals(expected))fail('PLAN_CHANGED');
107
+ let walked=0;const decoded=[],stack=new Set(),rawLength=formats.get(plan.format)/2;
108
+ const walk=(id,prefix)=>{
109
+ if(++walked>65536||stack.has(id)||prefix.length>512)fail('PLAN_CHANGED');stack.add(id);
110
+ const data=get(id,'tree').data;let at=0,last=null;
111
+ while(at<data.length){
112
+ const end=data.indexOf(0,at);if(end<0||end+1+rawLength>data.length)fail('PLAN_CHANGED');
113
+ const header=data.subarray(at,end),s=header.toString('utf8');
114
+ if(!Buffer.from(s).equals(header))fail('PLAN_CHANGED');const m=/^(40000|100644|100755) (.+)$/u.exec(s);if(!m||m[2].includes('/'))fail('PLAN_CHANGED');
115
+ const path=prefix+m[2];developmentPath(path);const dir=m[1]==='40000',sort=Buffer.from(m[2]+(dir?'/':''));
116
+ if(last&&Buffer.compare(last,sort)>=0)fail('PLAN_CHANGED');last=sort;
117
+ const child=data.subarray(end+1,end+1+rawLength).toString('hex');at=end+1+rawLength;
118
+ if(dir)walk(child,path+'/');else decoded.push({path,mode:m[1]==='100755'?0o755:0o644,bytes:get(child,'blob').data});
119
+ if(decoded.length>4096)fail('LIMIT');
120
+ }stack.delete(id);
121
+ };walk(plan.tree_oid,'');
122
+ const checked=files(decoded,plan.format),manifest=Object.fromEntries([...checked.keys()].sort().map(p=>[p,{sha256:checked.get(p).sha256,mode:checked.get(p).mode}]));
123
+ // Rebuild to reject empty/unreachable directories and noncanonical object graphs.
124
+ const rebuilt=treeOf(checked,plan.format,new Map());
125
+ if(rebuilt.oid!==plan.tree_oid||used.size!==objects.length||digest(manifest)!==plan.manifest_sha256)fail('PLAN_CHANGED');
126
+ if(!Array.isArray(plan.changes)||!plan.changes.length||plan.changes.length>128)fail('PLAN_CHANGED');
127
+ const paths=new Set();for(const change of plan.changes){
128
+ if((checked.get(change.path)?.blob.data.length??0)>1048576)fail('PLAN_CHANGED');
129
+ developmentPath(change.path);const key=change.path.normalize('NFC').toLowerCase();
130
+ if(paths.has(key)||!['create','modify','delete'].includes(change.action)||change.after_sha256!==(checked.get(change.path)?.sha256??null)||
131
+ (change.action==='create'?change.before_sha256!==null:!oid(change.before_sha256,'sha256'))||
132
+ (change.action==='delete'?checked.has(change.path):!checked.has(change.path)))fail('PLAN_CHANGED');paths.add(key);
133
+ }
134
+ const tested=plan.tested_content;
135
+ if(!tested||(tested.kind==='workspace_manifest_sha256'?tested.sha256!==plan.manifest_sha256:
136
+ tested.kind==='file_sha256'?plan.changes.length!==1||plan.changes[0].action!=='create'||tested.sha256!==plan.changes[0].after_sha256:true))fail('PLAN_CHANGED');
137
+ return {verified:true,persisted:false,grants_execution:false};
138
+ }
@@ -0,0 +1,153 @@
1
+ import {deliveryActions} from './delivery-state.js';
2
+ import {randomUUID} from 'node:crypto';
3
+ import {readFileSync,openSync,closeSync,fstatSync,realpathSync,constants} from 'node:fs';
4
+ import {join} from 'node:path';
5
+ import {canonical,digest} from './approval-ledger.js';
6
+ import {developmentSpec} from './development-contract.js';
7
+ import {DevelopmentFiles} from './development-files.js';
8
+ import {DevelopmentWorkspace,contentHash} from './development-workspace.js';
9
+
10
+ const has=(db,t)=>!!db?.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name=?").get(t);
11
+ const actions=Object.freeze({commit:false,push:false,publish:false,deploy:false});
12
+ const fail=code=>{throw Error('DELIVERY_'+code);};
13
+ const decode=bytes=>{if(bytes===null)return '';if(bytes.includes(0))return null;try{return new TextDecoder('utf-8',{fatal:true}).decode(bytes);}catch{return null;}};
14
+ function currentBytes(root,path,sha){
15
+ if(sha===null)return null;
16
+ const name=join(root,path);if(realpathSync(name)!==name)fail('FILE_CONFLICT');
17
+ const fd=openSync(name,constants.O_RDONLY|constants.O_NOFOLLOW|constants.O_NONBLOCK);
18
+ try{const s=fstatSync(fd);if(!s.isFile()||s.nlink!==1||s.size>1048576)fail('FILE_CONFLICT');const b=readFileSync(fd);if(contentHash(b)!==sha)fail('FILE_CONFLICT');return b;}finally{closeSync(fd);}
19
+ }
20
+ // A bounded comparison for review, NOT a patch, shell input, or proof the user read it.
21
+ export function compareText(before,after){
22
+ const a=decode(before),b=decode(after);
23
+ if(a===null||b===null)return {format:'binary_or_invalid_utf8',truncated:true,executable_patch:false};
24
+ const al=a.split('\n'),bl=b.split('\n');let prefix=0,suffix=0;
25
+ while(prefix<al.length&&prefix<bl.length&&al[prefix]===bl[prefix])prefix++;
26
+ while(suffix<al.length-prefix&&suffix<bl.length-prefix&&al[al.length-1-suffix]===bl[bl.length-1-suffix])suffix++;
27
+ const clip=ls=>{const s=ls.slice(0,40).join('\n');return {text:s.slice(0,2048),truncated:ls.length>40||s.length>2048};};
28
+ const old=clip(al.slice(prefix,al.length-suffix)),next=clip(bl.slice(prefix,bl.length-suffix));
29
+ return {format:'single_changed_span',before_ends_newline:a.endsWith('\n'),after_ends_newline:b.endsWith('\n'),before_changed_lines:al.length-prefix-suffix,after_changed_lines:bl.length-prefix-suffix,unchanged_prefix_lines:prefix,unchanged_suffix_lines:suffix,before:old.text,after:next.text,truncated:old.truncated||next.truncated,executable_patch:false};
30
+ }
31
+
32
+ // Rendering reads only persisted metadata. It never inspects Git, migrates task
33
+ // rows, renews approvals, checks remote access, or gives a filesystem freshness claim.
34
+ export function deliverySnapshot(g,task,revision){
35
+ const db=g.store?.db,execution=deliveryActions(g,task);
36
+ if(!has(db,'delivery_previews'))return {available:false,read_only:true,latest:null,execution,grants_execution:false};
37
+ const row=db.prepare('SELECT snapshot FROM delivery_previews WHERE task_id=? ORDER BY rowid DESC LIMIT 1').get(task);
38
+ const snapshot=row?JSON.parse(row.snapshot):null;
39
+ return {available:true,read_only:true,latest:snapshot,execution,revision_matches:snapshot?snapshot.spec_revision===revision:null,filesystem_checked_now:false,remote_checked_now:false,grants_execution:false};
40
+ }
41
+
42
+ export class DeliveryPreview {
43
+ constructor(g){
44
+ this.g=g;this.db=g.store.db;
45
+ this.db.exec(`CREATE TABLE IF NOT EXISTS delivery_previews(id TEXT PRIMARY KEY,event_id TEXT UNIQUE NOT NULL,event_fingerprint TEXT NOT NULL,task_id TEXT NOT NULL,request_id TEXT NOT NULL,snapshot TEXT NOT NULL,created INTEGER NOT NULL);`);
46
+ }
47
+ status(task){
48
+ this.g.store.task(task);
49
+ const h=this.db.prepare('SELECT spec_revision FROM task_catalog WHERE task_id=?').get(task);
50
+ return deliverySnapshot(this.g,task,h?.spec_revision??null);
51
+ }
52
+ stored(task,id,fingerprint){
53
+ if(typeof id!=='string'||typeof fingerprint!=='string'||!/^[a-f0-9]{64}$/.test(fingerprint))fail('INVALID_REFERENCE');
54
+ const row=this.db.prepare('SELECT task_id,snapshot FROM delivery_previews WHERE id=?').get(id);
55
+ if(!row||row.task_id!==task)fail('PREVIEW_NOT_FOUND');
56
+ const p=JSON.parse(row.snapshot),{fingerprint:hash,...body}=p;
57
+ if(hash!==fingerprint||digest(body)!==hash||p.task_id!==task||p.id!==id)fail('PREVIEW_FINGERPRINT_MISMATCH');
58
+ return p;
59
+ }
60
+ checked(p){
61
+ const checked=this.inspect(p.task_id,p.spec_revision,p.request_id);
62
+ if(checked.r.expected_hash!==p.tested_content.sha256||checked.a.proposal_hash!==p.source_approval.proposal_hash||checked.spec.branch!==p.workspace_branch||checked.w.b.base_sha!==p.baseline_commit||canonical(checked.a.proposal.repository)!==canonical(p.repository))fail('PREVIEW_CHANGED');
63
+ return checked;
64
+ }
65
+ page(a){
66
+ if(!a||Object.keys(a).some(k=>!['task_id','preview_id','fingerprint','path','side','offset','limit'].includes(k))||typeof a.task_id!=='string'||typeof a.path!=='string'||!['before','after'].includes(a.side)||!Number.isSafeInteger(a.offset)||a.offset<0||!Number.isSafeInteger(a.limit)||a.limit<1||a.limit>4096)fail('INVALID_PAGE');
67
+ const p=this.stored(a.task_id,a.preview_id,a.fingerprint),f=p.files.find(f=>f.path===a.path);
68
+ if(!f)fail('FILE_DENIED');
69
+ const {w}=this.checked(p),sha=f[a.side+'_sha256'];
70
+ const bytes=sha===null?null:a.side==='before'?Buffer.from(w.git(['show',p.baseline_commit+':'+f.path])):currentBytes(w.root,f.path,sha);
71
+ if((bytes===null?null:contentHash(bytes))!==sha)fail('FILE_CONFLICT');
72
+ this.checked(p);
73
+ const value=decode(bytes),base={schema:1,task_id:p.task_id,preview_id:p.id,fingerprint:p.fingerprint,path:f.path,side:a.side,sha256:sha,bytes:bytes?.length??null,read_only:true,grants_execution:false,checked_at:this.g.now(),cursor_unit:'unicode_codepoints',executable_patch:false};
74
+ if(value===null)return {...base,state:'binary_or_invalid_utf8',text:null,next_offset:null};
75
+ const points=Array.from(value);if(a.offset>points.length)fail('INVALID_PAGE');
76
+ const end=Math.min(a.offset+a.limit,points.length);
77
+ return {...base,state:bytes===null?'absent':'text',text:points.slice(a.offset,end).join(''),offset:a.offset,end_offset:end,total_codepoints:points.length,next_offset:end<points.length?end:null};
78
+ }
79
+ approvalSnapshot(task,revision,reference,repository,policy){
80
+ const p=this.stored(task,reference.preview_id,reference.fingerprint);
81
+ if(p.spec_revision!==revision||canonical(p.repository)!==canonical(repository))fail('APPROVAL_REFERENCE_MISMATCH');
82
+ const checked=this.checked(p);
83
+ if(canonical(checked.a.proposal.model_policy)!==canonical(policy))fail('APPROVAL_MODEL_MISMATCH');
84
+ if(!p.files.some(f=>f.changed))fail('CHANGES_REQUIRED');
85
+ // Bind an independently reviewable exact commit plan, not general commit scope.
86
+ // No commit exists or is executed here. Push/publish/deploy are separate future gates.
87
+ return {kind:'commit-preview-v1',preview_id:p.id,fingerprint:p.fingerprint,development_request_id:p.request_id,source_approval_hash:p.source_approval.proposal_hash,task_revision:p.spec_revision,repository_fingerprint:p.repository.fingerprint,workspace_branch:p.workspace_branch,baseline_commit:p.baseline_commit,tested_content_sha256:p.tested_content.sha256,tested_content_kind:p.tested_content.kind,files_digest:digest(p.files.map(f=>({path:f.path,action:f.approved_action,before:f.before_sha256,after:f.after_sha256}))),file_count:p.files.length,changed_files:p.files.filter(f=>f.changed).length,commit_message:reference.commit_message,execution:'disabled',push:false,publish:false,deploy:false};
88
+ }
89
+ matches(task,revision,plan){
90
+ // Pure ledger check for rendering/confirmation. No implicit filesystem refresh.
91
+ try{const p=this.stored(task,plan.preview_id,plan.fingerprint);return plan.kind==='commit-preview-v1'&&plan.task_revision===revision&&p.spec_revision===revision&&plan.development_request_id===p.request_id&&plan.source_approval_hash===p.source_approval.proposal_hash&&plan.repository_fingerprint===p.repository.fingerprint&&plan.workspace_branch===p.workspace_branch&&plan.baseline_commit===p.baseline_commit&&plan.tested_content_sha256===p.tested_content.sha256&&plan.files_digest===digest(p.files.map(f=>({path:f.path,action:f.approved_action,before:f.before_sha256,after:f.after_sha256})))&&plan.execution==='disabled'&&plan.push===false&&plan.publish===false&&plan.deploy===false;}catch{return false;}
92
+ }
93
+ inspect(task,revision,request){
94
+ const g=this.g,gate=g.development?.gate;
95
+ const bindings=gate?.bindings??g.c?.development?.bindings;
96
+ if(!bindings||!has(this.db,'development_requests'))fail('CAPABILITY_REQUIRED');
97
+ const h=this.db.prepare('SELECT * FROM task_catalog WHERE task_id=?').get(task);
98
+ if(!h||h.legacy||h.spec_revision!==revision)fail('TASK_REVISION_CONFLICT');
99
+ const t=g.store.task(task);if(t.busy||t.blocked)fail('TASK_BUSY');
100
+ g.assertTaskQuiescent(task);
101
+ let r;
102
+ if(request){r=this.db.prepare('SELECT * FROM development_requests WHERE id=?').get(request);if(!r)fail('REQUEST_NOT_FOUND');}
103
+ else{
104
+ const rows=this.db.prepare("SELECT r.* FROM development_requests r JOIN approval_requests a ON a.id=r.approval_id WHERE r.task_id=? AND a.spec_revision=? AND r.state='completed' ORDER BY r.seq DESC LIMIT 2").all(task,revision);
105
+ if(rows.length!==1)fail(rows.length?'REQUEST_AMBIGUOUS':'COMPLETED_REQUEST_REQUIRED');
106
+ r=rows[0];
107
+ }
108
+ if(r.task_id!==task||r.state!=='completed')fail('COMPLETED_REQUEST_REQUIRED');
109
+ if(this.db.prepare("SELECT 1 FROM development_requests WHERE resource=? AND state IN ('queued','active','needs_review')").get(r.resource))fail('RESOURCE_BUSY');
110
+ if(gate?.inflight.has(r.id)||this.db.prepare("SELECT 1 FROM development_operations WHERE request_id=? AND state<>'closed'").get(r.id)||this.db.prepare("SELECT 1 FROM development_writes WHERE request_id=? AND state<>'applied'").get(r.id))fail('DRAIN_REQUIRED');
111
+ // Completed development is historical evidence, not a fresh execution grant.
112
+ // Expired/superseded approval may be inspected without being revived.
113
+ const record=g.approvals.row(r.approval_id),a=g.approvals.view(r.approval_id),spec=developmentSpec(a.proposal.development),binding=bindings[task];
114
+ const authority=digest({approval:a.id,proposal_hash:a.proposal_hash,spec});
115
+ if(a.task_id!==task||a.spec_revision!==revision||digest({task_id:a.task_id,spec_revision:a.spec_revision,task_hash:record.task_hash,proposal:a.proposal,repository_revision:a.repository_revision,expires:a.expires})!==a.proposal_hash||canonical(a.proposal.scopes)!==canonical(['develop'])||r.authority_hash!==authority||binding?.approval_hash!==authority||canonical(JSON.parse(r.policy))!==canonical(a.proposal.model_policy))fail('SOURCE_EVIDENCE_MISMATCH');
116
+ if(!g.repositories.matches(task,a.repository_revision,a.proposal.repository))fail('REPOSITORY_BINDING_MISMATCH');
117
+ const w=new (spec.kind==='workspace-v1'?DevelopmentFiles:DevelopmentWorkspace)(binding,spec,a.proposal.repository);
118
+ if(!r.workspace_identity||r.workspace_identity!==canonical(w.identity()))fail('WORKSPACE_IDENTITY_MISMATCH');const state=w.check(r.expected_hash),test=JSON.parse(r.test_result??'null');
119
+ if(!r.expected_hash||!test?.passed||test.file_hash!==r.expected_hash)fail('TEST_EVIDENCE_REQUIRED');
120
+ const safe=this.db.prepare("SELECT data FROM development_events WHERE request_id=? AND type='safe_point' ORDER BY seq DESC LIMIT 1").get(r.id);
121
+ if(!safe||canonical(JSON.parse(safe.data))!==canonical({node:r.node,epoch:r.epoch,hash:r.expected_hash}))fail('HANDOFF_EVIDENCE_REQUIRED');
122
+ if(spec.kind==='workspace-v1'){
123
+ if(test.validator!=='approved-commands-v1'||test.commands?.length!==spec.commands.length)fail('TEST_EVIDENCE_REQUIRED');
124
+ for(const c of spec.commands){
125
+ const row=this.db.prepare('SELECT * FROM development_commands WHERE request_id=? AND command_id=? ORDER BY rowid DESC LIMIT 1').get(r.id,c.id),result=row?.result?JSON.parse(row.result):null;
126
+ const operation=row?this.db.prepare('SELECT request_id,state,exit_code FROM development_operations WHERE id=?').get(row.operation_id):null;
127
+ if(operation?.request_id!==r.id||operation.state!=='closed'||operation.exit_code!==0||row?.state!=='completed'||!result?.passed||!result.drained||result.file_hash!==r.expected_hash||result.command_hash!==digest(c)||canonical(test.commands.find(x=>x.command_id===c.id))!==canonical(result))fail('TEST_EVIDENCE_REQUIRED');
128
+ }
129
+ }else if(test.validator!=='task-summary-v1'||test.cases!==6)fail('TEST_EVIDENCE_REQUIRED');
130
+ return {r,a,spec,w,state,test,h};
131
+ }
132
+ create(node,a){
133
+ if(!['local','cloud'].includes(node)||!a||Object.keys(a).some(k=>!['task_id','expected_revision','request_id','event_id'].includes(k))||typeof a.task_id!=='string'||!Number.isSafeInteger(a.expected_revision)||a.expected_revision<1||typeof a.event_id!=='string'||!a.event_id||a.event_id.length>256||a.request_id!==undefined&&(typeof a.request_id!=='string'||!a.request_id))fail('INVALID_PREVIEW');
134
+ const fp=digest({node,...a}),old=this.db.prepare('SELECT * FROM delivery_previews WHERE event_id=?').get(a.event_id);
135
+ if(old){if(old.event_fingerprint!==fp)fail('EVENT_CONFLICT');return {snapshot:JSON.parse(old.snapshot),replayed:true,filesystem_checked_now:false,grants_execution:false};}
136
+ const {r,spec,w,state,a:approval,test,h}=this.inspect(a.task_id,a.expected_revision,a.request_id);
137
+ const planned=spec.kind==='workspace-v1'?spec.files:[{path:spec.file,action:'create',base_sha256:null}];
138
+ const files=planned.map(f=>{
139
+ const before=f.action==='create'?null:Buffer.from(w.git(['show',w.b.base_sha+':'+f.path]));
140
+ const sha=spec.kind==='workspace-v1'?state.manifest[f.path]?.sha256??null:state.hash;
141
+ const after=currentBytes(w.root,f.path,sha);
142
+ if((before?contentHash(before):null)!==f.base_sha256||(after?contentHash(after):null)!==sha)fail('FILE_CONFLICT');
143
+ return {path:f.path,approved_action:f.action,changed:f.base_sha256!==sha,before_sha256:f.base_sha256,after_sha256:sha,before_bytes:before?.length??null,after_bytes:after?.length??null,comparison:compareText(before,after)};
144
+ });
145
+ // Detect a concurrent edit while reading; the result remains a point-in-time
146
+ // snapshot, never a lease preventing edits after this check.
147
+ this.inspect(a.task_id,a.expected_revision,r.id);
148
+ const snapshot={schema:1,id:'delivery-'+randomUUID(),task_id:a.task_id,title:h.title,spec_revision:a.expected_revision,request_id:r.id,created:this.g.now(),repository:{...approval.proposal.repository},workspace_branch:spec.branch,baseline_commit:w.b.base_sha,tested_content:{kind:spec.kind==='workspace-v1'?'workspace_manifest_sha256':'file_sha256',sha256:r.expected_hash,test:{validator:test.validator,passed:true,required_commands:spec.commands?.map(c=>c.id)??null,cases:test.cases??null},bound_commit:null},files,source_approval:{id:approval.id,proposal_hash:approval.proposal_hash,observed_state:approval.state,scopes:approval.proposal.scopes,historical_evidence_only:true},delivery:{candidate_commit:null,commit:'not_created',remote_acceptance:'not_observed',runtime_adoption:'not_observed',enabled:actions},local_checked_at:this.g.now(),remote_checked_now:false,grants_execution:false};
149
+ snapshot.fingerprint=digest(snapshot);
150
+ this.db.prepare('INSERT INTO delivery_previews VALUES (?,?,?,?,?,?,?)').run(snapshot.id,a.event_id,fp,a.task_id,r.id,canonical(snapshot),snapshot.created);
151
+ return {snapshot,replayed:false,filesystem_checked_now:true,grants_execution:false};
152
+ }
153
+ }