@anusornneal/chat-relay 1.9.0 → 2.1.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 (54) hide show
  1. package/README.md +8 -0
  2. package/agent/activity-capture.mjs +218 -0
  3. package/agent/auto-session-binding.mjs +46 -0
  4. package/agent/capability-scheduler.mjs +82 -5
  5. package/agent/file-manager.mjs +33 -8
  6. package/agent/full-bridge.mjs +53 -0
  7. package/agent/full-desktop-actions.mjs +124 -0
  8. package/agent/full-desktop-auth.mjs +53 -0
  9. package/agent/full-desktop-broker.mjs +318 -0
  10. package/agent/full-host.mjs +153 -0
  11. package/agent/full-job-broker.mjs +360 -0
  12. package/agent/full-native-job.mjs +205 -0
  13. package/agent/full-presentation-changes.mjs +191 -0
  14. package/agent/full-remote-diagnostics.mjs +129 -0
  15. package/agent/full-resources.mjs +343 -0
  16. package/agent/full-runtime-supervisor.mjs +67 -0
  17. package/agent/full-session-dispatch.mjs +167 -0
  18. package/agent/full-workspace-broker.mjs +290 -0
  19. package/agent/git-worktree-manager.mjs +171 -4
  20. package/agent/lifecycle.mjs +11 -0
  21. package/agent/local-agent.mjs +177 -24
  22. package/agent/local-usage.mjs +21 -0
  23. package/agent/monitor-activity.mjs +135 -0
  24. package/agent/presentation-redaction.mjs +10 -0
  25. package/agent/process-manager.mjs +32 -0
  26. package/agent/terminal-manager.mjs +189 -31
  27. package/agent/toolcall-context.mjs +27 -1
  28. package/agent/toolcall-summary.mjs +1 -1
  29. package/agent/windows-desktop-runner.mjs +65 -61
  30. package/agent/windows-desktop-worker.ps1 +33 -18
  31. package/agent/windows-powershell.mjs +51 -0
  32. package/cli/full-background.mjs +69 -0
  33. package/cli/full-launch.mjs +76 -0
  34. package/cli/full-prepare-child.mjs +48 -0
  35. package/cli/full-prepare.mjs +171 -0
  36. package/cli/full-release-default.json +4 -0
  37. package/cli/full-release-files.mjs +36 -0
  38. package/cli/full-release-official.mjs +48 -0
  39. package/cli/full-release-source.mjs +37 -0
  40. package/cli/index.mjs +9 -5
  41. package/cli/mod-cache.mjs +170 -0
  42. package/cli/mod-loader.mjs +67 -0
  43. package/cli/mod-manifest.mjs +63 -0
  44. package/cli/remote.mjs +173 -18
  45. package/cli/runner-ownership.mjs +116 -3
  46. package/cli/self-update.mjs +1 -1
  47. package/cli/tui.mjs +2 -20
  48. package/package.json +5 -3
  49. package/packages/full-contracts/auto-session.mjs +14 -0
  50. package/packages/full-contracts/index.mjs +193 -0
  51. package/packages/full-contracts/monitor-metadata.mjs +28 -0
  52. package/packages/full-contracts/native-job.mjs +13 -0
  53. package/packages/full-contracts/package.json +7 -0
  54. package/packages/full-contracts/remote-session.mjs +239 -0
