@anusornneal/chat-relay 1.9.0 → 2.0.1
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.
- package/README.md +6 -0
- package/agent/activity-capture.mjs +165 -0
- package/agent/capability-scheduler.mjs +82 -5
- package/agent/file-manager.mjs +8 -3
- package/agent/full-bridge.mjs +53 -0
- package/agent/full-desktop-actions.mjs +124 -0
- package/agent/full-desktop-auth.mjs +53 -0
- package/agent/full-desktop-broker.mjs +308 -0
- package/agent/full-host.mjs +153 -0
- package/agent/full-job-broker.mjs +360 -0
- package/agent/full-native-job.mjs +205 -0
- package/agent/full-presentation-changes.mjs +191 -0
- package/agent/full-remote-diagnostics.mjs +129 -0
- package/agent/full-resources.mjs +343 -0
- package/agent/full-runtime-supervisor.mjs +67 -0
- package/agent/full-session-dispatch.mjs +167 -0
- package/agent/full-workspace-broker.mjs +290 -0
- package/agent/git-worktree-manager.mjs +170 -4
- package/agent/lifecycle.mjs +11 -0
- package/agent/local-agent.mjs +150 -24
- package/agent/local-usage.mjs +21 -0
- package/agent/monitor-activity.mjs +111 -0
- package/agent/presentation-redaction.mjs +10 -0
- package/agent/process-manager.mjs +32 -0
- package/agent/terminal-manager.mjs +189 -31
- package/agent/toolcall-context.mjs +23 -1
- package/agent/windows-desktop-runner.mjs +65 -61
- package/agent/windows-desktop-worker.ps1 +33 -18
- package/agent/windows-powershell.mjs +51 -0
- package/cli/full-background.mjs +69 -0
- package/cli/full-launch.mjs +94 -0
- package/cli/full-prepare-child.mjs +48 -0
- package/cli/full-prepare.mjs +171 -0
- package/cli/full-release-default.json +4 -0
- package/cli/full-release-files.mjs +36 -0
- package/cli/full-release-official.mjs +48 -0
- package/cli/full-release-source.mjs +37 -0
- package/cli/index.mjs +8 -4
- package/cli/mod-cache.mjs +170 -0
- package/cli/mod-loader.mjs +67 -0
- package/cli/mod-manifest.mjs +63 -0
- package/cli/remote.mjs +172 -17
- package/cli/runner-ownership.mjs +116 -3
- package/cli/self-update.mjs +1 -1
- package/cli/tui.mjs +2 -20
- package/package.json +5 -3
- package/packages/full-contracts/index.mjs +193 -0
- package/packages/full-contracts/native-job.mjs +13 -0
- package/packages/full-contracts/package.json +7 -0
- package/packages/full-contracts/remote-session.mjs +239 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import {constants} from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import {randomUUID,createHash} from "node:crypto";
|
|
5
|
+
import {pathToFileURL} from "node:url";
|
|
6
|
+
import {FullContractError} from "../packages/full-contracts/index.mjs";
|
|
7
|
+
import {canonicalFileResource} from "./full-resources.mjs";
|
|
8
|
+
import {ISOLATION_BROKER_OPERATION,ARTIFACT_BROKER_OPERATION,INTELLIGENCE_BROKER_OPERATION,REMOTE_INTELLIGENCE_OPERATIONS,REMOTE_JOB_OPERATIONS,RESOURCE_HEALTH_OPERATION,EDIT_BROKER_OPERATION,VERIFICATION_ASSESS_OPERATION,PRESENTATION_WORKSPACE_OPERATION} from "../packages/full-contracts/remote-session.mjs";
|
|
9
|
+
import {createRemoteJobBroker,AGENT_EFFECT_KEY} from "./full-job-broker.mjs";
|
|
10
|
+
import {verificationEnvironment} from "./full-native-job.mjs";
|
|
11
|
+
import {readPresentationChanges,presentationChangePath} from "./full-presentation-changes.mjs";
|
|
12
|
+
|
|
13
|
+
const require=(ok,code)=>{if(!ok)throw new FullContractError(code);};
|
|
14
|
+
const within=(root,target)=>{
|
|
15
|
+
const relative=path.relative(root,target);
|
|
16
|
+
return relative===""||(!path.isAbsolute(relative)&&relative!==".."&&!relative.startsWith(".."+path.sep));
|
|
17
|
+
};
|
|
18
|
+
const samePath=(a,b)=>path.relative(a,b)==="";
|
|
19
|
+
const visibleBinding=({workspaceId,taskSessionId,mode,workspaceKind,state,branch,baseCommit})=>({workspaceId,taskSessionId,mode,workspaceKind,state,branch,baseCommit});
|
|
20
|
+
const safeBinding=(b,isolation,artifacts)=>b&&(["research","desktop","read-only"].includes(b.workspaceKind)&&b.mode==="none"||b.workspaceKind==="git"&&(["main","shared"].includes(b.mode)||isolation&&b.mode==="isolated")||artifacts&&b.workspaceKind==="artifact"&&b.mode==="isolated");
|
|
21
|
+
const MAX_READ_BYTES=8192,MAX_BATCH_RESPONSE=40000;
|
|
22
|
+
const encodedSize=value=>Buffer.byteLength(JSON.stringify(value),"utf8");
|
|
23
|
+
const batchReadError=(relativePath,code)=>({relativePath,ok:false,error:{code}});
|
|
24
|
+
const readErrorCode=error=>typeof error?.code==="string"&&/^full_[a-z0-9_]+$/.test(error.code)?error.code:"full_read_failed";
|
|
25
|
+
|
|
26
|
+
// The verified first-party artifact supplies the existing workspace service.
|
|
27
|
+
// Core remains the sole authority for Git and filesystem operations; the host
|
|
28
|
+
// remains the single durable session writer. Arbitrary terminal jobs reserve
|
|
29
|
+
// an agent-wide effect claim in addition to their bound Git/artifact workspace.
|
|
30
|
+
export async function createRemoteWorkspaceBroker({host,artifact,git,roots,scheduler,files,terminalEnabled=false,legacyBusy=()=>false,recoveryDirectory,onJobChanged}){
|
|
31
|
+
const scopedEdits=artifact.capabilities.includes("full.workspace.edit")&&host.operations.includes(EDIT_BROKER_OPERATION)&&typeof files?.editMany==="function";
|
|
32
|
+
let scopedWriteStarts=0;
|
|
33
|
+
const verification=artifact.capabilities.includes("full.verification")&&["full.verification.plan","full.verification.record",VERIFICATION_ASSESS_OPERATION].every(op=>host.operations.includes(op));
|
|
34
|
+
const intelligence=artifact.capabilities.includes("full.intelligence")&&host.operations.includes(INTELLIGENCE_BROKER_OPERATION);
|
|
35
|
+
const intelligenceBatch=intelligence&&artifact.capabilities.includes("full.intelligence.batch");
|
|
36
|
+
const taskContext=intelligence&&artifact.capabilities.includes("full.intelligence.task-context");
|
|
37
|
+
const taskContextExpand=taskContext&&artifact.capabilities.includes("full.intelligence.task-context.expand");
|
|
38
|
+
const readBatchEnabled=artifact.capabilities.includes("full.workspace.read-batch");
|
|
39
|
+
const isolation=terminalEnabled===true&&artifact.capabilities.includes("full.workspace.isolated")&&host.operations.includes(ISOLATION_BROKER_OPERATION)&&["planOwned","assertOwnedFresh","provisionOwned","inspectOwned"].every(key=>typeof git?.[key]==="function");
|
|
40
|
+
const artifacts=artifact.capabilities.includes("full.workspace.artifacts")&&host.operations.includes(ARTIFACT_BROKER_OPERATION);
|
|
41
|
+
const sharedGit=["planShared","inspectShared"].every(key=>typeof git?.[key]==="function");
|
|
42
|
+
require(typeof roots==="function"&&scheduler?.fullAdmission,"full_capability_unavailable");
|
|
43
|
+
const moduleUrl=pathToFileURL(path.resolve(path.dirname(artifact.executablePath),"../workspaces/service.mjs")).href;
|
|
44
|
+
const {createWorkspaceService,ArtifactWorkspaces}=await import(moduleUrl);
|
|
45
|
+
require(!artifacts||typeof ArtifactWorkspaces==="function","full_capability_unavailable");
|
|
46
|
+
const checkTarget=async target=>{
|
|
47
|
+
for(const allowed of roots()){
|
|
48
|
+
try{if(within(await fs.realpath(allowed),target))return true;}catch{}
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
};
|
|
52
|
+
const canonicalKey=target=>canonicalFileResource(target,{checkTarget});
|
|
53
|
+
const validatePlan=binding=>{require(binding.rootRef.length<=512&&binding.primaryRootRef.length<=512,"full_invalid_resource_path");return binding;};
|
|
54
|
+
function artifactProvider(root){
|
|
55
|
+
require(artifacts&&typeof root==="string"&&path.isAbsolute(root),"full_capability_unavailable");
|
|
56
|
+
const provider=new ArtifactWorkspaces({root,checkTarget});
|
|
57
|
+
const authorizeRoot=async()=>{
|
|
58
|
+
const stat=await fs.lstat(root),canonical=await fs.realpath(root);
|
|
59
|
+
require(stat.isDirectory()&&!stat.isSymbolicLink()&&samePath(root,canonical),"full_artifact_path_alias");
|
|
60
|
+
require(await checkTarget(canonical),"full_unauthorized");
|
|
61
|
+
// Explicit artifact roots cannot adopt/nest inside any managed task.
|
|
62
|
+
// Check parent markers too, including a caller-supplied root below one.
|
|
63
|
+
const parts=canonical.split(path.sep).map(part=>part.toLowerCase());
|
|
64
|
+
require(!parts.some((part,index)=>part===".workspace"&&parts[index+1]==="worktrees"&&/^full-ws-[a-f0-9]{32}$/.test(parts[index+2]??"")),"full_artifact_root_owned");
|
|
65
|
+
for(let current=canonical;;current=path.dirname(current)){
|
|
66
|
+
let marker;
|
|
67
|
+
try{marker=await fs.lstat(path.join(current,".relay-workspace-owner.json"));}
|
|
68
|
+
catch(error){if(error.code!=="ENOENT")throw error;}
|
|
69
|
+
require(!marker,"full_artifact_root_owned");
|
|
70
|
+
if(path.dirname(current)===current)break;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
async plan(workspaceId){await authorizeRoot();return validatePlan(await provider.plan(workspaceId));},
|
|
75
|
+
async assertFresh(binding){await authorizeRoot();return provider.assertFresh(binding);},
|
|
76
|
+
async provision(binding){await authorizeRoot();return provider.provision(binding);}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const planGit={
|
|
80
|
+
...(isolation?{
|
|
81
|
+
async planOwned(repoPath,options){require(path.isAbsolute(repoPath),"full_invalid_resource_path");return validatePlan(await git.planOwned(repoPath,options));},
|
|
82
|
+
assertOwnedFresh:binding=>git.assertOwnedFresh(binding),
|
|
83
|
+
provisionOwned:binding=>git.provisionOwned(binding)
|
|
84
|
+
}:{}),
|
|
85
|
+
async planShared(repoPath,options){
|
|
86
|
+
require(path.isAbsolute(repoPath)&&(!options.sharedPath||path.isAbsolute(options.sharedPath)),"full_invalid_resource_path");
|
|
87
|
+
const binding=await git.planShared(repoPath,options);
|
|
88
|
+
// Managed isolated worktrees can only be resumed by their owning task.
|
|
89
|
+
const managed=path.join(binding.primaryRootRef,".workspace","worktrees");
|
|
90
|
+
require(!within(managed,binding.rootRef),"full_workspace_mode_conflict");
|
|
91
|
+
return validatePlan(binding);
|
|
92
|
+
},
|
|
93
|
+
inspectShared:binding=>git.inspectShared(binding)
|
|
94
|
+
};
|
|
95
|
+
async function snapshotFor(invocation,parsed){
|
|
96
|
+
const view=await host.request(parsed.operation==="full.workspace.edit"?EDIT_BROKER_OPERATION:"full.internal.workspace.snapshot",{invocation},{taskSessionId:parsed.input.taskSessionId,timeoutMs:10000});
|
|
97
|
+
require(!view.workspace||safeBinding(view.workspace,isolation,artifacts),"full_capability_unavailable");
|
|
98
|
+
return view;
|
|
99
|
+
}
|
|
100
|
+
async function verifyWorkspace(binding){
|
|
101
|
+
require(binding?.state==="ready"&&["git","artifact"].includes(binding.workspaceKind),"full_workspace_not_ready");
|
|
102
|
+
if(binding.workspaceKind==="artifact")await artifactProvider(binding.primaryRootRef).provision(binding);
|
|
103
|
+
else{
|
|
104
|
+
require(binding.mode==="isolated"?isolation:sharedGit,"full_capability_unavailable");
|
|
105
|
+
if(binding.mode==="isolated")await git.inspectOwned(binding);else await git.inspectShared(binding);
|
|
106
|
+
}
|
|
107
|
+
const root=await fs.realpath(binding.rootRef);
|
|
108
|
+
require(samePath(root,binding.rootRef)&&await checkTarget(root),"full_unauthorized");
|
|
109
|
+
return root;
|
|
110
|
+
}
|
|
111
|
+
if(host.operations.includes(RESOURCE_HEALTH_OPERATION)){
|
|
112
|
+
const health=await host.request(RESOURCE_HEALTH_OPERATION);
|
|
113
|
+
require(Number.isSafeInteger(health?.unresolved)&&health.unresolved>=0,"full_recovery_state_unknown");
|
|
114
|
+
scheduler.fullAdmission.setRecoveryBlocked(health.unresolved>0);
|
|
115
|
+
}
|
|
116
|
+
const jobs=await createRemoteJobBroker({host,artifact,scheduler,terminalEnabled,legacyBusy,recoveryDirectory,onJobChanged,
|
|
117
|
+
workspaceFor:async(invocation,parsed)=>(await snapshotFor(invocation,parsed)).workspace,verifyWorkspace,canonicalKey});
|
|
118
|
+
async function readObservedFile(root,binding,relativePath){
|
|
119
|
+
const requested=path.join(root,...relativePath.split("/"));
|
|
120
|
+
const target=await fs.realpath(requested);
|
|
121
|
+
require(within(root,target)&&samePath(requested,target)&&await checkTarget(target),"full_unauthorized");
|
|
122
|
+
const initial=await fs.lstat(target,{bigint:true});
|
|
123
|
+
require(initial.isFile()&&!initial.isSymbolicLink(),"full_invalid_resource_path");
|
|
124
|
+
require(initial.size<=BigInt(MAX_READ_BYTES),"full_read_too_large");
|
|
125
|
+
const handle=await fs.open(target,constants.O_RDONLY|(constants.O_NOFOLLOW??0));
|
|
126
|
+
try{
|
|
127
|
+
const same=(left,right)=>left.dev===right.dev&&left.ino===right.ino&&left.size===right.size&&left.mtimeNs===right.mtimeNs&&left.ctimeNs===right.ctimeNs;
|
|
128
|
+
const before=await handle.stat({bigint:true});
|
|
129
|
+
require(before.isFile()&&same(initial,before),"full_workspace_changed");
|
|
130
|
+
// Bounded allocation even if an unscoped writer expands the file.
|
|
131
|
+
const buffer=Buffer.alloc(MAX_READ_BYTES+1);
|
|
132
|
+
let used=0;
|
|
133
|
+
while(used<buffer.length){
|
|
134
|
+
const {bytesRead}=await handle.read(buffer,used,buffer.length-used,used);
|
|
135
|
+
if(!bytesRead)break;
|
|
136
|
+
used+=bytesRead;
|
|
137
|
+
}
|
|
138
|
+
const after=await handle.stat({bigint:true});
|
|
139
|
+
require(used<=MAX_READ_BYTES,"full_read_too_large");
|
|
140
|
+
require(same(before,after)&&BigInt(used)===after.size&&samePath(await fs.realpath(requested),target)&&same(after,await fs.lstat(target,{bigint:true})),"full_workspace_changed");
|
|
141
|
+
const bytes=buffer.subarray(0,used);
|
|
142
|
+
let content;try{content=new TextDecoder("utf-8",{fatal:true}).decode(bytes);}catch{throw new FullContractError("full_read_not_text");}
|
|
143
|
+
require(!content.includes("\u0000"),"full_read_not_text");
|
|
144
|
+
return {workspaceId:binding.workspaceId,relativePath,content,bytes:used,fingerprint:"sha256:"+createHash("sha256").update(bytes).digest("hex"),coverage:"partial",provenance:"core-observed-file-read",readOnly:true};
|
|
145
|
+
}finally{await handle.close();}
|
|
146
|
+
}
|
|
147
|
+
async function readBatch(root,binding,paths,base={}){
|
|
148
|
+
// One scoped read admission. All started operations settle before
|
|
149
|
+
// releasing the lease, and every omitted/failed file is explicit.
|
|
150
|
+
const reads=await Promise.allSettled(paths.map(relativePath=>readObservedFile(root,binding,relativePath)));
|
|
151
|
+
const response={...base,reads:paths.map(relativePath=>batchReadError(relativePath,"full_response_too_large")),batchComplete:base.batchComplete??true};
|
|
152
|
+
for(let i=0;i<reads.length;i++){
|
|
153
|
+
const read=reads[i],relativePath=paths[i];
|
|
154
|
+
response.reads[i]=read.status==="fulfilled"?{ok:true,...read.value}:batchReadError(relativePath,readErrorCode(read.reason));
|
|
155
|
+
if(encodedSize(response)>MAX_BATCH_RESPONSE){
|
|
156
|
+
response.reads[i]=batchReadError(relativePath,"full_response_too_large");
|
|
157
|
+
response.truncated=true;response.coverage="partial";
|
|
158
|
+
}
|
|
159
|
+
if(!response.reads[i].ok)response.batchComplete=false;
|
|
160
|
+
}
|
|
161
|
+
require(encodedSize(response)<=MAX_BATCH_RESPONSE,"full_response_too_large");
|
|
162
|
+
return response;
|
|
163
|
+
}
|
|
164
|
+
const dispatchOperation=async (invocation,parsed)=>{
|
|
165
|
+
if(REMOTE_JOB_OPERATIONS.includes(parsed.operation)){
|
|
166
|
+
require(jobs,"full_capability_unavailable");
|
|
167
|
+
return jobs.dispatch(invocation,parsed);
|
|
168
|
+
}
|
|
169
|
+
const {principal,input,operation}=parsed;
|
|
170
|
+
const batch=operation==="full.intelligence.refresh"&&(input.queries!==undefined||input.readPaths!==undefined);
|
|
171
|
+
require(!batch||intelligenceBatch,"full_capability_unavailable");
|
|
172
|
+
require(input.taskContext===undefined||taskContext,"full_capability_unavailable");
|
|
173
|
+
require(input.taskContext?.detail===undefined||taskContextExpand,"full_capability_unavailable");
|
|
174
|
+
require(input.relativePaths===undefined||readBatchEnabled,"full_capability_unavailable");
|
|
175
|
+
const taskSessionId=input.taskSessionId;
|
|
176
|
+
const request=(name,fields={})=>host.request(name,{invocation,...fields},{taskSessionId,timeoutMs:10000});
|
|
177
|
+
const snapshot=()=>snapshotFor(invocation,parsed);
|
|
178
|
+
const store={
|
|
179
|
+
snapshot,
|
|
180
|
+
setWorkspace:({expectedRevision,binding})=>request(binding.workspaceKind==="artifact"?ARTIFACT_BROKER_OPERATION:binding.mode==="isolated"?ISOLATION_BROKER_OPERATION:"full.internal.workspace.set",{expectedRevision,binding})
|
|
181
|
+
};
|
|
182
|
+
const attemptId=randomUUID();
|
|
183
|
+
const admission=(options,work)=>scheduler.runFull("fs.read",work,{...options,claims:[{key:AGENT_EFFECT_KEY,mode:"read"},...options.claims]});
|
|
184
|
+
if(operation==="full.workspace.ensure"){
|
|
185
|
+
require(input.kind!=="git"||(input.mode==="isolated"?isolation:sharedGit),"full_capability_unavailable");
|
|
186
|
+
require(input.kind!=="artifact"||artifacts,"full_capability_unavailable");
|
|
187
|
+
const provisions=input.kind==="artifact"||input.kind==="git"&&input.mode==="isolated";
|
|
188
|
+
const service=createWorkspaceService({store,git:planGit,...(input.kind==="artifact"?{artifacts:artifactProvider(input.artifactRoot)}:{}),canonicalKey,
|
|
189
|
+
admit:(options,work)=>admission(options,async(...args)=>{if(provisions)require(!legacyBusy(),"full_legacy_effect_active");return work(...args);}),ownerEpoch:host.ownerEpoch});
|
|
190
|
+
const result=await service.ensure({...input,principal,attemptId});
|
|
191
|
+
return {...result,binding:visibleBinding(result.binding),readOnly:!scopedEdits||!["git","artifact"].includes(result.binding.workspaceKind)};
|
|
192
|
+
}
|
|
193
|
+
const isIntelligence=REMOTE_INTELLIGENCE_OPERATIONS.includes(operation),isEdit=operation==="full.workspace.edit",isAssess=operation==="full.verification.assess";
|
|
194
|
+
require(operation==="full.workspace.read"||isEdit&&scopedEdits||isIntelligence&&intelligence||isAssess&&verification,"full_capability_unavailable");
|
|
195
|
+
const {workspace:binding}=await snapshot();
|
|
196
|
+
require(binding?.state==="ready","full_workspace_not_ready");
|
|
197
|
+
const code=binding.workspaceKind==="git",ownedArtifact=artifacts&&binding.workspaceKind==="artifact";
|
|
198
|
+
const contextOnly=isIntelligence&&["full.intelligence.context","full.intelligence.acknowledge"].includes(operation);
|
|
199
|
+
require(code||ownedArtifact||contextOnly,"full_workspace_not_ready");
|
|
200
|
+
require(!isIntelligence||code||contextOnly,"full_capability_unavailable");
|
|
201
|
+
require(!isAssess||code,"full_verification_code_workspace_required");
|
|
202
|
+
const needsFiles=code||ownedArtifact&&!contextOnly;
|
|
203
|
+
const mode=isEdit?"write":"read";
|
|
204
|
+
const claims=[{key:"workspace:"+binding.workspaceId,mode}];
|
|
205
|
+
// The same root needs only one pre-admission observation. Distinct roots
|
|
206
|
+
// are resolved concurrently; effect-time checks below still run fresh.
|
|
207
|
+
const targets=[...new Set([...(code?[binding.primaryRootRef]:[]),...(needsFiles?[binding.rootRef]:[])])];
|
|
208
|
+
const results=await Promise.allSettled(targets.map(target=>canonicalFileResource(target,{checkTarget,requireExistingCanonical:true})));
|
|
209
|
+
const failure=results.find(result=>result.status==="rejected");
|
|
210
|
+
if(failure)throw failure.reason;
|
|
211
|
+
const keys=new Map(targets.map((target,i)=>[target,results[i].value]));
|
|
212
|
+
if(code)claims.push({key:"git:"+keys.get(binding.primaryRootRef),mode:"read"});
|
|
213
|
+
if(needsFiles)claims.push({key:keys.get(binding.rootRef),mode});
|
|
214
|
+
return admission({owner:{accountId:principal.accountId,agentId:principal.agentId,taskSessionId},ownerEpoch:host.ownerEpoch,attemptId,claims,priority:operation==="full.intelligence.refresh"&&input.taskContext===undefined?"background":"task",dependenciesReady:true},async(_meta,lease)=>{
|
|
215
|
+
const {workspace:current}=await snapshot();
|
|
216
|
+
require(current?.state==="ready"&&["workspaceId","workspaceKind","mode","rootRef","primaryRootRef","branch","baseCommit"].every(key=>current[key]===binding[key]),"full_workspace_conflict");
|
|
217
|
+
const root=needsFiles?await verifyWorkspace(current):null;
|
|
218
|
+
if(isEdit){
|
|
219
|
+
require(!legacyBusy(),"full_legacy_effect_active");
|
|
220
|
+
const operations=input.operations.map(({relativePath,...op})=>({...op,path:relativePath}));
|
|
221
|
+
const result=await files.editMany(operations,root,{strictPaths:true});
|
|
222
|
+
return {...result,workspaceId:current.workspaceId,provenance:"core-scoped-file-edit",requiresIntelligenceRefresh:code&&result.succeeded>0,atomicity:"per-file"};
|
|
223
|
+
}
|
|
224
|
+
if(isIntelligence||isAssess){
|
|
225
|
+
let result;
|
|
226
|
+
try{result=await host.request(isAssess?VERIFICATION_ASSESS_OPERATION:INTELLIGENCE_BROKER_OPERATION,{invocation,workspaceId:current.workspaceId,verifiedRoot:root,...(isAssess?{environment:verificationEnvironment(artifact.artifactId)}:{})},{taskSessionId,timeoutMs:12000,waitForSettlement:true});}
|
|
227
|
+
catch(error){
|
|
228
|
+
if(error.code==="full_settlement_unknown"){
|
|
229
|
+
lease.quarantine();
|
|
230
|
+
// Only this read/index/assessment request runs in the host. A
|
|
231
|
+
// confirmed exit fences its sole writer; never apply to Core
|
|
232
|
+
// file edits or retained native-process reservations.
|
|
233
|
+
void host.exited.then(proof=>{if(proof?.confirmed&&proof.ownerEpoch===host.ownerEpoch)lease.confirmRequestOwnerStopped({ownerEpoch:host.ownerEpoch,confirmed:true});}).catch(()=>{});
|
|
234
|
+
// A timed-out host must not hold an unknown request forever.
|
|
235
|
+
// The supervisor can restart it after actual process exit.
|
|
236
|
+
void host.dispose().catch(()=>{});
|
|
237
|
+
}
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
if(!batch||!input.readPaths)return result;
|
|
241
|
+
return readBatch(root,current,input.readPaths,result);
|
|
242
|
+
}
|
|
243
|
+
return input.relativePaths?readBatch(root,current,input.relativePaths,{workspaceId:current.workspaceId,readOnly:true}):readObservedFile(root,current,input.relativePath);
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
async function presentationChanges(invocation,parsed,input,signal,redact){
|
|
247
|
+
require(parsed.operation==="full.session.snapshot"&&parsed.input.taskSessionId===input.taskSessionId,"full_unauthorized");
|
|
248
|
+
require(input.relativePath===undefined||presentationChangePath(input.relativePath),"full_invalid_presentation_input");
|
|
249
|
+
const checkCancelled=()=>require(!signal?.aborted,"full_cancelled_before_start");
|
|
250
|
+
const taskSessionId=parsed.input.taskSessionId,principal=parsed.principal;
|
|
251
|
+
const snapshot=()=>host.request(PRESENTATION_WORKSPACE_OPERATION,{invocation},{taskSessionId,timeoutMs:10000,signal});
|
|
252
|
+
checkCancelled();
|
|
253
|
+
const {workspace:binding}=await snapshot();
|
|
254
|
+
checkCancelled();
|
|
255
|
+
const unavailable=reason=>({taskSessionId,workspaceId:binding?.workspaceId??null,source:"git-working-tree",observedAt:new Date().toISOString(),readOnly:true,state:"unavailable",reason,truncated:false,
|
|
256
|
+
...(input.relativePath!==undefined?{relativePath:input.relativePath,text:"",additions:null,deletions:null,binary:false}:{files:[]})});
|
|
257
|
+
if(!binding||binding.workspaceKind!=="git"||binding.state!=="ready")return unavailable("This session has no ready Git workspace.");
|
|
258
|
+
require(safeBinding(binding,isolation,artifacts),"full_capability_unavailable");
|
|
259
|
+
const targets=[...new Set([binding.primaryRootRef,binding.rootRef])];
|
|
260
|
+
const observations=await Promise.allSettled(targets.map(target=>canonicalFileResource(target,{checkTarget,requireExistingCanonical:true})));
|
|
261
|
+
const failed=observations.find(result=>result.status==="rejected");if(failed)throw failed.reason;
|
|
262
|
+
const keys=new Map(targets.map((target,index)=>[target,observations[index].value]));
|
|
263
|
+
checkCancelled();
|
|
264
|
+
const claims=[{key:AGENT_EFFECT_KEY,mode:"read"},{key:"workspace:"+binding.workspaceId,mode:"read"},
|
|
265
|
+
{key:"git:"+keys.get(binding.primaryRootRef),mode:"read"},{key:keys.get(binding.rootRef),mode:"read"}];
|
|
266
|
+
// A monitor must not wait behind a retained job lease. Keep the same
|
|
267
|
+
// read claims, but bound interactive waiting and withdraw on disposal.
|
|
268
|
+
try{
|
|
269
|
+
return await scheduler.runFull("fs.read",async()=>{
|
|
270
|
+
checkCancelled();
|
|
271
|
+
const {workspace:current}=await snapshot();
|
|
272
|
+
require(current?.state==="ready"&&["workspaceId","workspaceKind","mode","rootRef","primaryRootRef","branch","baseCommit"].every(key=>current[key]===binding[key]),"full_workspace_conflict");
|
|
273
|
+
const root=await verifyWorkspace(current);
|
|
274
|
+
checkCancelled();
|
|
275
|
+
return readPresentationChanges({root,taskSessionId,workspaceId:current.workspaceId,relativePath:input.relativePath,checkTarget,signal,redact});
|
|
276
|
+
},{owner:{accountId:principal.accountId,agentId:principal.agentId,taskSessionId},ownerEpoch:host.ownerEpoch,attemptId:randomUUID(),claims,priority:"background",dependenciesReady:true,queueTimeoutMs:250,signal});
|
|
277
|
+
}catch(error){
|
|
278
|
+
checkCancelled();
|
|
279
|
+
if(error?.code==="queue_timeout")return unavailable("Workspace is busy. Refresh Changes after the running operation finishes.");
|
|
280
|
+
throw error;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
async function dispatch(invocation,parsed){
|
|
284
|
+
const protectsFiles=parsed.operation==="full.workspace.edit"||parsed.operation==="full.workspace.ensure"&&(parsed.input.kind==="artifact"||parsed.input.kind==="git"&&parsed.input.mode==="isolated");
|
|
285
|
+
if(!protectsFiles)return dispatchOperation(invocation,parsed);
|
|
286
|
+
scopedWriteStarts++;
|
|
287
|
+
try{return await dispatchOperation(invocation,parsed);}finally{scopedWriteStarts--;}
|
|
288
|
+
}
|
|
289
|
+
return Object.freeze({dispatch,presentationChanges:host.operations.includes(PRESENTATION_WORKSPACE_OPERATION)?presentationChanges:null,assertSessionIdle:owner=>jobs?.assertSessionIdle(owner),forgetSession:owner=>jobs?.forgetSession(owner),close:()=>jobs?.close()??true,blocksLegacyEffects:()=>scheduler.fullAdmission.recoveryBlocked||scopedWriteStarts>0||!!jobs?.blocksLegacyEffects(),capabilities:["full.workspace.readonly",...(readBatchEnabled?["full.workspace.read-batch"]:[]),...(isolation?["full.workspace.isolated"]:[]),...(artifacts?["full.workspace.artifacts"]:[]),...(scopedEdits?["full.workspace.edit"]:[]),...(intelligence?["full.intelligence",...(intelligenceBatch?["full.intelligence.batch"]:[]),...(taskContext?["full.intelligence.task-context",...(taskContextExpand?["full.intelligence.task-context.expand"]:[])]:[])]:[]),...(verification?["full.verification"]:[]),...(jobs?["full.jobs",...(jobs.recoveryEnabled?["full.jobs.recovery"]:[]),...(jobs.waitEnabled?["full.jobs.wait"]:[])]:[])]});
|
|
290
|
+
}
|
|
@@ -2,6 +2,7 @@ import { execFile } from "node:child_process";
|
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
5
6
|
|
|
6
7
|
const execFileAsync = promisify(execFile);
|
|
7
8
|
const GIT_MAX_BUFFER = 256 * 1024;
|
|
@@ -21,15 +22,19 @@ function parseWorktrees(output) {
|
|
|
21
22
|
const entries = [];
|
|
22
23
|
let current = null;
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
const value=String(output||"");
|
|
26
|
+
for (const line of value.includes("\0")?value.split("\0"):value.split(/\r?\n/)) {
|
|
25
27
|
if (line.startsWith("worktree ")) {
|
|
26
28
|
if (current) entries.push(current);
|
|
27
|
-
current = { path: line.slice("worktree ".length), branch: null, detached: false };
|
|
29
|
+
current = { path: line.slice("worktree ".length), branch: null, detached: false, head:null,locked:false,bare:false };
|
|
28
30
|
continue;
|
|
29
31
|
}
|
|
30
32
|
if (!current) continue;
|
|
31
33
|
if (line.startsWith("branch refs/heads/")) current.branch = line.slice("branch refs/heads/".length);
|
|
32
34
|
if (line === "detached") current.detached = true;
|
|
35
|
+
if(line.startsWith("HEAD "))current.head=line.slice(5);
|
|
36
|
+
if(line==="locked"||line.startsWith("locked "))current.locked=true;
|
|
37
|
+
if(line==="bare")current.bare=true;
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
if (current) entries.push(current);
|
|
@@ -38,10 +43,11 @@ function parseWorktrees(output) {
|
|
|
38
43
|
|
|
39
44
|
async function runGit(cwd, args, options = {}) {
|
|
40
45
|
try {
|
|
41
|
-
const result = await execFileAsync("git", ["-C", cwd, ...args], {
|
|
46
|
+
const result = await execFileAsync("git", ["-C", cwd, ...(options.safe?["-c","core.fsmonitor=false","-c","core.hooksPath="+(process.platform==="win32"?"NUL":"/dev/null")]:[]), ...args], {
|
|
42
47
|
encoding: "utf8",
|
|
43
48
|
maxBuffer: GIT_MAX_BUFFER,
|
|
44
49
|
windowsHide: true,
|
|
50
|
+
...(options.safe?{env:{...Object.fromEntries(Object.entries(process.env).filter(([key])=>["path","systemroot","windir","home","userprofile","temp","tmp","tmpdir","appdata","localappdata","lang","lc_all"].includes(key.toLowerCase()))),GIT_TERMINAL_PROMPT:"0"},timeout:30000}:{}),
|
|
45
51
|
});
|
|
46
52
|
return {
|
|
47
53
|
ok: true,
|
|
@@ -50,7 +56,7 @@ async function runGit(cwd, args, options = {}) {
|
|
|
50
56
|
exitCode: 0,
|
|
51
57
|
};
|
|
52
58
|
} catch (error) {
|
|
53
|
-
const exitCode = Number.isInteger(error?.code) ?
|
|
59
|
+
const exitCode = Number.isInteger(error?.code) ? error.code : null;
|
|
54
60
|
if (Array.isArray(options.allowExitCodes) && options.allowExitCodes.includes(exitCode)) {
|
|
55
61
|
return {
|
|
56
62
|
ok: false,
|
|
@@ -84,6 +90,165 @@ export class GitWorktreeManager {
|
|
|
84
90
|
throw new Error("path_not_allowed");
|
|
85
91
|
}
|
|
86
92
|
|
|
93
|
+
async #primary(repoPathInput) {
|
|
94
|
+
const repo=await this.#resolveAllowedExisting(repoPathInput);
|
|
95
|
+
const listed=await runGit(repo,["worktree","list","--porcelain","-z"],{safe:true});
|
|
96
|
+
const entries=parseWorktrees(listed.stdout),first=entries[0];
|
|
97
|
+
if(!first||first.bare||!first.path)throw new Error("full_primary_worktree_not_found");
|
|
98
|
+
const root=await this.#resolveAllowedExisting(first.path);
|
|
99
|
+
return {root,entries,first};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#ownedTarget(root,workspaceId){
|
|
103
|
+
if(typeof workspaceId!=="string"||!/^ws-[a-f0-9]{32}$/.test(workspaceId))throw new Error("full_invalid_workspace_id");
|
|
104
|
+
return {rootRef:path.join(root,".workspace","worktrees","full-"+workspaceId),branch:"relay-full/"+workspaceId};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async #parents(root,{create=false}={}){
|
|
108
|
+
let current=root;
|
|
109
|
+
for(const name of [".workspace","worktrees"]){
|
|
110
|
+
current=path.join(current,name);
|
|
111
|
+
let stat;
|
|
112
|
+
try{stat=await fs.lstat(current);}
|
|
113
|
+
catch(error){
|
|
114
|
+
if(error.code!=="ENOENT")throw error;
|
|
115
|
+
if(!create)continue;
|
|
116
|
+
try{await fs.mkdir(current);}catch(cause){if(cause.code!=="EEXIST")throw cause;}
|
|
117
|
+
stat=await fs.lstat(current);
|
|
118
|
+
}
|
|
119
|
+
if(stat&&(!stat.isDirectory()||stat.isSymbolicLink()||comparablePath(await fs.realpath(current),this.platform)!==comparablePath(current,this.platform)))
|
|
120
|
+
throw new Error("full_workspace_path_alias");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async #exists(target){
|
|
125
|
+
try{return await fs.lstat(target);}catch(error){if(error.code==="ENOENT")return null;throw error;}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async #branch(root,branch){
|
|
129
|
+
const result=await runGit(root,["rev-parse","--verify","--quiet","refs/heads/"+branch],{safe:true,allowExitCodes:[1]});
|
|
130
|
+
return result.ok?result.stdout.trim():null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async #status(root){
|
|
134
|
+
const status=await runGit(root,["status","--porcelain=v1","-z","--untracked-files=all"],{safe:true});
|
|
135
|
+
return "sha256:"+createHash("sha256").update(status.stdout).digest("hex");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async planOwned(repoPath,{workspaceId,baseRef="HEAD"}={}){
|
|
139
|
+
const {root}=await this.#primary(repoPath);
|
|
140
|
+
const target=this.#ownedTarget(root,workspaceId);
|
|
141
|
+
if(typeof baseRef!=="string"||!baseRef||baseRef.length>256||/[\0\r\n]/.test(baseRef))throw new Error("full_invalid_workspace_base");
|
|
142
|
+
const ref=await runGit(root,["rev-parse","--verify","--end-of-options",baseRef+"^{commit}"],{safe:true});
|
|
143
|
+
const baseCommit=ref.stdout.trim();
|
|
144
|
+
if(!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(baseCommit))throw new Error("full_invalid_workspace_base");
|
|
145
|
+
// Never edit the caller's ignore file to make isolation possible.
|
|
146
|
+
const ignored=await runGit(root,["check-ignore","-q","--",path.relative(root,target.rootRef)],{safe:true,allowExitCodes:[1]});
|
|
147
|
+
if(!ignored.ok)throw new Error("full_workspace_directory_not_ignored");
|
|
148
|
+
await this.#parents(root);
|
|
149
|
+
return {...target,primaryRootRef:root,baseCommit};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async planShared(repoPath,{mode,sharedPath}={}){
|
|
153
|
+
if(!["main","shared"].includes(mode))throw new Error("full_explicit_workspace_required");
|
|
154
|
+
const {root,entries,first}=await this.#primary(repoPath);
|
|
155
|
+
const selected=mode==="main"?first:entries.find(x=>sharedPath&&comparablePath(x.path,this.platform)===comparablePath(sharedPath,this.platform));
|
|
156
|
+
if(!selected||selected.bare||selected.detached||!selected.branch)throw new Error("full_shared_worktree_not_registered");
|
|
157
|
+
if(selected.branch.startsWith("relay-full/"))throw new Error("full_workspace_requires_owner");
|
|
158
|
+
const rootRef=await this.#resolveAllowedExisting(selected.path);
|
|
159
|
+
return {rootRef,primaryRootRef:root,branch:selected.branch,baseCommit:selected.head,baselineStatusFingerprint:await this.#status(rootRef)};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async #ownedPlan(binding){
|
|
163
|
+
if(binding?.workspaceKind!=="git"||binding.mode!=="isolated")throw new Error("full_invalid_workspace_binding");
|
|
164
|
+
const {root,entries}=await this.#primary(binding.primaryRootRef);
|
|
165
|
+
const planned=this.#ownedTarget(root,binding.workspaceId);
|
|
166
|
+
if(comparablePath(planned.rootRef,this.platform)!==comparablePath(binding.rootRef,this.platform)||
|
|
167
|
+
planned.branch!==binding.branch||! /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(binding.baseCommit||""))
|
|
168
|
+
throw new Error("full_workspace_intent_mismatch");
|
|
169
|
+
await this.#parents(root);
|
|
170
|
+
const target=entries.find(x=>comparablePath(x.path,this.platform)===comparablePath(planned.rootRef,this.platform));
|
|
171
|
+
const other=entries.find(x=>x.branch===planned.branch&&x!==target);
|
|
172
|
+
if(other)throw new Error("full_workspace_branch_in_use");
|
|
173
|
+
const stat=await this.#exists(planned.rootRef);
|
|
174
|
+
if(stat&&(!stat.isDirectory()||stat.isSymbolicLink()||comparablePath(await fs.realpath(planned.rootRef),this.platform)!==comparablePath(planned.rootRef,this.platform)))
|
|
175
|
+
throw new Error("full_workspace_path_alias");
|
|
176
|
+
// Both Git observations are independent and read-only. Wait for both
|
|
177
|
+
// even on failure; no subprocess may outlive this admission boundary.
|
|
178
|
+
const results=await Promise.allSettled([
|
|
179
|
+
runGit(root,["check-ignore","-q","--",path.relative(root,planned.rootRef)],{safe:true,allowExitCodes:[1]}),
|
|
180
|
+
this.#branch(root,planned.branch)
|
|
181
|
+
]);
|
|
182
|
+
const failure=results.find(result=>result.status==="rejected");
|
|
183
|
+
if(failure)throw failure.reason;
|
|
184
|
+
if(!results[0].value.ok)throw new Error("full_workspace_directory_not_ignored");
|
|
185
|
+
return {root,planned,target,stat,branchHead:results[1].value};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async assertOwnedFresh(binding){
|
|
189
|
+
const view=await this.#ownedPlan(binding);
|
|
190
|
+
if(view.target||view.stat||view.branchHead)throw new Error("full_workspace_already_exists");
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Core broker holds the Git metadata + target claims. A durable pending
|
|
195
|
+
// binding (with immutable root, branch and base) must have been committed.
|
|
196
|
+
async provisionOwned(binding){
|
|
197
|
+
if(!["pending","failed","ready"].includes(binding?.state))throw new Error("full_workspace_intent_required");
|
|
198
|
+
const view=await this.#ownedPlan(binding),{root,planned,target,stat,branchHead}=view;
|
|
199
|
+
if(target){
|
|
200
|
+
if(!stat||target.detached||target.branch!==planned.branch||!branchHead||target.head!==branchHead)
|
|
201
|
+
throw new Error("full_workspace_reconciliation_required");
|
|
202
|
+
await this.#resolveAllowedExisting(planned.rootRef);
|
|
203
|
+
return {state:"ready",rootRef:planned.rootRef,branch:planned.branch,resumed:true};
|
|
204
|
+
}
|
|
205
|
+
if(binding.state==="ready")throw new Error("full_workspace_missing");
|
|
206
|
+
if(stat)throw new Error("full_workspace_unregistered_path");
|
|
207
|
+
if(branchHead&&branchHead!==binding.baseCommit)throw new Error("full_workspace_branch_changed");
|
|
208
|
+
await this.#parents(root,{create:true});
|
|
209
|
+
// No reset/force/cleanup on failure. If a branch was created before an
|
|
210
|
+
// interrupted checkout, a matching intent can resume that exact branch.
|
|
211
|
+
const args=branchHead?["worktree","add",planned.rootRef,planned.branch]:
|
|
212
|
+
["worktree","add","-b",planned.branch,planned.rootRef,binding.baseCommit];
|
|
213
|
+
await runGit(root,args,{safe:true,errorCode:"full_workspace_provision_failed"});
|
|
214
|
+
const after=await this.#ownedPlan(binding);
|
|
215
|
+
if(!after.target||!after.stat||after.target.branch!==planned.branch||after.target.head!==after.branchHead)
|
|
216
|
+
throw new Error("full_workspace_reconciliation_required");
|
|
217
|
+
return {state:"ready",rootRef:planned.rootRef,branch:planned.branch,resumed:false};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async inspectOwned(binding){
|
|
221
|
+
if(binding?.state!=="ready")throw new Error("full_workspace_not_ready");
|
|
222
|
+
return this.provisionOwned(binding);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async inspectShared(binding){
|
|
226
|
+
const {root,entries}=await this.#primary(binding.primaryRootRef);
|
|
227
|
+
if(comparablePath(root,this.platform)!==comparablePath(binding.primaryRootRef,this.platform))throw new Error("full_shared_workspace_changed");
|
|
228
|
+
const selected=entries.find(x=>comparablePath(x.path,this.platform)===comparablePath(binding.rootRef,this.platform));
|
|
229
|
+
if(!selected||selected.detached||selected.branch!==binding.branch||selected.branch.startsWith("relay-full/"))
|
|
230
|
+
throw new Error("full_shared_workspace_changed");
|
|
231
|
+
await this.#resolveAllowedExisting(selected.path);
|
|
232
|
+
return {state:"ready",rootRef:binding.rootRef,branch:selected.branch,attribution:"workspace-wide",baselineStatusFingerprint:binding.baselineStatusFingerprint};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async cleanupOwned(binding,{confirmed=false,checkInactive}={}){
|
|
236
|
+
if(!confirmed||typeof checkInactive!=="function"||await checkInactive()!==true)throw new Error("full_workspace_cleanup_blocked");
|
|
237
|
+
const {root,planned,target,stat}=await this.#ownedPlan(binding);
|
|
238
|
+
if(!target||!stat||target.detached||target.branch!==planned.branch||target.locked)throw new Error("full_workspace_cleanup_blocked");
|
|
239
|
+
const dirty=await runGit(planned.rootRef,["status","--porcelain=v1","-z","--untracked-files=all","--ignored=matching"],{safe:true});
|
|
240
|
+
if(dirty.stdout.length)throw new Error("full_workspace_dirty_or_ignored");
|
|
241
|
+
const merged=await runGit(root,["merge-base","--is-ancestor","refs/heads/"+planned.branch,"HEAD"],{safe:true,allowExitCodes:[1]});
|
|
242
|
+
if(!merged.ok)throw new Error("full_workspace_unmerged");
|
|
243
|
+
// Revalidate active work immediately before the destructive operation.
|
|
244
|
+
if(await checkInactive()!==true)throw new Error("full_workspace_cleanup_blocked");
|
|
245
|
+
await runGit(root,["worktree","remove",planned.rootRef],{safe:true,errorCode:"full_workspace_remove_failed"});
|
|
246
|
+
// Only the exact owned branch, no force or global prune.
|
|
247
|
+
try{await runGit(root,["branch","-d","--",planned.branch],{safe:true,errorCode:"full_workspace_branch_delete_failed"});}
|
|
248
|
+
catch{return {ok:false,worktreeRemoved:true,branchDeleted:false,branch:planned.branch,error:"full_workspace_branch_delete_failed"};}
|
|
249
|
+
return {ok:true,worktreeRemoved:true,branchDeleted:true,branch:planned.branch};
|
|
250
|
+
}
|
|
251
|
+
|
|
87
252
|
async cleanup(repoPathInput, worktreePathInput) {
|
|
88
253
|
let repoPath;
|
|
89
254
|
let worktreePath;
|
|
@@ -129,6 +294,7 @@ export class GitWorktreeManager {
|
|
|
129
294
|
return { ok: false, error: "primary_worktree_protected" };
|
|
130
295
|
}
|
|
131
296
|
if (target.detached || !target.branch) return { ok: false, error: "detached_worktree_not_supported" };
|
|
297
|
+
if(target.branch.startsWith("relay-full/"))return {ok:false,error:"full_workspace_requires_broker"};
|
|
132
298
|
if (DEFAULT_PROTECTED_BRANCHES.has(target.branch.toLowerCase())) {
|
|
133
299
|
return { ok: false, error: "protected_branch", branch: target.branch };
|
|
134
300
|
}
|
package/agent/lifecycle.mjs
CHANGED
|
@@ -34,6 +34,11 @@ const ALLOWED_WHILE_DRAINING = new Set([
|
|
|
34
34
|
"terminal.kill",
|
|
35
35
|
"terminal.list",
|
|
36
36
|
"terminal.observability",
|
|
37
|
+
"full.job.status",
|
|
38
|
+
"full.job.read",
|
|
39
|
+
"full.job.cancel",
|
|
40
|
+
"full.job.reconcile",
|
|
41
|
+
"full.diagnostics.snapshot",
|
|
37
42
|
]);
|
|
38
43
|
|
|
39
44
|
const ALLOWED_WHILE_FINALIZING = new Set([
|
|
@@ -57,10 +62,12 @@ export function summarizeAgentWork({ terminal = {}, scheduler = {}, desktop = {}
|
|
|
57
62
|
0,
|
|
58
63
|
);
|
|
59
64
|
const desktopControl = desktop.controlQueue || {};
|
|
65
|
+
const fullResources=scheduler.fullResources;
|
|
60
66
|
return {
|
|
61
67
|
activeSessions: Array.isArray(terminal.sessions)
|
|
62
68
|
? terminal.sessions.filter((item) => item?.status === "running").length
|
|
63
69
|
: 0,
|
|
70
|
+
...("drainingSessions" in terminal ? { drainingSessions: Math.max(0, Number(terminal.drainingSessions) || 0) } : {}),
|
|
64
71
|
activeBatchJobs: Math.max(0, Number(terminal.activeExecJobs) || 0),
|
|
65
72
|
queuedBatchJobs: Math.max(0, Number(terminal.queuedJobs) || 0),
|
|
66
73
|
activeTerminalExecs: Math.max(0, Number(terminalExec.active) || 0),
|
|
@@ -69,6 +76,7 @@ export function summarizeAgentWork({ terminal = {}, scheduler = {}, desktop = {}
|
|
|
69
76
|
queuedOtherJobs,
|
|
70
77
|
activeDesktopControls: Math.max(0, Number(desktopControl.active) || 0),
|
|
71
78
|
queuedDesktopControls: Math.max(0, Number(desktopControl.queued) || 0),
|
|
79
|
+
...(fullResources?{activeFullReservations:Math.max(0,Number(fullResources.active)||0),queuedFullReservations:Math.max(0,Number(fullResources.pending)||0),fullRecoveryBlocked:fullResources.recoveryBlocked?1:0}:{}),
|
|
72
80
|
};
|
|
73
81
|
}
|
|
74
82
|
|
|
@@ -76,6 +84,7 @@ function normalizeWork(value = {}) {
|
|
|
76
84
|
const count = (key) => Math.max(0, Number(value[key]) || 0);
|
|
77
85
|
const work = {
|
|
78
86
|
activeSessions: count("activeSessions"),
|
|
87
|
+
...("drainingSessions" in value ? { drainingSessions: count("drainingSessions") } : {}),
|
|
79
88
|
activeBatchJobs: count("activeBatchJobs"),
|
|
80
89
|
queuedBatchJobs: count("queuedBatchJobs"),
|
|
81
90
|
activeTerminalExecs: count("activeTerminalExecs"),
|
|
@@ -84,6 +93,8 @@ function normalizeWork(value = {}) {
|
|
|
84
93
|
queuedOtherJobs: count("queuedOtherJobs"),
|
|
85
94
|
activeDesktopControls: count("activeDesktopControls"),
|
|
86
95
|
queuedDesktopControls: count("queuedDesktopControls"),
|
|
96
|
+
...("activeFullReservations" in value?{activeFullReservations:count("activeFullReservations"),queuedFullReservations:count("queuedFullReservations"),fullRecoveryBlocked:count("fullRecoveryBlocked")}:{}),
|
|
97
|
+
...("activeFullRequests" in value?{activeFullRequests:count("activeFullRequests")}:{}),
|
|
87
98
|
};
|
|
88
99
|
work.total = Object.values(work).reduce((sum, item) => sum + item, 0);
|
|
89
100
|
return work;
|