@andorra-labs/code 0.1.9 → 0.1.10
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/dist/src/agent-execution.js +20 -0
- package/dist/src/app-server/protocol.d.ts +108 -1
- package/dist/src/app-server/protocol.js +8 -1
- package/dist/src/app-server.d.ts +25 -0
- package/dist/src/app-server.js +156 -11
- package/dist/src/auth/index.d.ts +1 -1
- package/dist/src/auth/index.js +1 -1
- package/dist/src/auth/store.d.ts +17 -1
- package/dist/src/auth/store.js +25 -2
- package/dist/src/browser-ui/app.js +19 -19
- package/dist/src/browser-ui/index.html +7 -7
- package/dist/src/cli.js +10 -5
- package/dist/src/commands.d.ts +1 -1
- package/dist/src/commands.js +1 -1
- package/dist/src/completion-gates.js +1 -1
- package/dist/src/completion.d.ts +1 -1
- package/dist/src/completion.js +1 -1
- package/dist/src/decision/checks.js +1 -1
- package/dist/src/file-diff.d.ts +105 -0
- package/dist/src/file-diff.js +244 -0
- package/dist/src/graph-manager-chat.js +15 -15
- package/dist/src/graph-server.js +9 -9
- package/dist/src/graph-ui/app.js +123 -118
- package/dist/src/graph-ui/embed.js +9 -9
- package/dist/src/graph-ui/icons.js +1 -0
- package/dist/src/graph-ui/index.html +3 -3
- package/dist/src/graph-ui/manager-state.js +3 -3
- package/dist/src/graph-ui/manager.js +14 -14
- package/dist/src/graph-ui/skill-picker.js +6 -6
- package/dist/src/graph-ui/studio-canvas.js +15 -15
- package/dist/src/graph-ui/studio.js +40 -40
- package/dist/src/graph-ui/style.css +3 -1
- package/dist/src/graph-ui/theme.js +2 -2
- package/dist/src/graphs.d.ts +7 -1
- package/dist/src/graphs.js +12 -2
- package/dist/src/mcp.d.ts +75 -0
- package/dist/src/mcp.js +240 -8
- package/dist/src/membership-errors.js +1 -1
- package/dist/src/provider-keys.d.ts +5 -1
- package/dist/src/provider-keys.js +7 -3
- package/dist/src/provider-settings.d.ts +4 -1
- package/dist/src/provider-settings.js +46 -5
- package/dist/src/qa/guidance.js +6 -19
- package/dist/src/qa/index.d.ts +0 -2
- package/dist/src/qa/index.js +0 -2
- package/dist/src/qa/profile/QaProfile.d.ts +5 -1
- package/dist/src/qa/profile/QaProfile.js +6 -2
- package/dist/src/qa/tools.d.ts +19 -1
- package/dist/src/qa/tools.js +20 -145
- package/dist/src/react-runtime.js +13 -2
- package/dist/src/remote/engine-pool.js +18 -6
- package/dist/src/screen-selection.d.ts +38 -0
- package/dist/src/screen-selection.js +103 -0
- package/dist/src/session-changes.d.ts +117 -0
- package/dist/src/session-changes.js +796 -0
- package/dist/src/stall-recovery.d.ts +11 -0
- package/dist/src/stall-recovery.js +12 -0
- package/dist/src/telemetry/schema.d.ts +1 -1
- package/dist/src/telemetry/schema.js +1 -2
- package/dist/src/terminal-ui.d.ts +64 -20
- package/dist/src/terminal-ui.js +310 -80
- package/dist/src/tool-diff-stats.d.ts +9 -0
- package/dist/src/tool-diff-stats.js +20 -0
- package/dist/src/tool-names.d.ts +1 -1
- package/dist/src/tool-result-filter.js +1 -1
- package/dist/src/tools.js +26 -2
- package/dist/src/transcript.d.ts +11 -0
- package/dist/src/transcript.js +14 -2
- package/dist/src/types.d.ts +6 -0
- package/docs/guides/desktop-app.md +1 -1
- package/docs/guides/tui.md +9 -9
- package/package.json +1 -1
- package/dist/src/qa/api/http-runner.d.ts +0 -3
- package/dist/src/qa/api/http-runner.js +0 -47
- package/dist/src/qa/git/ChangeDetector.d.ts +0 -26
- package/dist/src/qa/git/ChangeDetector.js +0 -177
- package/dist/src/qa/git/DiffReviewer.d.ts +0 -28
- package/dist/src/qa/git/DiffReviewer.js +0 -115
- package/dist/src/qa/orchestrator/ChangeClassifier.d.ts +0 -14
- package/dist/src/qa/orchestrator/ChangeClassifier.js +0 -28
- package/dist/src/qa/orchestrator/MergeGate.d.ts +0 -14
- package/dist/src/qa/orchestrator/MergeGate.js +0 -40
- package/dist/src/qa/orchestrator/QaOrchestrator.d.ts +0 -79
- package/dist/src/qa/orchestrator/QaOrchestrator.js +0 -373
- package/dist/src/qa/runners/CommandRunner.d.ts +0 -22
- package/dist/src/qa/runners/CommandRunner.js +0 -96
- package/dist/src/qa/runners/TestRunner.d.ts +0 -21
- package/dist/src/qa/runners/TestRunner.js +0 -66
- package/dist/src/qa/runtime/RuntimeSmoke.d.ts +0 -11
- package/dist/src/qa/runtime/RuntimeSmoke.js +0 -78
- package/dist/src/qa/runtime-detect.d.ts +0 -10
- package/dist/src/qa/runtime-detect.js +0 -72
- package/dist/src/qa/security/DependencyScanner.d.ts +0 -19
- package/dist/src/qa/security/DependencyScanner.js +0 -167
- package/dist/src/qa/security/SecretScanner.d.ts +0 -3
- package/dist/src/qa/security/SecretScanner.js +0 -55
package/dist/src/qa/tools.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { clipText } from '../text.js';
|
|
2
|
-
import {
|
|
2
|
+
import { deriveProfile } from './profile/ProjectInspector.js';
|
|
3
|
+
import { runBrowserQa } from './browser/PlaywrightRunner.js';
|
|
3
4
|
import { createQaAuthorizer } from './qa-authorize.js';
|
|
4
5
|
import { assertNotHostKill } from '../host-process-guard.js';
|
|
5
6
|
import { getQaPtyManager } from './runtime/PtyManager.js';
|
|
6
|
-
const RESULT_LIMIT = 25;
|
|
7
7
|
const ERROR_LIMIT = 20;
|
|
8
8
|
function compactResult(result) {
|
|
9
9
|
return {
|
|
@@ -15,36 +15,17 @@ function compactResult(result) {
|
|
|
15
15
|
...(result.repairExhausted ? { repairExhausted: true } : {}),
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
summary: reportText(report),
|
|
30
|
-
}), 24_000);
|
|
31
|
-
}
|
|
32
|
-
function reportEventOutput(output) {
|
|
33
|
-
try {
|
|
34
|
-
const parsed = JSON.parse(output);
|
|
35
|
-
return JSON.stringify({ runId: parsed.runId, verdict: parsed.verdict, results: parsed.results?.map(result => ({ id: result.id, status: result.status })) });
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
return output.slice(0, 500);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function validateStringArray(value, name, max) {
|
|
42
|
-
if (value === undefined)
|
|
43
|
-
return undefined;
|
|
44
|
-
if (!Array.isArray(value) || value.length > max || value.some(item => typeof item !== 'string' || !item || item.length > 1024))
|
|
45
|
-
throw new Error(`${name} must be an array of at most ${max} nonempty strings`);
|
|
46
|
-
return value;
|
|
47
|
-
}
|
|
18
|
+
/**
|
|
19
|
+
* The host work behind qa.browser, behind one seam so a test can stand in for the browser and
|
|
20
|
+
* observe that permission was decided before it ran.
|
|
21
|
+
*/
|
|
22
|
+
export const qaBrowserHost = {
|
|
23
|
+
async check(options) {
|
|
24
|
+
const { profile } = await deriveProfile(options.workspace);
|
|
25
|
+
const outcome = await runBrowserQa({ workspace: options.workspace, profile, ...(options.url ? { url: options.url } : {}), ...(options.accessibility !== undefined ? { accessibility: options.accessibility } : {}), signal: options.signal });
|
|
26
|
+
return [outcome.smoke, outcome.consoleErrors, outcome.networkErrors, ...(outcome.accessibility ? [outcome.accessibility] : [])];
|
|
27
|
+
},
|
|
28
|
+
};
|
|
48
29
|
function assertTerminalApplication(command) {
|
|
49
30
|
const trimmed = command.trim();
|
|
50
31
|
const first = /^(?:"([^"]+)"|'([^']+)'|(\S+))/.exec(trimmed)?.slice(1).find(Boolean)?.toLowerCase() ?? '';
|
|
@@ -65,71 +46,14 @@ function assertTerminalApplication(command) {
|
|
|
65
46
|
}
|
|
66
47
|
}
|
|
67
48
|
}
|
|
68
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* The LLM-facing QA tools: a terminal to drive a CLI or TUI and a browser page check. All command
|
|
51
|
+
* execution is permission-gated. The check pipeline that used to sit beside them (qa.fast,
|
|
52
|
+
* qa.test, qa.deep, qa.security, qa.status, qa.inspect_project) is gone: an agent verifies a
|
|
53
|
+
* change with the project's own commands through its shell.
|
|
54
|
+
*/
|
|
69
55
|
export function createQaTools() {
|
|
70
56
|
return [
|
|
71
|
-
{
|
|
72
|
-
name: 'qa.inspect_project',
|
|
73
|
-
family: 'qa',
|
|
74
|
-
executionMode: 'sequential',
|
|
75
|
-
description: 'Report the derived QA profile for this workspace: language, framework, package manager, the lint/typecheck/unit/build/e2e commands QA will run, detected runtime tools, current changed files and their classification, and any .andorra/qa.yaml validation error. Read-only; runs no commands.',
|
|
76
|
-
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
77
|
-
execute: async (_args, context) => {
|
|
78
|
-
const orchestrator = getQaOrchestrator(context.workspace);
|
|
79
|
-
const summary = await orchestrator.profileSummary(context.signal);
|
|
80
|
-
const snapshot = await orchestrator.changeSnapshot(context.signal);
|
|
81
|
-
return `${summary}\nchanged files (${snapshot.changedFiles.length}): ${snapshot.changedFiles.slice(0, 60).join(', ') || 'none'}\nclassification: ${Object.entries(snapshot.classification).filter(([, active]) => active).map(([name]) => name).join(', ') || 'none'}`;
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
name: 'qa.fast',
|
|
86
|
-
family: 'qa',
|
|
87
|
-
executionMode: 'sequential',
|
|
88
|
-
description: 'Run the fast QA pipeline over the current working tree: lint, typecheck, unit tests related to changed files, then automated diff review and secret scan (redacted). Set includeBuild when the build matters (packaging or build-config changes). After any fix, re-run this before trusting the result.',
|
|
89
|
-
parameters: {
|
|
90
|
-
type: 'object',
|
|
91
|
-
properties: { includeBuild: { type: 'boolean', description: 'Also run the build check; default false' } },
|
|
92
|
-
additionalProperties: false,
|
|
93
|
-
},
|
|
94
|
-
execute: async (args, context) => {
|
|
95
|
-
if (args.includeBuild !== undefined && typeof args.includeBuild !== 'boolean')
|
|
96
|
-
throw new Error('includeBuild must be a boolean');
|
|
97
|
-
const orchestrator = getQaOrchestrator(context.workspace);
|
|
98
|
-
const authorizer = createQaAuthorizer('qa.fast', context);
|
|
99
|
-
authorizer.assertPlanned(orchestrator.plannedCommands(await orchestrator.getProfile(context.signal)));
|
|
100
|
-
const report = await orchestrator.fast({ includeBuild: args.includeBuild === true, signal: context.signal, authorize: command => authorizer.authorize(command) });
|
|
101
|
-
return reportOutput(report);
|
|
102
|
-
},
|
|
103
|
-
eventOutput: reportEventOutput,
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
name: 'qa.test',
|
|
107
|
-
family: 'qa',
|
|
108
|
-
executionMode: 'sequential',
|
|
109
|
-
description: 'Run the project unit suite scoped by mode: "related" re-runs tests related to changed files, "file" runs the exact test files listed, "pattern" runs tests whose name matches a filter, and "all" runs the full suite. Prefer related/file while iterating on a specific failure.',
|
|
110
|
-
parameters: {
|
|
111
|
-
type: 'object',
|
|
112
|
-
properties: {
|
|
113
|
-
mode: { type: 'string', enum: ['related', 'file', 'pattern', 'all'], description: 'Test scoping mode' },
|
|
114
|
-
files: { type: 'array', items: { type: 'string' }, description: 'Workspace-relative file paths; required for related and file modes' },
|
|
115
|
-
pattern: { type: 'string', description: 'Test name filter; required for pattern mode' },
|
|
116
|
-
},
|
|
117
|
-
required: ['mode'],
|
|
118
|
-
additionalProperties: false,
|
|
119
|
-
},
|
|
120
|
-
execute: async (args, context) => {
|
|
121
|
-
const mode = args.mode;
|
|
122
|
-
const files = validateStringArray(args.files, 'files', 100);
|
|
123
|
-
const pattern = args.pattern;
|
|
124
|
-
if (typeof pattern === 'string' && (pattern.includes('\0') || pattern.length > 512))
|
|
125
|
-
throw new Error('pattern must be under 512 characters without NUL bytes');
|
|
126
|
-
const orchestrator = getQaOrchestrator(context.workspace);
|
|
127
|
-
const authorizer = createQaAuthorizer('qa.test', context);
|
|
128
|
-
authorizer.assertPlanned(orchestrator.plannedCommands(await orchestrator.getProfile(context.signal)));
|
|
129
|
-
const result = await orchestrator.test({ mode, files, pattern }, { signal: context.signal, authorize: command => authorizer.authorize(command) });
|
|
130
|
-
return JSON.stringify(compactResult(result));
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
57
|
{
|
|
134
58
|
name: 'qa.terminal',
|
|
135
59
|
family: 'qa',
|
|
@@ -248,58 +172,9 @@ export function createQaTools() {
|
|
|
248
172
|
throw new Error('url must be an http(s) URL');
|
|
249
173
|
if (args.accessibility !== undefined && typeof args.accessibility !== 'boolean')
|
|
250
174
|
throw new Error('accessibility must be a boolean');
|
|
251
|
-
const
|
|
252
|
-
const results = await orchestrator.browser({ ...(url ? { url } : {}), ...(typeof args.accessibility === 'boolean' ? { accessibility: args.accessibility } : {}), signal: context.signal });
|
|
253
|
-
return clipText(JSON.stringify({ results: results.map(compactResult), summary: results.map(result => `${result.id}: ${result.status.toUpperCase()} — ${result.summary}`).join('\n') }), 24_000);
|
|
254
|
-
},
|
|
255
|
-
},
|
|
256
|
-
{
|
|
257
|
-
name: 'qa.security',
|
|
258
|
-
family: 'qa',
|
|
259
|
-
executionMode: 'sequential',
|
|
260
|
-
description: 'Run security checks over the working tree: the built-in secret scan over all added lines (matched values are redacted), a dependency audit (npm/pnpm/yarn) against the configured severity cascade, and semgrep when enabled in .andorra/qa.yaml. Always run this before considering a merge; secret findings block the merge gate.',
|
|
261
|
-
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
262
|
-
execute: async (_args, context) => {
|
|
263
|
-
const orchestrator = getQaOrchestrator(context.workspace);
|
|
264
|
-
const authorizer = createQaAuthorizer('qa.security', context);
|
|
265
|
-
authorizer.assertPlanned(orchestrator.plannedCommands(await orchestrator.getProfile(context.signal)));
|
|
266
|
-
const results = await orchestrator.security({ signal: context.signal, authorize: command => authorizer.authorize(command) });
|
|
175
|
+
const results = await qaBrowserHost.check({ workspace: context.workspace, ...(url ? { url } : {}), ...(typeof args.accessibility === 'boolean' ? { accessibility: args.accessibility } : {}), signal: context.signal });
|
|
267
176
|
return clipText(JSON.stringify({ results: results.map(compactResult), summary: results.map(result => `${result.id}: ${result.status.toUpperCase()} — ${result.summary}`).join('\n') }), 24_000);
|
|
268
177
|
},
|
|
269
178
|
},
|
|
270
|
-
{
|
|
271
|
-
name: 'qa.deep',
|
|
272
|
-
family: 'qa',
|
|
273
|
-
executionMode: 'sequential',
|
|
274
|
-
description: 'Run the full merge gate for the current change set: the configured base gate (lint, typecheck, related tests, build, diff review, secret scan) plus checks the change classification adds — browser checks for frontend changes, runtime smoke when a startup command exists, API smoke, dependency audit, semgrep. Optional checks narrows to a subset of gate step ids. A ready verdict means every required check passed or was legitimately skipped.',
|
|
275
|
-
parameters: {
|
|
276
|
-
type: 'object',
|
|
277
|
-
properties: { checks: { type: 'array', items: { type: 'string' }, description: 'Optional subset of gate step ids to run' } },
|
|
278
|
-
additionalProperties: false,
|
|
279
|
-
},
|
|
280
|
-
execute: async (args, context) => {
|
|
281
|
-
const checks = validateStringArray(args.checks, 'checks', 32);
|
|
282
|
-
const orchestrator = getQaOrchestrator(context.workspace);
|
|
283
|
-
const authorizer = createQaAuthorizer('qa.deep', context);
|
|
284
|
-
authorizer.assertPlanned(orchestrator.plannedCommands(await orchestrator.getProfile(context.signal)));
|
|
285
|
-
const report = await orchestrator.deep({ signal: context.signal, authorize: command => authorizer.authorize(command), ...(checks ? { checks } : {}) });
|
|
286
|
-
return reportOutput(report);
|
|
287
|
-
},
|
|
288
|
-
eventOutput: reportEventOutput,
|
|
289
|
-
},
|
|
290
|
-
{
|
|
291
|
-
name: 'qa.status',
|
|
292
|
-
family: 'qa',
|
|
293
|
-
executionMode: 'sequential',
|
|
294
|
-
description: 'Show the QA session view: derived profile summary, every recorded check result this session, whether results are stale because the working tree changed since they were recorded, consecutive failure counts per check, and the last merge-gate verdict. Runs host Git and runtime probes; restricted permissions require scoped approval.',
|
|
295
|
-
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
296
|
-
execute: async (_args, context) => {
|
|
297
|
-
const orchestrator = getQaOrchestrator(context.workspace);
|
|
298
|
-
const { summary, state } = await orchestrator.status(context.signal);
|
|
299
|
-
const checks = Object.values(state.checks);
|
|
300
|
-
const lines = checks.map(result => `${result.id}: ${result.status.toUpperCase()} — ${result.summary}${result.repairExhausted ? ' (repair attempts exhausted)' : ''}${orchestrator.isStale(result.fingerprint ?? '') ? ' [STALE: working tree changed since this result]' : ''}`);
|
|
301
|
-
return `${summary}\n\nQA results:\n${lines.join('\n') || 'none yet'}\nchangedSinceLastQa: ${state.changedSinceLastQa}\nmergeReady: ${state.mergeReady}${state.lastGateVerdict ? ` (last verdict ${state.lastGateVerdict})` : ''}`;
|
|
302
|
-
},
|
|
303
|
-
},
|
|
304
179
|
];
|
|
305
180
|
}
|
|
@@ -22,7 +22,7 @@ import { stat } from 'node:fs/promises';
|
|
|
22
22
|
import { isAbsolute, relative, resolve } from 'node:path';
|
|
23
23
|
import { createRunTelemetry, recordEdit, recordTestCommand, recordToolFailure, recordToolUse } from './telemetry/capture.js';
|
|
24
24
|
import { isTestCommandLine } from './telemetry/classify.js';
|
|
25
|
-
import { diffLineStats, fileDiffTarget, readFileSnapshot } from './tool-diff-stats.js';
|
|
25
|
+
import { callFileDiff, diffLineStats, fileDiffTarget, readFileSnapshot } from './tool-diff-stats.js';
|
|
26
26
|
import { TodoStore } from './todos.js';
|
|
27
27
|
import { WIDGET_VALUE_MAX_CHARS } from './widgets.js';
|
|
28
28
|
import { PreparedSteps, PREPARE_STEPS, boundedDecisionText, permittedContinuation, preparedResponse, postToolGuidance, retrySafe } from './decision/PreparedSteps.js';
|
|
@@ -1450,9 +1450,14 @@ export class AndorraAgentEngine {
|
|
|
1450
1450
|
await emit('efficiency.tool_result.filtered', { name: entry.call.name, toolCallId: entry.call.id, format: filtered.format, originalChars: filtered.originalChars, keptChars: filtered.keptChars, omittedLines: filtered.omittedLines, reason: 'filtered' });
|
|
1451
1451
|
// A failed call changed nothing measurable, so the figures belong to the completed event
|
|
1452
1452
|
// alone — the row shows its error without a diff it did not make.
|
|
1453
|
+
const afterSnapshot = isError || snapshotTarget === undefined ? undefined : await readFileSnapshot(snapshotTarget);
|
|
1453
1454
|
const diffStats = isError || snapshotTarget === undefined
|
|
1454
1455
|
? undefined
|
|
1455
|
-
: diffLineStats(beforeSnapshot,
|
|
1456
|
+
: diffLineStats(beforeSnapshot, afterSnapshot);
|
|
1457
|
+
// The call's own change to the file, numbered on both sides, for the transcript row. Bounded: the row
|
|
1458
|
+
// shows the start of the diff and how much more there is, and the journal keeps the event.
|
|
1459
|
+
const editDiff = diffStats === undefined || beforeSnapshot === undefined || afterSnapshot === undefined
|
|
1460
|
+
? undefined : callFileDiff(beforeSnapshot, afterSnapshot);
|
|
1456
1461
|
// A stop that interrupted the call is not a reliability failure: the capture contract
|
|
1457
1462
|
// excludes it, and counting it would blame the tool for the user's pause.
|
|
1458
1463
|
if (isError && !operationSignal.aborted)
|
|
@@ -1474,6 +1479,7 @@ export class AndorraAgentEngine {
|
|
|
1474
1479
|
toolCallId: entry.call.id,
|
|
1475
1480
|
durationMs: workedMs === undefined ? undefined : Math.max(0, workedMs - waitedMs),
|
|
1476
1481
|
...(diffStats === undefined ? {} : { linesAdded: diffStats.linesAdded, linesRemoved: diffStats.linesRemoved }),
|
|
1482
|
+
...(editDiff === undefined ? {} : { fileDiff: editDiff }),
|
|
1477
1483
|
});
|
|
1478
1484
|
// A filtered observation is partial evidence by construction, so it is reported truncated:
|
|
1479
1485
|
// no completion shortcut may rest on it, and the decision snapshot sees the real output.
|
|
@@ -1729,6 +1735,11 @@ export class AndorraAgentEngine {
|
|
|
1729
1735
|
// A bare "continue" got the same discarded call back three times in a row (run 8a245b0f):
|
|
1730
1736
|
// say what this node can and cannot call, and require a tool call in the next response.
|
|
1731
1737
|
const dropped = suspectedDroppedToolCall(response);
|
|
1738
|
+
// The reply is sent back, but what it said is still the user's to read: it is often a
|
|
1739
|
+
// request only they can act on (sign in, approve, answer), and a tool-calling turn shows
|
|
1740
|
+
// its text the same way. Without this the transcript held only the "Continuing" notice.
|
|
1741
|
+
if (response.text.trim())
|
|
1742
|
+
await emit('agent.message', { text: response.text });
|
|
1732
1743
|
forceToolCall = true;
|
|
1733
1744
|
stall = { toolCallDropped: dropped, forcedToolCall: true };
|
|
1734
1745
|
const available = [...tools.filter(tool => tool.providerVisible !== false).map(tool => tool.name), COMPLETION_TOOL];
|
|
@@ -90,7 +90,7 @@ const FINISHED_RUNS_REMEMBERED = 8;
|
|
|
90
90
|
*/
|
|
91
91
|
const MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
|
|
92
92
|
const MAX_LARGE_RESPONSE_BYTES = 12 * 1024 * 1024;
|
|
93
|
-
const LARGE_RESPONSE_METHODS = new Set(['runs.get', 'workspace.diff', 'workspace.git', 'sessions.trajectory', 'browser.view.selection', 'attachments.read']);
|
|
93
|
+
const LARGE_RESPONSE_METHODS = new Set(['runs.get', 'workspace.diff', 'workspace.git', 'sessions.trajectory', 'browser.view.selection', 'attachments.read', 'sessions.changes.list', 'sessions.changes.get']);
|
|
94
94
|
/** Methods a paired client may ask the browsing engine (and only the browsing engine). */
|
|
95
95
|
const PRIMARY_METHODS = new Set([
|
|
96
96
|
'sessions.list', 'sessions.get', 'sessions.create', 'sessions.rename', 'sessions.setArchived', 'sessions.delete',
|
|
@@ -98,6 +98,9 @@ const PRIMARY_METHODS = new Set([
|
|
|
98
98
|
// The skill a slash invocation left active on that machine's session: the Plan card shows it and
|
|
99
99
|
// pauses, resumes or removes it there, since the session's later runs start there too.
|
|
100
100
|
'sessions.skill.get', 'sessions.skill.update',
|
|
101
|
+
// The files that machine's agent changed in the session, and Keep / Undo of them: the files and the
|
|
102
|
+
// stored originals are on that machine, and every engine sharing its home can read and change the record.
|
|
103
|
+
'sessions.changes.list', 'sessions.changes.get', 'sessions.changes.keep', 'sessions.changes.undo',
|
|
101
104
|
'runs.list', 'runs.get', 'timers.list',
|
|
102
105
|
'workspace.tree', 'workspace.read', 'workspace.git', 'workspace.branches', 'workspace.checkout', 'workspace.diff',
|
|
103
106
|
'graphs.list', 'graphs.get', 'graphs.select',
|
|
@@ -133,7 +136,7 @@ const ALLOWED_METHODS = new Set([...PRIMARY_METHODS, ...RUN_START_METHODS, ...RU
|
|
|
133
136
|
const SESSION_MUTATION_METHODS = new Set(['sessions.rename', 'sessions.setArchived', 'sessions.delete']);
|
|
134
137
|
/** Calls whose effect must land inside the caller's own deadline, not past it. */
|
|
135
138
|
const MUTATING_METHODS = new Set([
|
|
136
|
-
...RUN_START_METHODS, ...RUN_TARGET_METHODS, ...SESSION_MUTATION_METHODS, 'sessions.skill.update',
|
|
139
|
+
...RUN_START_METHODS, ...RUN_TARGET_METHODS, ...SESSION_MUTATION_METHODS, 'sessions.skill.update', 'sessions.changes.keep', 'sessions.changes.undo',
|
|
137
140
|
'terminal.open', 'terminal.write', 'terminal.close', 'terminal.closeAll', 'workspace.checkout', 'projects.add', 'projects.remove',
|
|
138
141
|
// Panel calls act on the peer's browser immediately; an install outlives the
|
|
139
142
|
// relay's default child deadline, so it keeps the caller's own budget.
|
|
@@ -1141,7 +1144,15 @@ export class RemoteEngineRelay {
|
|
|
1141
1144
|
await Promise.all(children.map(child => child.stop().catch(() => undefined)));
|
|
1142
1145
|
}
|
|
1143
1146
|
}
|
|
1144
|
-
/**
|
|
1147
|
+
/**
|
|
1148
|
+
* Fields whose value is a file's own text wherever it appears: a completed call's `fileDiff` on
|
|
1149
|
+
* `node.tool.completed`, which reaches a viewer live inside `run.event` and again in the journal a
|
|
1150
|
+
* `runs.get` or a trajectory read returns. A diff line that reads exactly like a host project folder is
|
|
1151
|
+
* still a line of the file, and rewriting it would show the viewer a change the file never had. Only the
|
|
1152
|
+
* routing fields around such a value are translated.
|
|
1153
|
+
*/
|
|
1154
|
+
const VERBATIM_FIELDS = new Set(['fileDiff']);
|
|
1155
|
+
/** Rewrite every known host path inside an arbitrary payload, structurally, leaving file text alone. */
|
|
1145
1156
|
function rewritePaths(value, paths) {
|
|
1146
1157
|
if (typeof value === 'string')
|
|
1147
1158
|
return paths.get(value) ?? value;
|
|
@@ -1150,7 +1161,7 @@ function rewritePaths(value, paths) {
|
|
|
1150
1161
|
if (value && typeof value === 'object') {
|
|
1151
1162
|
const out = {};
|
|
1152
1163
|
for (const [key, entry] of Object.entries(value))
|
|
1153
|
-
out[key] = rewritePaths(entry, paths);
|
|
1164
|
+
out[key] = VERBATIM_FIELDS.has(key) ? entry : rewritePaths(entry, paths);
|
|
1154
1165
|
return out;
|
|
1155
1166
|
}
|
|
1156
1167
|
return value;
|
|
@@ -1159,7 +1170,8 @@ function rewritePaths(value, paths) {
|
|
|
1159
1170
|
* Answers that are the page's own data, not file-system answers. A selection that happens to read
|
|
1160
1171
|
* exactly like one of the host's shared-root paths is the user's text — rewriting it would put an
|
|
1161
1172
|
* `rw:` project identifier on the viewer's clipboard and, for a cut, delete the original from the
|
|
1162
|
-
* page with only the identifier surviving.
|
|
1173
|
+
* page with only the identifier surviving. A pending change's diff is the same: the file's own text,
|
|
1174
|
+
* whose paths are workspace-relative, and a line that reads like a host path is still a line.
|
|
1163
1175
|
*/
|
|
1164
|
-
const OPAQUE_RESPONSE_METHODS = new Set(['browser.view.selection', 'browser.view.cursor']);
|
|
1176
|
+
const OPAQUE_RESPONSE_METHODS = new Set(['browser.view.selection', 'browser.view.cursor', 'sessions.changes.list', 'sessions.changes.get']);
|
|
1165
1177
|
export { REMOTE_PROJECT_PREFIX, isRemoteProjectSpelling, rootPartOf };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** One screen cell, 1-based like the terminal's own mouse reports. */
|
|
2
|
+
export interface ScreenCell {
|
|
3
|
+
row: number;
|
|
4
|
+
column: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A drag selection in screen coordinates.
|
|
8
|
+
*
|
|
9
|
+
* `limit` is the last column the selection may reach: a drag that starts in the chat column stops
|
|
10
|
+
* at its edge, so the side panel drawn beside it is never copied along with the transcript.
|
|
11
|
+
*/
|
|
12
|
+
export interface ScreenSelection {
|
|
13
|
+
anchor: ScreenCell;
|
|
14
|
+
head: ScreenCell;
|
|
15
|
+
limit?: number;
|
|
16
|
+
}
|
|
17
|
+
/** The selection's two ends in reading order. */
|
|
18
|
+
export declare function orderedSelection(selection: ScreenSelection): [ScreenCell, ScreenCell];
|
|
19
|
+
/** Whether the selection covers nothing but the cell it started on. */
|
|
20
|
+
export declare function emptySelection(selection: ScreenSelection): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The inclusive column span the selection covers on one row, or undefined when it misses the row.
|
|
23
|
+
*
|
|
24
|
+
* A selection reads like text: the first row runs from its start to the edge, the last row from
|
|
25
|
+
* the edge to its end, and every row between is taken whole.
|
|
26
|
+
*/
|
|
27
|
+
export declare function selectedSpan(selection: ScreenSelection, row: number): [number, number] | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Draw one row with the selected columns in reverse video.
|
|
30
|
+
*
|
|
31
|
+
* The row keeps its own colors. Reverse video is re-asserted after every escape inside the span,
|
|
32
|
+
* because a color reset there would otherwise end the highlight early.
|
|
33
|
+
*/
|
|
34
|
+
export declare function highlightRow(line: string, from: number, to: number): string;
|
|
35
|
+
/** The plain text the selection covers, one line per screen row, trailing blanks dropped. */
|
|
36
|
+
export declare function selectedText(rows: readonly string[], selection: ScreenSelection): string;
|
|
37
|
+
/** The run of non-blank cells under a cell, as a selection; undefined on blank space. */
|
|
38
|
+
export declare function wordAt(rows: readonly string[], cell: ScreenCell): ScreenSelection | undefined;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import stringWidth from 'string-width';
|
|
2
|
+
const segmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
|
|
3
|
+
/** A CSI sequence (colors, cursor moves) or an OSC string, matched at the start of the text. */
|
|
4
|
+
const ESCAPE = /^(?:\x1b\[[0-?]*[ -/]*[@-~]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\))/;
|
|
5
|
+
/**
|
|
6
|
+
* Split one drawn row into escape sequences and graphemes, each grapheme with the columns it covers.
|
|
7
|
+
*
|
|
8
|
+
* A zero-width grapheme takes the column of the cell before it, so it travels with that cell.
|
|
9
|
+
*/
|
|
10
|
+
function pieces(line) {
|
|
11
|
+
const result = [];
|
|
12
|
+
let column = 1, rest = line;
|
|
13
|
+
while (rest) {
|
|
14
|
+
const escape = ESCAPE.exec(rest);
|
|
15
|
+
if (escape) {
|
|
16
|
+
result.push({ text: escape[0], escape: true, from: column, to: column - 1 });
|
|
17
|
+
rest = rest.slice(escape[0].length);
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const next = rest.indexOf('\x1b', 1);
|
|
21
|
+
const run = rest.startsWith('\x1b') ? rest.slice(0, 1) : next < 0 ? rest : rest.slice(0, next);
|
|
22
|
+
rest = rest.slice(run.length);
|
|
23
|
+
for (const { segment } of segmenter.segment(run)) {
|
|
24
|
+
const width = stringWidth(segment);
|
|
25
|
+
if (width === 0)
|
|
26
|
+
result.push({ text: segment, escape: false, from: column - 1, to: column - 1 });
|
|
27
|
+
else {
|
|
28
|
+
result.push({ text: segment, escape: false, from: column, to: column + width - 1 });
|
|
29
|
+
column += width;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
/** The selection's two ends in reading order. */
|
|
36
|
+
export function orderedSelection(selection) {
|
|
37
|
+
const { anchor, head } = selection;
|
|
38
|
+
return anchor.row < head.row || (anchor.row === head.row && anchor.column <= head.column) ? [anchor, head] : [head, anchor];
|
|
39
|
+
}
|
|
40
|
+
/** Whether the selection covers nothing but the cell it started on. */
|
|
41
|
+
export function emptySelection(selection) {
|
|
42
|
+
return selection.anchor.row === selection.head.row && selection.anchor.column === selection.head.column;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The inclusive column span the selection covers on one row, or undefined when it misses the row.
|
|
46
|
+
*
|
|
47
|
+
* A selection reads like text: the first row runs from its start to the edge, the last row from
|
|
48
|
+
* the edge to its end, and every row between is taken whole.
|
|
49
|
+
*/
|
|
50
|
+
export function selectedSpan(selection, row) {
|
|
51
|
+
const [start, end] = orderedSelection(selection);
|
|
52
|
+
if (row < start.row || row > end.row)
|
|
53
|
+
return undefined;
|
|
54
|
+
const edge = selection.limit ?? Number.MAX_SAFE_INTEGER;
|
|
55
|
+
const from = row === start.row ? start.column : 1, to = Math.min(edge, row === end.row ? end.column : edge);
|
|
56
|
+
return from <= to ? [from, to] : undefined;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Draw one row with the selected columns in reverse video.
|
|
60
|
+
*
|
|
61
|
+
* The row keeps its own colors. Reverse video is re-asserted after every escape inside the span,
|
|
62
|
+
* because a color reset there would otherwise end the highlight early.
|
|
63
|
+
*/
|
|
64
|
+
export function highlightRow(line, from, to) {
|
|
65
|
+
let out = '', inside = false;
|
|
66
|
+
for (const piece of pieces(line)) {
|
|
67
|
+
if (piece.escape) {
|
|
68
|
+
out += piece.text + (inside ? '\x1b[7m' : '');
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const selected = piece.to >= from && piece.from <= to;
|
|
72
|
+
if (selected !== inside) {
|
|
73
|
+
out += selected ? '\x1b[7m' : '\x1b[27m';
|
|
74
|
+
inside = selected;
|
|
75
|
+
}
|
|
76
|
+
out += piece.text;
|
|
77
|
+
}
|
|
78
|
+
return inside ? out + '\x1b[27m' : out;
|
|
79
|
+
}
|
|
80
|
+
/** The plain text the selection covers, one line per screen row, trailing blanks dropped. */
|
|
81
|
+
export function selectedText(rows, selection) {
|
|
82
|
+
const [start, end] = orderedSelection(selection);
|
|
83
|
+
const lines = [];
|
|
84
|
+
for (let row = start.row; row <= end.row; row++) {
|
|
85
|
+
const span = selectedSpan(selection, row);
|
|
86
|
+
const text = span ? pieces(rows[row - 1] ?? '').filter(piece => !piece.escape && piece.to >= span[0] && piece.from <= span[1]).map(piece => piece.text).join('') : '';
|
|
87
|
+
lines.push(text.trimEnd());
|
|
88
|
+
}
|
|
89
|
+
return lines.join('\n');
|
|
90
|
+
}
|
|
91
|
+
/** The run of non-blank cells under a cell, as a selection; undefined on blank space. */
|
|
92
|
+
export function wordAt(rows, cell) {
|
|
93
|
+
const cells = pieces(rows[cell.row - 1] ?? '').filter(piece => !piece.escape && piece.to >= piece.from);
|
|
94
|
+
const at = cells.findIndex(piece => piece.from <= cell.column && piece.to >= cell.column);
|
|
95
|
+
if (at < 0 || !/\S/u.test(cells[at].text))
|
|
96
|
+
return undefined;
|
|
97
|
+
let first = at, last = at;
|
|
98
|
+
while (first > 0 && /\S/u.test(cells[first - 1].text))
|
|
99
|
+
first--;
|
|
100
|
+
while (last < cells.length - 1 && /\S/u.test(cells[last + 1].text))
|
|
101
|
+
last++;
|
|
102
|
+
return { anchor: { row: cell.row, column: cells[first].from }, head: { row: cell.row, column: cells[last].to } };
|
|
103
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { AppServerSessionChanges, AppServerSessionChangesKept, AppServerSessionChangesUndone, AppServerSessionFileChange } from './app-server/protocol.js';
|
|
2
|
+
/**
|
|
3
|
+
* The files an agent changed in a session since the person last reviewed them, with Keep and Undo.
|
|
4
|
+
*
|
|
5
|
+
* Every write an agent makes to a workspace file passes one function (`atomicWrite` in `tools.ts`), and a
|
|
6
|
+
* delegated change lands through one more (`applyLanding`). Both report here, before and after: before, so
|
|
7
|
+
* the content the file held can be kept as its baseline the first time the agent touches it; after, so the
|
|
8
|
+
* store knows what the agent's write left. Between two reviews the baseline never moves — a file edited ten
|
|
9
|
+
* times has one entry, and its diff is the file's whole change, not the last call's.
|
|
10
|
+
*
|
|
11
|
+
* Keep makes the file as it is the new baseline: it leaves the pending set and its stored original is
|
|
12
|
+
* dropped. Undo puts the baseline back — the earlier content, or no file at all for one the agent created,
|
|
13
|
+
* or the file again for one a landing removed — but only while the file is still what the agent left: a file
|
|
14
|
+
* something else changed afterwards is reported as a conflict instead of being overwritten, unless the
|
|
15
|
+
* caller asks with `force`.
|
|
16
|
+
*
|
|
17
|
+
* The record lives in the configuration home beside the session (`session-changes/<id>/`), not in the
|
|
18
|
+
* workspace and not in Git: it works for a folder that is no repository, needs no index, and survives an
|
|
19
|
+
* app restart and a resumed session. Engines sharing a home can all read and change it — the desktop runs a
|
|
20
|
+
* process per task and browses with another — so every change happens under the session's store lock, and
|
|
21
|
+
* the revision it carries orders every answer and event across those processes.
|
|
22
|
+
*/
|
|
23
|
+
/** Past this size a file's earlier content is not kept: the change is listed, and Undo refuses the file. */
|
|
24
|
+
export declare const BASELINE_BYTE_LIMIT: number;
|
|
25
|
+
/** Diff lines `list` returns per file unless asked for another bound. */
|
|
26
|
+
export declare const LIST_DIFF_LINES = 200;
|
|
27
|
+
/** The most diff lines one answer may ask for per file. */
|
|
28
|
+
export declare const MAX_DIFF_LINES = 20000;
|
|
29
|
+
/** Session ids name files, so only the characters a session id is made of are accepted. */
|
|
30
|
+
export declare function sessionChangesId(id: string): string;
|
|
31
|
+
export declare const sessionChangesRoot: (home: string) => string;
|
|
32
|
+
/**
|
|
33
|
+
* One write (or one landing of several files) as the review record sees it.
|
|
34
|
+
*
|
|
35
|
+
* The write's own mutation of the disk happens between `begin` and `commit`, and those hold the session's
|
|
36
|
+
* review lock — the one Keep and Undo take — so an Undo can never observe a file, have an agent write land on
|
|
37
|
+
* it, and then restore over that write: either the Undo finishes first and the write lands on the restored
|
|
38
|
+
* file (and is recorded against it), or the write lands first and the Undo sees it.
|
|
39
|
+
*
|
|
40
|
+
* - `begin` takes the lock and reads what each file holds now, which becomes its original the first time it
|
|
41
|
+
* changes. Call it right before the mutation, after anything that can wait on a person (an approval).
|
|
42
|
+
* - `commit` records what the mutation left and releases the lock; `abort` releases it for a write that did
|
|
43
|
+
* not land. Exactly one of them must follow a `begin` that resolved.
|
|
44
|
+
*
|
|
45
|
+
* None of them may fail the write: a record that cannot be made is a change the review does not list, not a
|
|
46
|
+
* lost edit. They reject only when the lock could not be taken (`begin`), which the writer treats as
|
|
47
|
+
* "write unrecorded".
|
|
48
|
+
*/
|
|
49
|
+
export interface FileWriteRecording {
|
|
50
|
+
begin(): Promise<void>;
|
|
51
|
+
commit(): Promise<void>;
|
|
52
|
+
abort(): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Where a run's tools report their writes. `beforeWrite` is called with the canonical paths a mutation will
|
|
56
|
+
* write or remove, before any folder is created for them; it answers nothing when none of the paths is one
|
|
57
|
+
* this recorder tracks.
|
|
58
|
+
*/
|
|
59
|
+
export interface FileChangeRecorder {
|
|
60
|
+
beforeWrite(targets: string | readonly string[]): Promise<FileWriteRecording | undefined>;
|
|
61
|
+
}
|
|
62
|
+
export declare class SessionChangeStore {
|
|
63
|
+
private readonly home;
|
|
64
|
+
private readonly baselineLimit;
|
|
65
|
+
private readonly beforeRestore?;
|
|
66
|
+
/**
|
|
67
|
+
* Both options exist for tests: `baselineLimit` is the size past which an original is not kept, and
|
|
68
|
+
* `beforeRestore` runs inside an Undo, under its lock, after it has checked the files and before it writes.
|
|
69
|
+
*/
|
|
70
|
+
constructor(home: string, options?: {
|
|
71
|
+
baselineLimit?: number;
|
|
72
|
+
beforeRestore?: () => Promise<void>;
|
|
73
|
+
beginMemory?: number;
|
|
74
|
+
});
|
|
75
|
+
/** Test seam: the bytes of originals one write holds in memory before the rest go to the store. */
|
|
76
|
+
private readonly beginMemory;
|
|
77
|
+
/**
|
|
78
|
+
* The recorder a run's tools report their writes to. Only files inside `root` (the run's workspace folder)
|
|
79
|
+
* are tracked: a delegated subagent writes in a worktree of its own, and its change reaches the workspace
|
|
80
|
+
* through the landing, which reports the files it lands.
|
|
81
|
+
*/
|
|
82
|
+
recorder(sessionId: string, workspace: string, onChange: (changes: AppServerSessionChanges) => void, onError?: (error: unknown) => void): FileChangeRecorder;
|
|
83
|
+
/** Records what a landed write left, for each file it wrote. The caller holds the session's lock. */
|
|
84
|
+
private recordWrites;
|
|
85
|
+
/** Updates one file's entry in `state`; answers whether the pending set changed. */
|
|
86
|
+
private recordWrite;
|
|
87
|
+
/** The pending set as the last write, Keep or Undo left it, without reading the files. */
|
|
88
|
+
pending(sessionId: string): Promise<AppServerSessionChanges>;
|
|
89
|
+
/** Each pending file with its diff from the earlier content to the file as it is now, `maxLines` per file. */
|
|
90
|
+
list(sessionId: string, maxLines?: number): Promise<AppServerSessionChanges>;
|
|
91
|
+
/** One pending file with its diff, up to `maxLines`; null when the file is not pending. */
|
|
92
|
+
get(sessionId: string, relative: string, maxLines?: number): Promise<{
|
|
93
|
+
revision: number;
|
|
94
|
+
change: AppServerSessionFileChange | null;
|
|
95
|
+
}>;
|
|
96
|
+
/** A stored entry measured against the disk now; nothing when the file is back to its baseline. */
|
|
97
|
+
private fresh;
|
|
98
|
+
/** Accepts the named files (every pending file when `paths` is omitted): each leaves the pending set as it is. */
|
|
99
|
+
keep(sessionId: string, paths?: readonly string[]): Promise<AppServerSessionChangesKept>;
|
|
100
|
+
/**
|
|
101
|
+
* Restores the named files (every pending file when `paths` is omitted) to their content before the first
|
|
102
|
+
* unreviewed change. A file whose disk content is no longer what the agent left is a conflict: without
|
|
103
|
+
* `force` one such conflict reverts nothing, so a multi-file Undo never leaves the folder half restored by
|
|
104
|
+
* choice. A file whose original was too large to keep is reported and stays pending either way.
|
|
105
|
+
*
|
|
106
|
+
* The check and the restore run under the lock of every file restored, the lock any session's agent write
|
|
107
|
+
* holds from just before its rename until it is recorded (`FileWriteRecording`), so no write — of this
|
|
108
|
+
* session or another one editing the same folder — can land between them.
|
|
109
|
+
*/
|
|
110
|
+
undo(sessionId: string, paths?: readonly string[], force?: boolean): Promise<AppServerSessionChangesUndone>;
|
|
111
|
+
/** Undo of `targets`, whose file locks and the session's lock the caller holds. */
|
|
112
|
+
private undoLocked;
|
|
113
|
+
/** Puts one file back to its baseline. Refuses a path whose folders now lead outside the workspace. */
|
|
114
|
+
private restore;
|
|
115
|
+
/** Forgets the session's record and its stored originals, as a deleted session must. */
|
|
116
|
+
remove(sessionId: string): Promise<void>;
|
|
117
|
+
}
|