@anusornneal/chat-relay 2.0.1 → 2.2.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.
- package/README.md +3 -1
- package/agent/activity-capture.mjs +176 -14
- package/agent/auto-session-binding.mjs +46 -0
- package/agent/file-manager.mjs +26 -6
- package/agent/full-coding-prepare.mjs +40 -0
- package/agent/full-desktop-broker.mjs +101 -21
- package/agent/full-remote-diagnostics.mjs +1 -1
- package/agent/full-session-dispatch.mjs +10 -3
- package/agent/full-workspace-broker.mjs +1 -1
- package/agent/git-worktree-manager.mjs +2 -1
- package/agent/local-agent.mjs +43 -5
- package/agent/local-usage.mjs +8 -0
- package/agent/monitor-activity.mjs +101 -18
- package/agent/presentation-redaction.mjs +1 -10
- package/agent/toolcall-context.mjs +43 -1
- package/agent/toolcall-summary.mjs +1 -1
- package/cli/full-launch.mjs +4 -22
- package/cli/full-release-default.json +2 -2
- package/cli/index.mjs +2 -2
- package/cli/remote.mjs +2 -2
- package/package.json +1 -1
- package/packages/full-contracts/auto-session.mjs +14 -0
- package/packages/full-contracts/monitor-metadata.mjs +28 -0
- package/packages/full-contracts/presentation-redaction.mjs +16 -0
- package/packages/full-contracts/remote-session.mjs +21 -2
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import {humanizeToolCall} from "./toolcall-summary.mjs";
|
|
2
|
+
import {activityPreview,redactPresentationText} from "./presentation-redaction.mjs";
|
|
2
3
|
import {activityIcon} from "./toolcall-context.mjs";
|
|
3
|
-
import {historicalDiff,projectActivityDetails} from "./activity-capture.mjs";
|
|
4
|
+
import {historicalDiff,projectActivityDetails,displayActivityPath,activityChangeTotals} from "./activity-capture.mjs";
|
|
5
|
+
import {monitorActivityId,normalizeLearnMonitorMetadata} from "../packages/full-contracts/monitor-metadata.mjs";
|
|
4
6
|
|
|
5
7
|
// The local monitor reuses Core's TUI activity projection. One bounded row per
|
|
6
8
|
// request (not one per start/end); never retain raw request bodies or output.
|
|
7
|
-
const
|
|
9
|
+
export const MAX_MONITOR_ROWS=100;
|
|
10
|
+
const DETAIL_TTL_MS=15*60*1000;
|
|
11
|
+
export const SESSION_IDLE_MS=60000,SESSION_HIDE_MS=15*60*1000;
|
|
12
|
+
const MAX_SESSION_PRESENCE=127;
|
|
13
|
+
const sessionId=value=>typeof value==="string"&&/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/.test(value)?value:null;
|
|
8
14
|
const clean=(value,n)=>typeof value==="string"?value.replace(/[\u0000-\u001f\u007f]/g," ").replace(/\s+/g," ").trim().slice(0,n).toWellFormed():"";
|
|
9
15
|
const code=value=>typeof value==="string"&&/^[A-Za-z0-9_.:-]{1,100}$/.test(value)?value:"tool";
|
|
10
|
-
const detailed=new Set(["fs.read","fs.write","fs.edit","fs.stat","fs.list","fs.readMany","fs.readMany.relative","fs.editMany","fs.batch","fs.batch.compact","terminal.exec","terminal.exec.compact","terminal.batch.start","terminal.batch.read","terminal.batch.read.compact","terminal.batch.status","terminal.read","terminal.read.compact","terminal.list"]);
|
|
16
|
+
const detailed=new Set(["fs.read","fs.write","fs.edit","fs.delete","fs.stat","fs.list","fs.readMany","fs.readMany.relative","fs.editMany","fs.batch","fs.batch.compact","terminal.exec","terminal.exec.compact","terminal.batch.start","terminal.batch.read","terminal.batch.read.compact","terminal.batch.status","terminal.read","terminal.read.compact","terminal.list"]);
|
|
11
17
|
const learnLabels={learn_prepare:"Load relevant Learn context",learn_get:"Read Learn memories",learn_put:"Update Learn memory",learn_delete:"Delete Learn memory",learn_feedback:"Rate Learn memory",learn_usage_report:"Report Learn usage"};
|
|
12
18
|
|
|
13
19
|
// Safe bounded metadata; never expose raw commands, search terms, edit bodies or output.
|
|
@@ -29,6 +35,7 @@ export function describeFullMonitorActivity(action,input={}){
|
|
|
29
35
|
case "full.intelligence.symbols":return "Find code symbols";
|
|
30
36
|
case "full.intelligence.dependencies":return "Inspect dependencies";
|
|
31
37
|
case "full.intelligence.impact":return "Review affected code";
|
|
38
|
+
case "full.coding.prepare":return "Prepare coding context";
|
|
32
39
|
case "full.session.ensure":return "Prepare task session";
|
|
33
40
|
case "full.session.list":return "List task sessions";
|
|
34
41
|
case "full.session.snapshot":return "Read task session";
|
|
@@ -60,42 +67,118 @@ export function describeFullMonitorActivity(action,input={}){
|
|
|
60
67
|
const bytes=value=>Number.isSafeInteger(value)&&value>=0?value:null;
|
|
61
68
|
const safeError=value=>typeof value==="string"&&/^[a-z][a-z0-9_]{1,95}$/.test(value)?value:"";
|
|
62
69
|
|
|
70
|
+
// Retain only a small, redacted display projection of output already delivered
|
|
71
|
+
// to the owner chat. No raw commands, replay requests, disk logs or extra RPCs.
|
|
72
|
+
export function observedTerminalResult(action,result){
|
|
73
|
+
if(!["terminal.exec","terminal.exec.compact","terminal.read","terminal.read.compact"].includes(action)||!result||typeof result!=="object")return null;
|
|
74
|
+
const exitCode=Number.isSafeInteger(result.exitCode)&&result.status!=="running"&&result.outputDraining!==true?result.exitCode:null;
|
|
75
|
+
const pieces=Array.isArray(result.chunks)?result.chunks.map(c=>typeof c?.text==="string"?c.text:""):[result.stdout,result.stderr].filter(v=>typeof v==="string");
|
|
76
|
+
const size=pieces.reduce((n,v)=>n+v.length,0);
|
|
77
|
+
// Redact before clipping; skip oversized output rather than scan unbounded text.
|
|
78
|
+
const safe=size<=65536?redactPresentationText(pieces.join(Array.isArray(result.chunks)?"":"\n"),size+1).trim():"";
|
|
79
|
+
const partial=size>65536||safe.length>2048||result.truncated===true||result.hasMore===true||result.outputIncomplete===true||Number(result.omittedChars)>0;
|
|
80
|
+
const text=safe.slice(-2048).toWellFormed()|| (partial?"Output omitted by capture limits or compact mode.":"");
|
|
81
|
+
if(!text&&exitCode===null&&!partial)return null;
|
|
82
|
+
return {text,exitCode,partial};
|
|
83
|
+
}
|
|
84
|
+
|
|
63
85
|
export function createMonitorActivity({now=()=>new Date()}={}){
|
|
64
|
-
const rows=new Map(),running=new
|
|
86
|
+
const rows=new Map(),running=new Map(),details=new Map(),presence=new Map(),outputs=new Map();
|
|
65
87
|
const localTime=new Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"});
|
|
66
88
|
let calls=0,errors=0,learnEvents=0,sequence=0;
|
|
67
|
-
|
|
89
|
+
// Session liveness is independent of the 100-row activity ring. Retain only
|
|
90
|
+
// bounded display metadata, so a burst of calls cannot hide an active chat.
|
|
91
|
+
const observe=(row)=>{
|
|
92
|
+
const id=sessionId(row.taskSessionId);if(!id)return;
|
|
93
|
+
const at=row.completedAt??Date.parse(row.at),previous=presence.get(id);
|
|
94
|
+
if(previous&&previous.at>at){
|
|
95
|
+
if(!previous.project&&row.project)previous.project=row.project;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
presence.delete(id);
|
|
99
|
+
presence.set(id,{taskSessionId:id,at,time:localTime.format(new Date(at)),project:row.project||previous?.project||"",failed:row.ok===false});
|
|
100
|
+
while(presence.size>MAX_SESSION_PRESENCE)presence.delete(presence.keys().next().value);
|
|
101
|
+
};
|
|
102
|
+
const remember=(key,row)=>{rows.set(key,row);observe(row);while(rows.size>MAX_MONITOR_ROWS){const first=rows.keys().next().value;details.delete(rows.get(first).requestId);outputs.delete(rows.get(first).requestId);rows.delete(first);}return row;};
|
|
68
103
|
const stamp=()=>{const at=now();return {at:at.toISOString(),time:localTime.format(at)};};
|
|
69
|
-
const prune=()=>{const cutoff=now().getTime()-DETAIL_TTL_MS;for(const row of rows.values())if(Date.parse(row.at)<cutoff)details.delete(row.requestId);};
|
|
104
|
+
const prune=()=>{const cutoff=now().getTime()-DETAIL_TTL_MS;for(const row of rows.values())if(Date.parse(row.at)<cutoff){details.delete(row.requestId);outputs.delete(row.requestId);}};
|
|
70
105
|
return {
|
|
71
106
|
accept(event,payload={}){
|
|
72
107
|
if(event==="tool:start"){
|
|
73
108
|
const key=payload.requestId;
|
|
74
109
|
if(typeof key!=="string"||running.has(key))return;
|
|
75
|
-
calls++;
|
|
110
|
+
calls++;
|
|
76
111
|
const action=code(payload.monitorAction??payload.action),category=action.startsWith("full.")?"Full":clean(payload.category,32)||"Agent";
|
|
77
112
|
// The TUI's descriptive operations are reused only for known routes
|
|
78
113
|
// that do not embed arbitrary request data. Search/filter and unknown
|
|
79
114
|
// arguments are deliberately not forwarded.
|
|
80
|
-
const label=action.startsWith("full.")?clean(payload.monitorOperation,128)||describeFullMonitorActivity(action):action==="terminal.start"?"Start background task":action.startsWith("fs.search.")?(action==="fs.search.start"?"Search project files":"Read search results"):detailed.has(action)?clean(payload.operation,128):humanizeToolCall({action});
|
|
81
|
-
remember(key,{requestId:"monitor-"+(++sequence),...stamp(),action,category,icon:activityIcon({action,category,operation:label})||(category==="Full"?"⚙":"·"),operation:label||humanizeToolCall({action}),project:clean(payload.project,64),taskSessionId:
|
|
115
|
+
const label=action.startsWith("full.")?clean(payload.monitorOperation,128)||describeFullMonitorActivity(action):action==="fs.artifact"?("Export "+(displayActivityPath(payload.detail).split("/").at(-1)||"file")):action==="terminal.start"?(payload.operation==="Commit changes"?"Commit changes":"Start background task"):action.startsWith("fs.search.")?(action==="fs.search.start"?"Search project files":"Read search results"):detailed.has(action)?clean(payload.operation,128):humanizeToolCall({action});
|
|
116
|
+
const row=remember(key,{requestId:"monitor-"+(++sequence),...stamp(),action,category,icon:activityIcon({action,category,operation:label})||(category==="Full"?"⚙":"·"),operation:label||humanizeToolCall({action}),project:clean(payload.project,64),taskSessionId:sessionId(payload.monitorTaskSessionId),status:"running",ok:null,durationMs:null,requestBytes:bytes(payload.requestBytes),responseBytes:null,error:"",pollKey:typeof payload.monitorPollKey==="string"&&/^[a-f0-9]{24}$/.test(payload.monitorPollKey)?payload.monitorPollKey:null,query:clean(payload.query,180),searchScope:clean(payload.searchScope,180),detail:detailed.has(action)||action==="terminal.start"&&label==="Commit changes"?clean(payload.detail,160):""});
|
|
117
|
+
running.set(key,row);
|
|
82
118
|
}else if(event==="tool:end"){
|
|
83
|
-
const key=payload.requestId;if(!running.delete(key)
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
119
|
+
const key=payload.requestId,row=running.get(key);if(!row)return;running.delete(key);
|
|
120
|
+
const terminal=payload.activityDetails?.terminal;
|
|
121
|
+
const exitCode=terminal?terminal.exitCode:payload.activityDetails?.exitCode;
|
|
122
|
+
const exitFailed=Number.isInteger(exitCode)&&exitCode!==0;
|
|
123
|
+
if(Number.isSafeInteger(exitCode))row.exitCode=exitCode;
|
|
124
|
+
if(rows.get(key)===row&&terminal&&(terminal.text||terminal.partial))outputs.set(row.requestId,terminal);
|
|
125
|
+
const failed=payload.ok===false||exitFailed;
|
|
126
|
+
if(failed)errors++;
|
|
127
|
+
{
|
|
128
|
+
if(rows.get(key)===row&&payload.activityDetails){
|
|
129
|
+
if(row.operation==="Commit changes"&&!failed&&payload.activityDetails.commitSubject)row.detail=activityPreview(payload.activityDetails.commitSubject,160);
|
|
130
|
+
const {commitSubject,terminal,...extra}=payload.activityDetails;
|
|
131
|
+
// A commit subject is already shown inline; no redundant expansion.
|
|
132
|
+
if(extra.files?.length||extra.omitted||extra.query||extra.searchScope||extra.exitCode!==null&&extra.exitCode!==undefined&&extra.exitCode!==0||extra.resultCount!==null&&extra.resultCount!==undefined)details.set(row.requestId,extra);
|
|
133
|
+
const totals=activityChangeTotals(payload.activityDetails);
|
|
134
|
+
if(totals)Object.assign(row,totals);
|
|
135
|
+
}
|
|
136
|
+
Object.assign(row,{status:payload.status==="cancelled"?"cancelled":failed?"failed":"done",ok:!failed,durationMs:bytes(payload.durationMs)===null?null:Math.min(86400000,payload.durationMs),responseBytes:bytes(payload.responseBytes),error:safeError(payload.error)||(exitFailed?"command_exit_nonzero":""),completedAt:now().getTime()});
|
|
137
|
+
observe(row);
|
|
88
138
|
}
|
|
89
139
|
}else if(event==="learn"){
|
|
90
140
|
learnEvents++;
|
|
91
141
|
const activity=payload.activity??{},tool=code(activity.tool);
|
|
92
|
-
const change=activity.change??{},rowId="learn-"+(++sequence)
|
|
142
|
+
const change=activity.change??{},rowId="learn-"+(++sequence),metadata=activity.ok===false?null:normalizeLearnMonitorMetadata(activity.metadata);
|
|
143
|
+
const retrieved=metadata?.retrieved;
|
|
144
|
+
const mutation=tool==="learn_put"&&activity.ok!==false&&["created","updated"].includes(change.type)&&change.key;
|
|
145
|
+
const summary=mutation?activityPreview(change.summary):"";
|
|
146
|
+
const operation=mutation&&change.type==="created"?"Add Learn memory":retrieved!==undefined?(tool==="learn_get"?"Read ":"Load ")+retrieved+(retrieved===1?" Learn memory":" Learn memories"):learnLabels[tool]||"Learn activity";
|
|
147
|
+
const detail=metadata?.evaluated!==undefined?metadata.evaluated+" evaluated · "+metadata.applied+" applied · "+metadata.verified+" verified":summary||[clean(change.key,100),clean(change.scope??activity.scopeSummary,50)].filter(Boolean).join(" · ");
|
|
148
|
+
remember(rowId,{requestId:rowId,...stamp(),conversationId:monitorActivityId(payload.monitorConversationId),taskSessionId:sessionId(payload.monitorTaskSessionId),action:"learn",category:"Learn",icon:"🧠",operation,project:clean(change.scope==="project"?change.scopeKey:activity.projectKey,64),detail:clean(detail,160),status:activity.ok===false?"failed":"done",ok:activity.ok!==false,durationMs:bytes(activity.durationMs)});
|
|
149
|
+
if(retrieved!==undefined&&retrieved>0)details.set(rowId,{files:[],omitted:0,learn:metadata});
|
|
150
|
+
else if(mutation)details.set(rowId,{files:[],omitted:0,learn:{change:{key:clean(change.key,100),scope:clean(change.scope,20),kind:clean(change.kind,40),summary}}});
|
|
93
151
|
}else return false;
|
|
94
152
|
return true;
|
|
95
153
|
},
|
|
96
|
-
snapshot(){
|
|
154
|
+
snapshot(){
|
|
155
|
+
prune();const current=now().getTime();
|
|
156
|
+
const activeIds=new Set();
|
|
157
|
+
for(const row of running.values()){
|
|
158
|
+
const id=sessionId(row.taskSessionId);
|
|
159
|
+
if(!id)continue;
|
|
160
|
+
activeIds.add(id);
|
|
161
|
+
if(!presence.has(id))observe(row);
|
|
162
|
+
}
|
|
163
|
+
for(const [id,entry] of presence)if(!activeIds.has(id)&¤t-entry.at>=SESSION_HIDE_MS)presence.delete(id);
|
|
164
|
+
const sessionPresence=[...presence.values()].map(({at,...entry})=>({...entry,ageMs:Math.max(0,current-at),working:activeIds.has(entry.taskSessionId)}));
|
|
165
|
+
return {calls,errors,active:running.size,learnEvents,sessionPresence,activity:[...rows.values()].slice(-MAX_MONITOR_ROWS).map(({conversationId,completedAt,...row})=>({...row,elapsedMs:row.status==="running"?Math.max(0,current-Date.parse(row.at)):null,hasDetails:details.has(row.requestId),...(outputs.has(row.requestId)?{hasOutput:true}:{})}))};
|
|
166
|
+
},
|
|
167
|
+
bindSession(requestId,taskSessionId){
|
|
168
|
+
const row=rows.get(requestId)??running.get(requestId);
|
|
169
|
+
if(!row||row.taskSessionId||!sessionId(taskSessionId))return false;
|
|
170
|
+
row.taskSessionId=taskSessionId;observe(row);return true;
|
|
171
|
+
},
|
|
172
|
+
bindConversation(conversationId,taskSessionId){
|
|
173
|
+
if(!monitorActivityId(conversationId)||typeof taskSessionId!=="string"||!/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/.test(taskSessionId))return false;
|
|
174
|
+
let changed=false;
|
|
175
|
+
for(const row of rows.values())if(row.conversationId===conversationId&&!row.taskSessionId){row.taskSessionId=taskSessionId;observe(row);changed=true;}
|
|
176
|
+
return changed;
|
|
177
|
+
},
|
|
97
178
|
forgetSession(taskSessionId){
|
|
98
|
-
|
|
179
|
+
presence.delete(taskSessionId);
|
|
180
|
+
for(const [key,row] of rows){if(row.taskSessionId===taskSessionId){details.delete(row.requestId);outputs.delete(row.requestId);rows.delete(key);}}
|
|
181
|
+
for(const row of running.values())if(row.taskSessionId===taskSessionId)row.taskSessionId=null;
|
|
99
182
|
},
|
|
100
183
|
detail(activityId,fileId){
|
|
101
184
|
prune();
|
|
@@ -105,7 +188,7 @@ export function createMonitorActivity({now=()=>new Date()}={}){
|
|
|
105
188
|
const file=detail?.files.find(f=>f.fileId===fileId);
|
|
106
189
|
return {activityId,fileId,...historicalDiff(file?.pair)};
|
|
107
190
|
}
|
|
108
|
-
return {activityId,...projectActivityDetails(detail)};
|
|
191
|
+
return {activityId,...projectActivityDetails(detail),...(detail?.learn?{learn:detail.learn}:{}),...(row&&outputs.has(activityId)?{terminal:outputs.get(activityId)}:{})};
|
|
109
192
|
}
|
|
110
193
|
};
|
|
111
194
|
}
|
|
@@ -1,10 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export function redactPresentationText(value,max=12000){
|
|
3
|
-
// Best-effort display redaction, not a claim to recognize arbitrary secrets.
|
|
4
|
-
return text(value,max).replace(/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g,"[private key redacted]")
|
|
5
|
-
.replace(/\b(Bearer\s+)[A-Za-z0-9._~+\/-]+/gi,"$1[redacted]")
|
|
6
|
-
.replace(/\b((?:password|passwd|secret|api[_-]?key|access[_-]?token|refresh[_-]?token|authorization)\s*[:=]\s*)(?:"[^"]*"|'[^']*'|[^\s,;]+)/gi,"$1[redacted]")
|
|
7
|
-
.replace(/\b(sk-[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9]{20,})\b/g,"[credential redacted]")
|
|
8
|
-
.replace(/(https?:\/\/)[^\s/@]+:[^\s/@]+@/gi,"$1[redacted]@")
|
|
9
|
-
.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g,"");
|
|
10
|
-
}
|
|
1
|
+
export {redactPresentationText,activityPreview} from "../packages/full-contracts/presentation-redaction.mjs";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { humanizeToolCall } from "./toolcall-summary.mjs";
|
|
3
|
+
import { activityPreview } from "./presentation-redaction.mjs";
|
|
3
4
|
|
|
4
5
|
export function activityCategory(item) {
|
|
5
6
|
if (item.category) return String(item.category);
|
|
@@ -146,11 +147,49 @@ function relativeLocation(value, project) {
|
|
|
146
147
|
return parts.length > 3 ? "…/" + parts.slice(-3).join("/") : normalized.slice(0, 130);
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
// Extract a literal commit subject, never the surrounding command.
|
|
151
|
+
function commitCommands(command){
|
|
152
|
+
if(typeof command!=="string"||command.length>16000)return [];
|
|
153
|
+
let start=0,quote="",escaped=false;
|
|
154
|
+
const segments=[];
|
|
155
|
+
for(let i=0;i<command.length;i++){
|
|
156
|
+
const c=command[i];
|
|
157
|
+
if(escaped){escaped=false;continue;}
|
|
158
|
+
if(c==="\\"&"e!=="'"){escaped=true;continue;}
|
|
159
|
+
if(quote){if(c===quote)quote="";continue;}
|
|
160
|
+
if(c==="'"||c==='"'){quote=c;continue;}
|
|
161
|
+
if(c===";"||c==="&"||c==="|"||c==="\n"){segments.push(command.slice(start,i));start=i+1;}
|
|
162
|
+
}
|
|
163
|
+
segments.push(command.slice(start));
|
|
164
|
+
return segments.filter(segment=>/^\s*git(?:\.exe)?\s+commit(?:\s|$)/i.test(segment));
|
|
165
|
+
}
|
|
166
|
+
function commitSubject(command){
|
|
167
|
+
for(const segment of commitCommands(command)){
|
|
168
|
+
const match=segment.match(/(?:^|\s)(?:-m\s+|--message(?:=|\s+))(["'])(.*?)\1(?:\s|$)/);
|
|
169
|
+
if(!match||!match[2]||/[\r\n]/.test(match[2])||match[1]==='"'&&/[$%\x60\\]/.test(match[2]))continue;
|
|
170
|
+
return activityPreview(match[2],160);
|
|
171
|
+
}
|
|
172
|
+
return "";
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Prefer the observed Git summary over a literal argument when available.
|
|
176
|
+
export function observedCommitSubject(command,stdout){
|
|
177
|
+
if(!commitCommands(command).length||typeof stdout!=="string")return "";
|
|
178
|
+
const lines=stdout.slice(-16000).split(/\r?\n/);
|
|
179
|
+
for(let i=lines.length-1;i>=0;i--){
|
|
180
|
+
const match=lines[i].match(/^\[[^\]\r\n]{1,200} [0-9a-f]{4,64}\] ([^\r\n]{1,1000})$/i);
|
|
181
|
+
if(match)return activityPreview(match[1],160);
|
|
182
|
+
}
|
|
183
|
+
return "";
|
|
184
|
+
}
|
|
185
|
+
|
|
149
186
|
function terminalTitle(payload) {
|
|
150
187
|
const command = String(payload.command || "");
|
|
188
|
+
if (commitCommands(command).length) return "Commit changes";
|
|
151
189
|
if (/\bGet-Command\s+(?:rg|ripgrep)\b/i.test(command)) return "Check ripgrep availability";
|
|
152
190
|
const toolCheck = command.match(/\bGet-Command\s+([a-z][a-z0-9.-]{0,25})\b/i);
|
|
153
191
|
if (toolCheck?.[1]) return "Check " + toolCheck[1] + " availability";
|
|
192
|
+
if (/\|\s*(?:Select-String|rg)\b/i.test(command)) return "Search command output";
|
|
154
193
|
if (/\b(?:Select-String|rg)\b/i.test(command) && !/Get-Command/i.test(command)) return "Search project files";
|
|
155
194
|
const npmScript = command.match(/\bnpm\s+run\s+([a-z][a-z0-9:_-]+)/i);
|
|
156
195
|
if (npmScript?.[1]) {
|
|
@@ -166,7 +205,6 @@ function terminalTitle(payload) {
|
|
|
166
205
|
if (/\bnode\s+--test\b/i.test(command)) return "Run unit tests";
|
|
167
206
|
if (/\bgit\s+diff\s+--check\b/i.test(command)) return "Validate Git changes";
|
|
168
207
|
if (/\bgit\s+status\b/i.test(command) && !/\bgit\s+commit\b/i.test(command)) return "Review Git status";
|
|
169
|
-
if (/\bgit\s+commit\b/i.test(command)) return "Commit changes";
|
|
170
208
|
if (/\bGet-ChildItem\b/i.test(command)) return "Inspect project files";
|
|
171
209
|
const translated = humanizeToolCall(payload).replace(/\s+· in [^·]+$/, "");
|
|
172
210
|
if (translated.startsWith("Run ")) {
|
|
@@ -199,6 +237,9 @@ export function describeToolActivity(payload = {}, allowedRoots = [], linkedCont
|
|
|
199
237
|
case "fs.write":
|
|
200
238
|
operation = (payload.mode === "append" ? "Append " : "Write ") + shortName(payload.path);
|
|
201
239
|
break;
|
|
240
|
+
case "fs.delete":
|
|
241
|
+
operation = "Delete " + shortName(payload.path);
|
|
242
|
+
break;
|
|
202
243
|
case "fs.edit":
|
|
203
244
|
operation = "Edit " + shortName(payload.path);
|
|
204
245
|
break;
|
|
@@ -226,6 +267,7 @@ export function describeToolActivity(payload = {}, allowedRoots = [], linkedCont
|
|
|
226
267
|
case "terminal.exec":
|
|
227
268
|
case "terminal.start":
|
|
228
269
|
operation = terminalTitle(payload);
|
|
270
|
+
if (operation === "Commit changes") detail = commitSubject(payload.command);
|
|
229
271
|
break;
|
|
230
272
|
case "terminal.batch.start":
|
|
231
273
|
operation = "Run " + count(payload.jobs) + " terminal tasks";
|
|
@@ -193,7 +193,7 @@ export function humanizeToolCall(payload = {}) {
|
|
|
193
193
|
case "fs.batch":
|
|
194
194
|
return `Inspect filesystem · ${Array.isArray(payload.operations) ? payload.operations.length : 0} operations`;
|
|
195
195
|
case "fs.artifact":
|
|
196
|
-
return `Export ${compactPath(payload.path)}
|
|
196
|
+
return payload.path ? `Export ${compactPath(payload.path)}` : "Export file";
|
|
197
197
|
case "fs.write": {
|
|
198
198
|
const bytes = Buffer.byteLength(String(payload.content ?? ""), "utf8");
|
|
199
199
|
const mode = payload.mode === "append" ? "append" : "replace file";
|
package/cli/full-launch.mjs
CHANGED
|
@@ -4,10 +4,8 @@ import {createHash,randomUUID} from "node:crypto";
|
|
|
4
4
|
import {configDir} from "./config.mjs";
|
|
5
5
|
import {getAgentVersion} from "../agent/protocol.mjs";
|
|
6
6
|
import {prepareFullArtifact} from "./full-prepare.mjs";
|
|
7
|
-
import {regularFile
|
|
8
|
-
import {
|
|
9
|
-
import {officialFullSettings} from "./full-release-official.mjs";
|
|
10
|
-
import {ModError,MAX_MANIFEST_BYTES} from "./mod-manifest.mjs";
|
|
7
|
+
import {regularFile} from "./full-release-files.mjs";
|
|
8
|
+
import {ModError} from "./mod-manifest.mjs";
|
|
11
9
|
|
|
12
10
|
const require=(ok,code)=>{if(!ok)throw new ModError(code);};
|
|
13
11
|
export function supportedFullNode(version=process.versions.node){
|
|
@@ -17,24 +15,8 @@ export function supportedFullNode(version=process.versions.node){
|
|
|
17
15
|
const atLeast=(m,p)=>minor>m||minor===m&&patch>=p;
|
|
18
16
|
return major===22&&atLeast(23,4)||major===24&&atLeast(22,1)||major===26&&atLeast(12,1)||major>26;
|
|
19
17
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// No release URL, key or version from relay payloads.
|
|
23
|
-
let raw;
|
|
24
|
-
try{raw=JSON.parse((await readBounded(path.join(home,"full-release.json"),MAX_MANIFEST_BYTES)).toString("utf8"));}
|
|
25
|
-
catch(error){if(error.code==="ENOENT")return officialFullSettings({headless});throw new ModError("full_invalid_release_configuration");}
|
|
26
|
-
require(raw&&typeof raw==="object"&&!Array.isArray(raw)&&Object.keys(raw).every(k=>["headlessVersion","guiVersion","trustedKeys","sourceDirectory","guiSourceDirectory","sourceUrl","guiSourceUrl"].includes(k)),"full_invalid_release_configuration");
|
|
27
|
-
const requestedVersion=headless?raw.headlessVersion:raw.guiVersion;
|
|
28
|
-
require(typeof requestedVersion==="string"&&/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[A-Za-z0-9.-]+)?$/.test(requestedVersion)&&requestedVersion.length<=64,"full_invalid_release_configuration");
|
|
29
|
-
const entries=Object.entries(raw.trustedKeys??{});
|
|
30
|
-
require(raw.trustedKeys&&typeof raw.trustedKeys==="object"&&!Array.isArray(raw.trustedKeys)&&entries.length>=1&&entries.length<=8&&entries.every(([key,value])=>/^[A-Za-z0-9_-]{1,64}$/.test(key)&&typeof value==="string"&&value.length<=1024&&value.includes("BEGIN PUBLIC KEY")),"full_invalid_release_configuration");
|
|
31
|
-
for(const value of [raw.sourceDirectory,raw.guiSourceDirectory])require(value===undefined||typeof value==="string"&&path.isAbsolute(value),"full_invalid_release_configuration");
|
|
32
|
-
for(const url of [raw.sourceUrl,raw.guiSourceUrl])if(url!==undefined)releaseSourceUrl(url);
|
|
33
|
-
const sourceDirectory=headless?raw.sourceDirectory:raw.guiSourceDirectory??(raw.guiSourceUrl?undefined:raw.sourceDirectory);
|
|
34
|
-
const sourceUrl=headless?raw.sourceUrl:raw.guiSourceUrl??(raw.guiSourceDirectory?undefined:raw.sourceUrl);
|
|
35
|
-
require(!(sourceDirectory&&sourceUrl),"full_invalid_release_configuration");
|
|
36
|
-
return {headless,requestedVersion,trustedKeys:new Map(entries),sourceDirectory,sourceUrl};
|
|
37
|
-
}
|
|
18
|
+
// The public launcher uses only the release-specific pin bundled with Core.
|
|
19
|
+
export {officialFullSettings as readFullReleaseSettings} from "./full-release-official.mjs";
|
|
38
20
|
export function fullStateDirectory(home,{relayUrl,agentId}){
|
|
39
21
|
require(typeof relayUrl==="string"&&typeof agentId==="string"&&/^[a-z0-9_-]{1,64}$/.test(agentId),"full_invalid_host_configuration");
|
|
40
22
|
const normalized=new URL(relayUrl);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "2.0
|
|
3
|
-
"publicKey": "-----BEGIN PUBLIC KEY-----\
|
|
2
|
+
"version": "2.2.0",
|
|
3
|
+
"publicKey": "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAaE+ab0fqmb3MqNkmdmJe7vojF0ZNZlP/99ZkQ21UYNY=\n-----END PUBLIC KEY-----\n"
|
|
4
4
|
}
|
package/cli/index.mjs
CHANGED
|
@@ -244,7 +244,7 @@ async function logout() {
|
|
|
244
244
|
return 0;
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
export async function runCli(argv = process.argv.slice(2)) {
|
|
247
|
+
export async function runCli(argv = process.argv.slice(2), dependencies) {
|
|
248
248
|
const command = (argv[0] || "remote").toLowerCase();
|
|
249
249
|
const { options } = parseOptions(argv.slice(1));
|
|
250
250
|
|
|
@@ -273,7 +273,7 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
273
273
|
if (command === "restart") return lifecycleAction("restart");
|
|
274
274
|
if (command === "upgrade") return lifecycleAction("upgrade");
|
|
275
275
|
if (command === "remote") {
|
|
276
|
-
const remoteCode = (await remote({...options,launchArgs:argv})) || 0;
|
|
276
|
+
const remoteCode = (await remote({...options,launchArgs:argv},dependencies)) || 0;
|
|
277
277
|
if (remoteCode === AGENT_UPGRADE_EXIT_CODE) {
|
|
278
278
|
const relaunched = launchLatestRemote(options);
|
|
279
279
|
if (!relaunched.ok) {
|
package/cli/remote.mjs
CHANGED
|
@@ -138,13 +138,13 @@ function openDesktopOnChild(child, accountId) {
|
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
export async function remote(options = {}) {
|
|
141
|
+
export async function remote(options = {}, {loadReleaseSettings} = {}) {
|
|
142
142
|
const background=createBackgroundHandoff();
|
|
143
143
|
let fullSettings=null, prepareFullLaunch=null, localFullPrincipal=null;
|
|
144
144
|
if (options.full === true) {
|
|
145
145
|
try {
|
|
146
146
|
const full=await import("./full-launch.mjs");
|
|
147
|
-
fullSettings=await full.readFullReleaseSettings({headless:options.headless===true});
|
|
147
|
+
fullSettings=await (loadReleaseSettings??full.readFullReleaseSettings)({headless:options.headless===true});
|
|
148
148
|
if(!full.supportedFullNode())throw Object.assign(new Error("Unsupported Node.js"),{code:"full_node_unsupported"});
|
|
149
149
|
prepareFullLaunch=full.prepareFullLaunch;
|
|
150
150
|
localFullPrincipal=full.localFullPrincipal;
|
package/package.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Conversation metadata is an attribution hint, never authorization.
|
|
2
|
+
// Only the already authorized Worker may construct the internal envelope.
|
|
3
|
+
const account=value=>typeof value==="string"&&/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/.test(value);
|
|
4
|
+
const activity=value=>typeof value==="string"&&/^act_[a-f0-9]{20}$/.test(value);
|
|
5
|
+
export function automaticSessionContext({accountId,activityId,reliableIdentity,scopes,action}={}){
|
|
6
|
+
if(reliableIdentity!==true||!account(accountId)||!activity(activityId)||
|
|
7
|
+
!Array.isArray(scopes)||!["read","write"].every(s=>scopes.includes("*")||scopes.includes(s))||
|
|
8
|
+
typeof action!=="string"||! /^(?:fs|terminal|git|desktop|process)\./.test(action))return undefined;
|
|
9
|
+
return {accountId,activityId};
|
|
10
|
+
}
|
|
11
|
+
export function validAutomaticSessionContext(value){
|
|
12
|
+
return !!value&&typeof value==="object"&&!Array.isArray(value)&&
|
|
13
|
+
Object.keys(value).length===2&&account(value.accountId)&&activity(value.activityId);
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// A small, content-free projection shared by Worker, relay and local monitor.
|
|
2
|
+
const scopes=new Set(["global","project","agent"]);
|
|
3
|
+
const kinds=new Set(["preference","response_style","work_style","coding_style","problem_solving","project_context","tool_pattern","workflow","correction","agent_context"]);
|
|
4
|
+
const count=value=>Number.isSafeInteger(value)&&value>=0&&value<=100?value:undefined;
|
|
5
|
+
const key=value=>typeof value==="string"&&/^[a-z0-9][a-z0-9_.:-]{0,79}$/.test(value)&&! /^(?:sk-|gh[pousr]_)/i.test(value)?value:null;
|
|
6
|
+
export const monitorAccountId=value=>typeof value==="string"&&/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/.test(value)?value:null;
|
|
7
|
+
export const monitorActivityId=value=>typeof value==="string"&&/^act_[a-f0-9]{20}$/.test(value)?value:null;
|
|
8
|
+
export function normalizeLearnMonitorMetadata(value){
|
|
9
|
+
if(!value||typeof value!=="object"||Array.isArray(value))return null;
|
|
10
|
+
const retrieved=count(value.retrieved);
|
|
11
|
+
if(retrieved!==undefined){
|
|
12
|
+
const items=[];
|
|
13
|
+
for(const item of (Array.isArray(value.items)?value.items:[]).slice(0,8)){
|
|
14
|
+
const name=key(item?.key);
|
|
15
|
+
if(name&&scopes.has(item.scope)&&kinds.has(item.kind))items.push({key:name,scope:item.scope,kind:item.kind});
|
|
16
|
+
}
|
|
17
|
+
return {retrieved,items:items.slice(0,retrieved)};
|
|
18
|
+
}
|
|
19
|
+
const evaluated=count(value.evaluated),applied=count(value.applied),verified=count(value.verified);
|
|
20
|
+
if(evaluated===undefined||applied===undefined||verified===undefined||applied>evaluated||verified>applied)return null;
|
|
21
|
+
return {evaluated,applied,verified};
|
|
22
|
+
}
|
|
23
|
+
export function learnMonitorMetadata(tool,body){
|
|
24
|
+
if(!body||typeof body!=="object")return null;
|
|
25
|
+
if(tool==="learn_usage_report")return normalizeLearnMonitorMetadata(body);
|
|
26
|
+
const items=tool==="learn_prepare"?body.preparedContext?.items:tool==="learn_get"?body.items:null;
|
|
27
|
+
return Array.isArray(items)?normalizeLearnMonitorMetadata({retrieved:Math.min(items.length,100),items}):null;
|
|
28
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const text=(v,n=512)=>typeof v==="string"?v.slice(0,n).toWellFormed():"";
|
|
2
|
+
export function redactPresentationText(value,max=12000){
|
|
3
|
+
// Best-effort display redaction, not a claim to recognize arbitrary secrets.
|
|
4
|
+
return text(value,max).replace(/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g,"[private key redacted]")
|
|
5
|
+
.replace(/\b(Bearer\s+)[A-Za-z0-9._~+\/-]+/gi,"$1[redacted]")
|
|
6
|
+
.replace(/\b((?:password|passwd|secret|api[_-]?key|access[_-]?token|refresh[_-]?token|authorization)\s*[:=]\s*)(?:"[^"]*"|'[^']*'|[^\s,;]+)/gi,"$1[redacted]")
|
|
7
|
+
.replace(/\b(sk-[A-Za-z0-9_-]{16,}|gh[pousr]_[A-Za-z0-9]{20,})\b/g,"[credential redacted]")
|
|
8
|
+
.replace(/(https?:\/\/)[^\s/@]+:[^\s/@]+@/gi,"$1[redacted]@")
|
|
9
|
+
.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g,"");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Redact before truncating so credentials crossing the preview boundary stay hidden.
|
|
13
|
+
export function activityPreview(value,max=320){
|
|
14
|
+
if(typeof value!=="string"||value.length>16000)return "";
|
|
15
|
+
return redactPresentationText(value,value.length).replace(/\s+/g," ").trim().slice(0,max).toWellFormed();
|
|
16
|
+
}
|
|
@@ -7,9 +7,11 @@ const record=value=>value!==null&&typeof value==="object"&&!Array.isArray(value)
|
|
|
7
7
|
const require=(condition,code)=>{if(!condition)throw new FullContractError(code);};
|
|
8
8
|
const exact=(value,fields)=>record(value)&&Object.keys(value).every(key=>fields.includes(key));
|
|
9
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
|
+
// Core-only composition of existing authorized Full operations, not a host operation.
|
|
11
|
+
export const CODING_PREPARE_OPERATION="full.coding.prepare";
|
|
10
12
|
const descriptors={
|
|
11
13
|
"full.session.ensure":{fields:["intent","taskSessionId","idempotencyKey","title","projectKey"],write:true},
|
|
12
|
-
"full.session.list":{fields:["after","limit"]},
|
|
14
|
+
"full.session.list":{fields:["after","limit","monitorSessionIds"]},
|
|
13
15
|
"full.session.snapshot":{fields:["taskSessionId","consumerId","cursor"],session:true},
|
|
14
16
|
"full.session.acknowledge":{fields:["taskSessionId","consumerId","cursor","revision"],session:true},
|
|
15
17
|
"full.task.checkpoint":{fields:["taskSessionId","expectedRevision","facts"],session:true,write:true},
|
|
@@ -40,6 +42,7 @@ const descriptors={
|
|
|
40
42
|
"full.diagnostics.export":{fields:["taskSessionId","confirmed"],session:true},
|
|
41
43
|
"full.desktop.windows":{fields:["taskSessionId","limit"],session:true,desktopRead:true},
|
|
42
44
|
"full.desktop.step":{fields:["taskSessionId","idempotencyKey","actions","settleMs"],session:true,write:true,desktopControl:true},
|
|
45
|
+
[CODING_PREPARE_OPERATION]:{fields:["taskSessionId","idempotencyKey","title","projectKey","repoPath","taskContext"],write:true},
|
|
43
46
|
"full.session.export":{fields:["taskSessionId","confirmed","cursor"],session:true},
|
|
44
47
|
"full.session.delete":{fields:["taskSessionId","confirmed","expectedRevision"],session:true,write:true}
|
|
45
48
|
};
|
|
@@ -75,11 +78,27 @@ export function parseRemoteFullRequest(value){
|
|
|
75
78
|
const input=record(value.input)?{...value.input}:value.input;
|
|
76
79
|
require(exact(input,descriptor.fields),"full_invalid_remote_input");
|
|
77
80
|
if(descriptor.session||Object.hasOwn(input,"taskSessionId"))require(id(input.taskSessionId),"full_invalid_session_id");
|
|
81
|
+
if(operation==="full.session.list"&&Object.hasOwn(input,"monitorSessionIds"))require(Array.isArray(input.monitorSessionIds)&&input.monitorSessionIds.length<=128&&input.monitorSessionIds.every(id)&&new Set(input.monitorSessionIds).size===input.monitorSessionIds.length,"full_invalid_page");
|
|
78
82
|
if(operation==="full.session.ensure"){
|
|
79
83
|
require(["create","ensure","resume","new-attempt"].includes(input.intent)&&id(input.idempotencyKey),"full_invalid_intent");
|
|
80
84
|
if(["resume","new-attempt"].includes(input.intent))require(id(input.taskSessionId),"full_invalid_session_id");
|
|
81
85
|
if(input.intent==="create")require(!Object.hasOwn(input,"taskSessionId"),"full_invalid_session_id");
|
|
82
86
|
}
|
|
87
|
+
if(operation===CODING_PREPARE_OPERATION){
|
|
88
|
+
const existing=Object.hasOwn(input,"taskSessionId"),creating=Object.hasOwn(input,"idempotencyKey");
|
|
89
|
+
require(existing!==creating,"full_coding_session_identity_required");
|
|
90
|
+
if(existing)require(input.title===undefined&&input.projectKey===undefined,"full_invalid_remote_input");
|
|
91
|
+
else {
|
|
92
|
+
require(id(input.idempotencyKey)&&input.repoPath!==undefined,"full_invalid_remote_input");
|
|
93
|
+
require(input.title===undefined||typeof input.title==="string"&&input.title.length<=256&&input.title.isWellFormed(),"full_invalid_remote_input");
|
|
94
|
+
require(input.projectKey===undefined||typeof input.projectKey==="string"&&input.projectKey.length<=200&&input.projectKey.isWellFormed(),"full_invalid_remote_input");
|
|
95
|
+
}
|
|
96
|
+
// Existing sessions may reuse their already verified binding without a path.
|
|
97
|
+
// Supplying a path permits shared checkout binding only, never provisioning.
|
|
98
|
+
if(input.repoPath!==undefined)parseRemoteFullRequest({operation:"full.workspace.ensure",input:{taskSessionId:"validation",kind:"git",repoPath:input.repoPath}});
|
|
99
|
+
require(Object.hasOwn(input,"taskContext"),"full_invalid_task_context");
|
|
100
|
+
parseRemoteFullRequest({operation:"full.intelligence.refresh",input:{taskSessionId:"validation",taskContext:input.taskContext}});
|
|
101
|
+
}
|
|
83
102
|
if(operation==="full.session.export"){
|
|
84
103
|
require(input.confirmed===true,"full_export_confirmation_required");
|
|
85
104
|
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");
|
|
@@ -96,7 +115,7 @@ export function parseRemoteFullRequest(value){
|
|
|
96
115
|
const boundedPath=value=>typeof value==="string"&&value.length>0&&value.length<=512&&!/[\u0000-\u001f]/.test(value);
|
|
97
116
|
if(input.kind==="git"){
|
|
98
117
|
require(!has("artifactRoot"),"full_invalid_workspace_mode");
|
|
99
|
-
input.mode
|
|
118
|
+
if(input.mode===undefined){input.mode="shared";input.sharedPath=input.sharedPath??input.repoPath;}
|
|
100
119
|
require(["isolated","main","shared"].includes(input.mode),"full_invalid_workspace_mode");
|
|
101
120
|
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
121
|
require(boundedPath(input.repoPath),"full_invalid_resource_path");
|