@@ -0,0 +1,239 @@
1
+ import {FullContractError,FULL_LIMITS} from "./index.mjs";
2
+
3
+ const ID=/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/;
4
+ const AGENT=/^[a-z0-9_-]{1,64}$/;
5
+ const id=value=>typeof value==="string"&&ID.test(value);
6
+ const record=value=>value!==null&&typeof value==="object"&&!Array.isArray(value);
7
+ const require=(condition,code)=>{if(!condition)throw new FullContractError(code);};
8
+ const exact=(value,fields)=>record(value)&&Object.keys(value).every(key=>fields.includes(key));
9
+ const relativePath=relative=>typeof relative==="string"&&relative.length>0&&relative.length<=512&&relative.split("/").every(part=>part.length>0&&part!=="."&&part!==".."&&![".git",".workspace",".relay-workspace-owner.json"].includes(part.toLowerCase())&&!/[\\:\u0000-\u001f]/.test(part)&&!/[. ]$/.test(part)&&!/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(part));
10
+ const descriptors={
11
+ "full.session.ensure":{fields:["intent","taskSessionId","idempotencyKey","title","projectKey"],write:true},
12
+ "full.session.list":{fields:["after","limit"]},
13
+ "full.session.snapshot":{fields:["taskSessionId","consumerId","cursor"],session:true},
14
+ "full.session.acknowledge":{fields:["taskSessionId","consumerId","cursor","revision"],session:true},
15
+ "full.task.checkpoint":{fields:["taskSessionId","expectedRevision","facts"],session:true,write:true},
16
+ "full.task.plan":{fields:["taskSessionId","expectedRevision","steps","reason"],session:true,write:true},
17
+ "full.task.phase":{fields:["taskSessionId","expectedRevision","phase"],session:true,write:true},
18
+ "full.task.narrative":{fields:["taskSessionId","expectedRevision","stepId","state","note"],session:true,write:true},
19
+ "full.task.status":{fields:["taskSessionId","expectedRevision","status"],session:true,write:true},
20
+ "full.workspace.ensure":{fields:["taskSessionId","kind","mode","repoPath","sharedPath","baseRef","artifactRoot"],session:true,write:true},
21
+ "full.workspace.read":{fields:["taskSessionId","relativePath","relativePaths"],session:true},
22
+ "full.workspace.edit":{fields:["taskSessionId","operations"],session:true,write:true},
23
+ "full.intelligence.refresh":{fields:["taskSessionId","queries","readPaths","taskContext"],session:true,write:true},
24
+ "full.intelligence.search":{fields:["taskSessionId","query","limit","cursor"],session:true},
25
+ "full.intelligence.symbols":{fields:["taskSessionId","query","limit","cursor"],session:true},
26
+ "full.intelligence.dependencies":{fields:["taskSessionId","files","direction","depth"],session:true},
27
+ "full.intelligence.impact":{fields:["taskSessionId","baseGeneration","proposedPaths","proposedSymbolIds","mandatoryChecks"],session:true},
28
+ "full.intelligence.context":{fields:["taskSessionId","consumerId","phase","query","budgetBytes","requirements","learn","cursor","refresh"],session:true},
29
+ "full.intelligence.acknowledge":{fields:["taskSessionId","consumerId","deliveryId"],session:true},
30
+ "full.job.start":{fields:["taskSessionId","idempotencyKey","command","timeoutMs","verificationCheckId","waitMs"],session:true,terminal:true,write:true},
31
+ "full.job.status":{fields:["taskSessionId","jobId"],session:true},
32
+ "full.job.read":{fields:["taskSessionId","jobId","afterSeq","waitMs"],session:true,terminal:true},
33
+ "full.job.cancel":{fields:["taskSessionId","jobId"],session:true,terminal:true,write:true},
34
+ "full.job.reconcile":{fields:["taskSessionId","jobId"],session:true,terminal:true,write:true},
35
+ "full.verification.plan":{fields:["taskSessionId","expectedRevision","requirements","checks","risk","knownImplementationComplete","staticReviewComplete"],session:true,write:true},
36
+ "full.verification.record":{fields:["taskSessionId","expectedRevision","jobId"],session:true,write:true},
37
+ "full.verification.assess":{fields:["taskSessionId"],session:true},
38
+ "full.diagnostics.snapshot":{fields:["taskSessionId","cursor"],session:true},
39
+ "full.diagnostics.mode":{fields:["taskSessionId","mode","durationMs","confirmed"],session:true,write:true},
40
+ "full.diagnostics.export":{fields:["taskSessionId","confirmed"],session:true},
41
+ "full.desktop.windows":{fields:["taskSessionId","limit"],session:true,desktopRead:true},
42
+ "full.desktop.step":{fields:["taskSessionId","idempotencyKey","actions","settleMs"],session:true,write:true,desktopControl:true},
43
+ "full.session.export":{fields:["taskSessionId","confirmed","cursor"],session:true},
44
+ "full.session.delete":{fields:["taskSessionId","confirmed","expectedRevision"],session:true,write:true}
45
+ };
46
+ export const REMOTE_FULL_OPERATIONS=Object.freeze(Object.keys(descriptors));
47
+ // Additive optional operations must not change the baseline required of older
48
+ // verified full.sessions providers during Core startup.
49
+ export const REMOTE_SESSION_LIFECYCLE_OPERATIONS=Object.freeze(["full.session.export","full.session.delete"]);
50
+ export const REMOTE_SESSION_OPERATIONS=Object.freeze(REMOTE_FULL_OPERATIONS.filter(op=>(op.startsWith("full.session.")||op.startsWith("full.task."))&&!REMOTE_SESSION_LIFECYCLE_OPERATIONS.includes(op)));
51
+ export const REMOTE_WORKSPACE_OPERATIONS=Object.freeze(REMOTE_FULL_OPERATIONS.filter(op=>op.startsWith("full.workspace.")));
52
+ export const REMOTE_INTELLIGENCE_OPERATIONS=Object.freeze(REMOTE_FULL_OPERATIONS.filter(op=>op.startsWith("full.intelligence.")));
53
+ export const REMOTE_JOB_OPERATIONS=Object.freeze(REMOTE_FULL_OPERATIONS.filter(op=>op.startsWith("full.job.")));
54
+ export const REMOTE_DESKTOP_OPERATIONS=Object.freeze(REMOTE_FULL_OPERATIONS.filter(op=>op.startsWith("full.desktop.")));
55
+ export const DESKTOP_BROKER_OPERATION="full.internal.desktop.run";
56
+ export const VERIFICATION_ASSESS_OPERATION="full.internal.verification.assess";
57
+ export const DIAGNOSTICS_OPERATION="full.diagnostics.snapshot";
58
+ export const REMOTE_DIAGNOSTICS_OPERATIONS=Object.freeze(REMOTE_FULL_OPERATIONS.filter(op=>op.startsWith("full.diagnostics.")));
59
+ export const JOB_BROKER_OPERATION="full.internal.jobs.run";
60
+ export const RESOURCE_HEALTH_OPERATION="full.internal.resources.health";
61
+ export const INTELLIGENCE_BROKER_OPERATION="full.internal.intelligence.run";
62
+ export const WORKSPACE_BROKER_OPERATIONS=Object.freeze(["full.internal.workspace.snapshot","full.internal.workspace.set"]);
63
+ // Private inherited IPC only. This is deliberately absent from remote operations.
64
+ export const PRESENTATION_WORKSPACE_OPERATION="full.internal.presentation.workspace";
65
+ export const EDIT_BROKER_OPERATION="full.internal.workspace.edit";
66
+ export const ISOLATION_BROKER_OPERATION="full.internal.workspace.set-isolated";
67
+ export const ARTIFACT_BROKER_OPERATION="full.internal.workspace.set-artifact";
68
+ export const REMOTE_FULL_CAPABILITIES=Object.freeze(["full.host","full.sessions","full.sessions.lifecycle","full.workspace.readonly","full.workspace.read-batch","full.workspace.isolated","full.workspace.artifacts","full.workspace.edit","full.intelligence","full.intelligence.batch","full.intelligence.task-context","full.intelligence.task-context.expand","full.jobs","full.jobs.recovery","full.jobs.wait","full.verification","full.diagnostics","full.desktop"]);
69
+
70
+ /** Public request contains data only. It cannot choose an authority, a job,
71
+ * an evidence producer, an arbitrary absolute read target or host capability. */
72
+ export function parseRemoteFullRequest(value){
73
+ require(exact(value,["operation","input"])&&typeof value.operation==="string"&&Object.hasOwn(descriptors,value.operation),"full_capability_unavailable");
74
+ const {operation}=value,descriptor=descriptors[operation];
75
+ const input=record(value.input)?{...value.input}:value.input;
76
+ require(exact(input,descriptor.fields),"full_invalid_remote_input");
77
+ if(descriptor.session||Object.hasOwn(input,"taskSessionId"))require(id(input.taskSessionId),"full_invalid_session_id");
78
+ if(operation==="full.session.ensure"){
79
+ require(["create","ensure","resume","new-attempt"].includes(input.intent)&&id(input.idempotencyKey),"full_invalid_intent");
80
+ if(["resume","new-attempt"].includes(input.intent))require(id(input.taskSessionId),"full_invalid_session_id");
81
+ if(input.intent==="create")require(!Object.hasOwn(input,"taskSessionId"),"full_invalid_session_id");
82
+ }
83
+ if(operation==="full.session.export"){
84
+ require(input.confirmed===true,"full_export_confirmation_required");
85
+ if(Object.hasOwn(input,"cursor"))require(typeof input.cursor==="string"&&input.cursor.length>=1&&input.cursor.length<=512&&/^[A-Za-z0-9_-]+$/.test(input.cursor),"full_invalid_cursor");
86
+ }
87
+ if(operation==="full.session.delete")require(input.confirmed===true,"full_delete_confirmation_required");
88
+ if(operation.startsWith("full.task.")||operation==="full.session.delete")require(Number.isSafeInteger(input.expectedRevision)&&input.expectedRevision>=1,"full_revision_required");
89
+ if(operation==="full.session.acknowledge")require(id(input.consumerId)&&Number.isSafeInteger(input.revision)&&input.revision>=1,"full_invalid_cursor");
90
+ if(Object.hasOwn(input,"consumerId"))require(id(input.consumerId),"full_invalid_identifier");
91
+ if(operation==="full.task.plan")require(Array.isArray(input.steps)&&input.steps.length<=32&&input.steps.every(step=>exact(step,["stepId","title"])),"full_invalid_task_step");
92
+ if(operation==="full.task.checkpoint")require(exact(input.facts,["requirements","decisions","changedFiles","outcomes","blockers","summary","nextSteps"]),"full_invalid_checkpoint_field");
93
+ if(operation==="full.workspace.ensure"){
94
+ require(["git","artifact","research","desktop","read-only"].includes(input.kind),"full_invalid_workspace_kind");
95
+ const has=key=>Object.hasOwn(input,key);
96
+ const boundedPath=value=>typeof value==="string"&&value.length>0&&value.length<=512&&!/[\u0000-\u001f]/.test(value);
97
+ if(input.kind==="git"){
98
+ require(!has("artifactRoot"),"full_invalid_workspace_mode");
99
+ if(input.mode===undefined){input.mode="shared";input.sharedPath=input.sharedPath??input.repoPath;}
100
+ require(["isolated","main","shared"].includes(input.mode),"full_invalid_workspace_mode");
101
+ require(!has("baseRef")||(input.mode==="isolated"&&typeof input.baseRef==="string"&&input.baseRef.length>0&&input.baseRef.length<=256&&!/[\u0000\r\n]/.test(input.baseRef)),"full_invalid_workspace_base");
102
+ require(boundedPath(input.repoPath),"full_invalid_resource_path");
103
+ require(input.mode==="shared"?boundedPath(input.sharedPath):!has("sharedPath"),"full_invalid_resource_path");
104
+ }else if(input.kind==="artifact"){
105
+ input.mode=input.mode===undefined?"isolated":input.mode;
106
+ require(input.mode==="isolated"&&!has("repoPath")&&!has("sharedPath")&&!has("baseRef"),"full_invalid_workspace_mode");
107
+ require(boundedPath(input.artifactRoot),"full_invalid_resource_path");
108
+ }else require(!has("repoPath")&&!has("sharedPath")&&!has("baseRef")&&!has("artifactRoot")&&(!has("mode")||input.mode==="none"),"full_invalid_workspace_mode");
109
+ }
110
+ if(operation==="full.workspace.read"){
111
+ const multi=Object.hasOwn(input,"relativePaths");
112
+ require(multi?!Object.hasOwn(input,"relativePath")&&Array.isArray(input.relativePaths)&&input.relativePaths.length>=1&&input.relativePaths.length<=4&&input.relativePaths.every(relativePath)&&new Set(input.relativePaths.map(p=>p.toLowerCase())).size===input.relativePaths.length:relativePath(input.relativePath),"full_invalid_resource_path");
113
+ }
114
+ if(operation==="full.workspace.edit"){
115
+ const ops=input.operations;
116
+ require(Array.isArray(ops)&&ops.length>=1&&ops.length<=8,"full_invalid_edit_batch");
117
+ for(const op of ops){
118
+ require(record(op)&&relativePath(op.relativePath),"full_invalid_resource_path");
119
+ if(op.op==="create")require(exact(op,["op","relativePath","content"])&&typeof op.content==="string"&&op.content.isWellFormed()&&!op.content.includes("\u0000"),"full_invalid_edit_batch");
120
+ else require(op.op==="edit"&&exact(op,["op","relativePath","edits"])&&Array.isArray(op.edits)&&op.edits.length>=1&&op.edits.length<=20&&op.edits.every(e=>exact(e,["oldText","newText","expectedReplacements"])&&typeof e.oldText==="string"&&e.oldText.length>0&&e.oldText.isWellFormed()&&typeof e.newText==="string"&&e.newText.isWellFormed()&&!e.oldText.includes("\u0000")&&!e.newText.includes("\u0000")&&(e.expectedReplacements===undefined||Number.isSafeInteger(e.expectedReplacements)&&e.expectedReplacements>=1&&e.expectedReplacements<=100)),"full_invalid_edit_batch");
121
+ }
122
+ require(new TextEncoder().encode(JSON.stringify(ops)).byteLength<=44000,"full_frame_too_large");
123
+ }
124
+ if(operation==="full.intelligence.refresh"){
125
+ if(Object.hasOwn(input,"taskContext")){
126
+ const context=input.taskContext;
127
+ require(exact(context,["consumerId","phase","query","requirements","learn","budgetBytes","detail"]),"full_invalid_task_context");
128
+ require(context.detail===undefined||["compact","expanded"].includes(context.detail),"full_invalid_task_context");
129
+ require(id(context.consumerId)&&typeof context.query==="string"&&context.query.trim().length>0&&context.query.length<=512&&context.query.isWellFormed(),"full_invalid_task_context");
130
+ require(context.phase===undefined||["prepare","read","execute","verify","complete","review","implement","test","resume"].includes(context.phase),"full_invalid_task_context");
131
+ require(context.budgetBytes===undefined||Number.isSafeInteger(context.budgetBytes)&&context.budgetBytes>=4096&&context.budgetBytes<=16000,"full_invalid_task_context");
132
+ require(context.requirements===undefined||Array.isArray(context.requirements)&&context.requirements.length<=32&&context.requirements.every(v=>typeof v==="string"&&v.length<=512&&v.isWellFormed()),"full_invalid_task_context");
133
+ require(context.learn===undefined||Array.isArray(context.learn)&&context.learn.length<=8&&context.learn.every(m=>exact(m,["memoryId","revision","content"])&&id(m.memoryId)&&typeof m.content==="string"&&m.content.length<=2048&&m.content.isWellFormed()&&(m.revision===undefined||typeof m.revision==="string"&&m.revision.length<=128)),"full_invalid_task_context");
134
+ require(new TextEncoder().encode(JSON.stringify(context)).byteLength<=24000,"full_invalid_task_context");
135
+ }
136
+ if(Object.hasOwn(input,"queries")){
137
+ require(Array.isArray(input.queries)&&input.queries.length>=1&&input.queries.length<=4,"full_invalid_query_batch");
138
+ for(const query of input.queries){
139
+ require(record(query)&&["search","symbols","dependencies"].includes(query.kind),"full_invalid_query_batch");
140
+ const fields=query.kind==="dependencies"?["kind","files","direction","depth"]:["kind","query","limit"];
141
+ require(exact(query,fields),"full_invalid_query_batch");
142
+ const {kind,...options}=query;
143
+ // Share the standalone query checks without allowing nested authority,
144
+ // cursors, refreshes or effectful operations inside a retrieval batch.
145
+ parseRemoteFullRequest({operation:"full.intelligence."+kind,input:{taskSessionId:input.taskSessionId,...options}});
146
+ }
147
+ }
148
+ if(Object.hasOwn(input,"readPaths")){
149
+ require(Array.isArray(input.readPaths)&&input.readPaths.length>=1&&input.readPaths.length<=4&&input.readPaths.every(relativePath),"full_invalid_resource_path");
150
+ require(new Set(input.readPaths.map(p=>p.toLowerCase())).size===input.readPaths.length,"full_invalid_query_batch");
151
+ }
152
+ }
153
+ if(operation==="full.intelligence.search"||operation==="full.intelligence.symbols"){
154
+ require(typeof input.query==="string"&&input.query.trim().length>0&&input.query.length<=(operation.endsWith("symbols")?128:256),"full_invalid_index_query");
155
+ require(input.limit===undefined||Number.isSafeInteger(input.limit)&&input.limit>=1&&input.limit<=10,"full_invalid_page");
156
+ }
157
+ if(operation==="full.intelligence.dependencies"){
158
+ require(Array.isArray(input.files)&&input.files.length>=1&&input.files.length<=8&&input.files.every(p=>typeof p==="string"&&p.length>0&&p.length<=512&&!p.startsWith("/")&&!/[\\:\u0000-\u001f]/.test(p)&&p.split("/").every(x=>x&&x!=="."&&x!=="..")),"full_invalid_graph_roots");
159
+ require(input.direction===undefined||["consumers","dependencies"].includes(input.direction),"full_invalid_graph_direction");
160
+ require(input.depth===undefined||Number.isSafeInteger(input.depth)&&input.depth>=1&&input.depth<=4,"full_invalid_graph_depth");
161
+ }
162
+ if(operation==="full.intelligence.impact"){
163
+ require(input.baseGeneration===undefined||Number.isSafeInteger(input.baseGeneration)&&input.baseGeneration>=1,"full_invalid_revision");
164
+ for(const key of ["proposedPaths","proposedSymbolIds","mandatoryChecks"])
165
+ require(input[key]===undefined||Array.isArray(input[key])&&input[key].length<=32&&input[key].every(v=>typeof v==="string"&&v.length>0&&v.length<=512),"full_invalid_impact_input");
166
+ }
167
+ if(operation==="full.intelligence.context"||operation==="full.intelligence.acknowledge")require(id(input.consumerId),"full_invalid_identifier");
168
+ if(operation==="full.intelligence.context")require(input.budgetBytes===undefined||Number.isSafeInteger(input.budgetBytes)&&input.budgetBytes>=4096&&input.budgetBytes<=32000,"full_context_invalid_budget_or_query");
169
+ if(operation==="full.intelligence.acknowledge")require(id(input.deliveryId),"full_invalid_identifier");
170
+ if(operation==="full.verification.plan"||operation==="full.verification.record")require(Number.isSafeInteger(input.expectedRevision)&&input.expectedRevision>=1,"full_revision_required");
171
+ if(operation==="full.verification.plan"){
172
+ require(Array.isArray(input.requirements)&&input.requirements.length>=1&&input.requirements.length<=16&&input.requirements.every(r=>exact(r,["requirementId","title"])&&id(r.requirementId)&&typeof r.title==="string"&&r.title.trim()&&r.title.length<=256),"full_invalid_verification_plan");
173
+ require(Array.isArray(input.checks)&&input.checks.length>=1&&input.checks.length<=8,"full_invalid_verification_plan");
174
+ for(const c of input.checks){
175
+ require(exact(c,["checkId","title","requirementIds","mandatory","command","timeoutMs","paths"])&&id(c.checkId)&&typeof c.title==="string"&&c.title.trim()&&c.title.length<=128&&Array.isArray(c.requirementIds)&&c.requirementIds.length>=1&&c.requirementIds.length<=8&&c.requirementIds.every(id)&&typeof c.mandatory==="boolean","full_invalid_verification_check");
176
+ require(typeof c.command==="string"&&c.command.trim()&&c.command.length<=4000&&!c.command.includes("\u0000"),"full_invalid_job_request");
177
+ require(c.timeoutMs===undefined||Number.isSafeInteger(c.timeoutMs)&&c.timeoutMs>=1000&&c.timeoutMs<=1800000,"full_invalid_timeout");
178
+ require(Array.isArray(c.paths)&&c.paths.length>=1&&c.paths.length<=6&&c.paths.every(p=>relativePath(p)&&p.length<=100)&&new Set(c.paths.map(p=>p.toLowerCase())).size===c.paths.length,"full_verification_input_limit");
179
+ }
180
+ require(new Set(input.checks.flatMap(c=>c.paths)).size<=12,"full_verification_input_limit");
181
+ require(input.risk===undefined||["trivial","low","normal","high"].includes(input.risk),"full_invalid_verification_plan");
182
+ require(["knownImplementationComplete","staticReviewComplete"].every(k=>input[k]===undefined||typeof input[k]==="boolean"),"full_invalid_verification_plan");
183
+ }
184
+ if(operation==="full.verification.record")require(id(input.jobId),"full_invalid_job");
185
+ if(operation===DIAGNOSTICS_OPERATION&&input.cursor!==undefined)require(exact(input.cursor,["epoch","sequence","sourceGaps"])&&id(input.cursor.epoch)&&Number.isSafeInteger(input.cursor.sequence)&&input.cursor.sequence>=0&&Number.isSafeInteger(input.cursor.sourceGaps)&&input.cursor.sourceGaps>=0,"full_invalid_cursor");
186
+ if(operation==="full.diagnostics.mode"){
187
+ require(["normal","debug","profile"].includes(input.mode),"full_invalid_diagnostic_mode");
188
+ require(input.mode==="normal"?(input.confirmed===undefined||typeof input.confirmed==="boolean"):input.confirmed===true,"full_diagnostic_confirmation_required");
189
+ require(input.durationMs===undefined||Number.isSafeInteger(input.durationMs)&&input.durationMs>=100&&input.durationMs<=1800000,"full_invalid_timeout");
190
+ }
191
+ if(operation==="full.diagnostics.export")require(input.confirmed===true,"full_diagnostic_confirmation_required");
192
+ if(operation==="full.desktop.windows")require(input.limit===undefined||Number.isSafeInteger(input.limit)&&input.limit>=1&&input.limit<=32,"full_invalid_page");
193
+ if(operation==="full.desktop.step"){
194
+ require(id(input.idempotencyKey)&&Array.isArray(input.actions)&&input.actions.length>=1&&input.actions.length<=20,"full_invalid_desktop_step");
195
+ require(input.settleMs===undefined||Number.isSafeInteger(input.settleMs)&&input.settleMs>=0&&input.settleMs<=1000,"full_invalid_desktop_step");
196
+ let wait=0,bytes=0;
197
+ for(const action of input.actions){
198
+ require(record(action),"full_invalid_desktop_step");
199
+ if(action.type==="click")require(exact(action,["type","x","y","button","clicks"])&&[action.x,action.y].every(n=>Number.isSafeInteger(n)&&Math.abs(n)<=1000000)&&(action.button===undefined||["left","right","middle"].includes(action.button))&&(action.clicks===undefined||action.clicks===1||action.clicks===2),"full_invalid_desktop_step");
200
+ else if(action.type==="text"){
201
+ require(exact(action,["type","text"])&&typeof action.text==="string"&&action.text.length>0&&action.text.length<=8192&&action.text.isWellFormed()&&!action.text.includes("\u0000"),"full_invalid_desktop_step");
202
+ bytes+=new TextEncoder().encode(action.text).byteLength;
203
+ }else if(action.type==="key")require(exact(action,["type","key","ctrl","alt","shift","win"])&&typeof action.key==="string"&&/^(?:[A-Za-z0-9]|Enter|Tab|Escape|Backspace|Delete|Arrow(?:Left|Up|Right|Down)|Home|End|PageUp|PageDown|Space|F(?:[1-9]|1[0-2]))$/.test(action.key)&&["ctrl","alt","shift","win"].every(k=>action[k]===undefined||typeof action[k]==="boolean"),"full_invalid_desktop_step");
204
+ else if(action.type==="wait"){require(exact(action,["type","ms"])&&Number.isSafeInteger(action.ms)&&action.ms>=0&&action.ms<=2000,"full_invalid_desktop_step");wait+=action.ms;}
205
+ else throw new FullContractError("full_invalid_desktop_step");
206
+ }
207
+ require(wait<=2000&&bytes<=16384,"full_invalid_desktop_step");
208
+ }
209
+ if(operation==="full.job.start"){
210
+ require(id(input.idempotencyKey)&&typeof input.command==="string"&&input.command.trim().length>0&&input.command.length<=4000&&!input.command.includes("\u0000"),"full_invalid_job_request");
211
+ require(input.verificationCheckId===undefined||id(input.verificationCheckId),"full_invalid_verification_check");
212
+ input.timeoutMs=input.timeoutMs===undefined?120000:input.timeoutMs;
213
+ require(Number.isSafeInteger(input.timeoutMs)&&input.timeoutMs>=1000&&input.timeoutMs<=1800000,"full_invalid_timeout");
214
+ }else if(REMOTE_JOB_OPERATIONS.includes(operation)){
215
+ require(id(input.jobId),"full_invalid_job");
216
+ if(operation==="full.job.read")require(input.afterSeq===undefined||Number.isSafeInteger(input.afterSeq)&&input.afterSeq>=0,"full_invalid_cursor");
217
+ }
218
+ if((operation==="full.job.start"||operation==="full.job.read")&&Object.hasOwn(input,"waitMs"))
219
+ require(Number.isSafeInteger(input.waitMs)&&input.waitMs>=0&&input.waitMs<=8000,"full_invalid_wait");
220
+ let encoded;try{encoded=JSON.stringify(input);}catch{throw new FullContractError("full_invalid_remote_input");}
221
+ require(typeof encoded==="string"&&new TextEncoder().encode(encoded).byteLength<=FULL_LIMITS.frameBytes-4096,"full_frame_too_large");
222
+ return {operation,input:JSON.parse(encoded),requiredScopes:operation==="full.workspace.ensure"&&input.kind==="git"&&input.mode==="isolated"?["read","write","terminal"]:["read",...(descriptor.write?["write"]:[]),...(descriptor.terminal?["terminal"]:[]),...(descriptor.desktopRead?["desktop_read"]:[]),...(descriptor.desktopControl?["desktop_control"]:[])]};
223
+ }
224
+ /** Trusted Worker only, AFTER selecting an explicit agent and checking all
225
+ * required ACL scopes. The public /relay route never accepts full.invoke. */
226
+ export function createAuthorizedFullInvocation(request,{accountId,agentId}){
227
+ const parsed=parseRemoteFullRequest(request);
228
+ require(id(accountId)&&typeof agentId==="string"&&AGENT.test(agentId),"full_unauthorized");
229
+ return {action:"full.invoke",operation:parsed.operation,input:parsed.input,principal:{accountId,agentId,scopes:parsed.requiredScopes}};
230
+ }
231
+ /** Defense in depth at the agent and supervised child. No wildcard grants,
232
+ * extra fields or foreign agent identities in an internal invocation. */
233
+ export function parseAuthorizedFullInvocation(value,agentId){
234
+ require(exact(value,["action","operation","input","principal"])&&value.action==="full.invoke","full_unauthorized");
235
+ const parsed=parseRemoteFullRequest({operation:value.operation,input:value.input});
236
+ const p=value.principal;
237
+ require(exact(p,["accountId","agentId","scopes"])&&id(p.accountId)&&p.agentId===agentId&&AGENT.test(agentId)&&Array.isArray(p.scopes)&&p.scopes.length===parsed.requiredScopes.length&&parsed.requiredScopes.every(scope=>p.scopes.includes(scope)),"full_unauthorized");
238
+ return {...parsed,principal:{accountId:p.accountId,agentId,scopes:parsed.requiredScopes}};
239
+ }