@andorra-labs/code 0.1.16 → 0.1.18
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/acp-agent.d.ts +6 -0
- package/dist/src/acp-agent.js +15 -4
- package/dist/src/agent-execution.js +108 -19
- package/dist/src/agent-mcp-catalog.js +1 -0
- package/dist/src/agent-mcp.d.ts +3 -0
- package/dist/src/agent-mcp.js +33 -1
- package/dist/src/andorra/entry.d.ts +10 -0
- package/dist/src/andorra/entry.js +18 -4
- package/dist/src/andorra/errors.js +3 -0
- package/dist/src/andorra/hosted.d.ts +2 -1
- package/dist/src/andorra/hosted.js +2 -1
- package/dist/src/andorra/notices.d.ts +5 -0
- package/dist/src/andorra/notices.js +7 -0
- package/dist/src/andorra/state.d.ts +3 -2
- package/dist/src/andorra/state.js +4 -4
- package/dist/src/andorra/terminal.js +7 -2
- package/dist/src/anthropic-credentials.js +2 -0
- package/dist/src/app-server/error.d.ts +5 -0
- package/dist/src/app-server/error.js +7 -0
- package/dist/src/app-server/protocol.d.ts +30 -44
- package/dist/src/app-server/protocol.js +5 -1
- package/dist/src/app-server/workspace.d.ts +108 -0
- package/dist/src/app-server/workspace.js +608 -11
- package/dist/src/app-server.d.ts +390 -33
- package/dist/src/app-server.js +3033 -565
- package/dist/src/attachments.d.ts +10 -0
- package/dist/src/attachments.js +102 -7
- package/dist/src/automation-tool.js +2 -1
- package/dist/src/bridge/cloud.d.ts +27 -0
- package/dist/src/bridge/cloud.js +187 -0
- package/dist/src/bridge/command.d.ts +30 -0
- package/dist/src/bridge/command.js +359 -0
- package/dist/src/bridge/control.d.ts +70 -0
- package/dist/src/bridge/control.js +238 -0
- package/dist/src/bridge/engines.d.ts +90 -0
- package/dist/src/bridge/engines.js +601 -0
- package/dist/src/bridge/github.d.ts +108 -0
- package/dist/src/bridge/github.js +378 -0
- package/dist/src/bridge/host-ops.d.ts +9 -0
- package/dist/src/bridge/host-ops.js +139 -0
- package/dist/src/bridge/host.d.ts +47 -0
- package/dist/src/bridge/host.js +543 -0
- package/dist/src/bridge/link.d.ts +38 -0
- package/dist/src/bridge/link.js +508 -0
- package/dist/src/bridge/login-link.d.ts +29 -0
- package/dist/src/bridge/login-link.js +54 -0
- package/dist/src/bridge/protocol.d.ts +136 -0
- package/dist/src/bridge/protocol.js +11 -0
- package/dist/src/bridge/store.d.ts +12 -0
- package/dist/src/bridge/store.js +61 -0
- package/dist/src/bridge/wording.d.ts +6 -0
- package/dist/src/bridge/wording.js +10 -0
- package/dist/src/browser-server.js +7 -1
- package/dist/src/browser-ui/tokens.css +1 -1
- package/dist/src/bug-report-attachments.d.ts +48 -0
- package/dist/src/bug-report-attachments.js +327 -0
- package/dist/src/bug-report.d.ts +23 -3
- package/dist/src/bug-report.js +72 -9
- package/dist/src/change-authors.d.ts +41 -0
- package/dist/src/change-authors.js +146 -0
- package/dist/src/cli.d.ts +1 -3
- package/dist/src/cli.js +191 -35
- package/dist/src/codex-provider.js +1 -1
- package/dist/src/coding-tools.js +24 -17
- package/dist/src/command-screens.d.ts +6 -0
- package/dist/src/command-screens.js +14 -11
- package/dist/src/commands.d.ts +15 -3
- package/dist/src/commands.js +2 -1
- package/dist/src/compaction-phrases.js +1 -1
- package/dist/src/completion.js +89 -8
- package/dist/src/config.d.ts +71 -3
- package/dist/src/config.js +205 -78
- package/dist/src/context-budget.js +15 -2
- package/dist/src/deadline.js +13 -1
- package/dist/src/decision/DecisionEngine.d.ts +2 -0
- package/dist/src/decision/DecisionManager.d.ts +11 -0
- package/dist/src/decision/DecisionManager.js +36 -0
- package/dist/src/decision/applyTaskKind.d.ts +8 -0
- package/dist/src/decision/applyTaskKind.js +53 -0
- package/dist/src/decision/checks.js +1 -1
- package/dist/src/decision/hostedPolicy.js +2 -1
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +2 -0
- package/dist/src/decision/providers/AndorraDecisionProvider.js +12 -0
- package/dist/src/decision/requestPhrases.js +0 -1
- package/dist/src/decision/taskKind.d.ts +52 -0
- package/dist/src/decision/taskKind.js +76 -0
- package/dist/src/decision/types.d.ts +1 -1
- package/dist/src/default-graph.js +1 -1
- package/dist/src/efficiency.d.ts +5 -0
- package/dist/src/efficiency.js +5 -1
- package/dist/src/effort-routing.d.ts +27 -0
- package/dist/src/effort-routing.js +34 -0
- package/dist/src/evidence.d.ts +110 -0
- package/dist/src/evidence.js +195 -0
- package/dist/src/file-diff.d.ts +4 -0
- package/dist/src/file-diff.js +2 -1
- package/dist/src/github-app/agent-writes.d.ts +102 -0
- package/dist/src/github-app/agent-writes.js +320 -0
- package/dist/src/github-app/client.d.ts +368 -0
- package/dist/src/github-app/client.js +830 -0
- package/dist/src/github-app/event-source.d.ts +208 -0
- package/dist/src/github-app/event-source.js +684 -0
- package/dist/src/github-app/metrics.d.ts +32 -0
- package/dist/src/github-app/metrics.js +49 -0
- package/dist/src/github-app/review-loop.d.ts +274 -0
- package/dist/src/github-app/review-loop.js +1177 -0
- package/dist/src/github-app/review-node.d.ts +81 -0
- package/dist/src/github-app/review-node.js +205 -0
- package/dist/src/github-app/review-post.d.ts +73 -0
- package/dist/src/github-app/review-post.js +139 -0
- package/dist/src/github-app/review-text.d.ts +107 -0
- package/dist/src/github-app/review-text.js +1133 -0
- package/dist/src/github-app/review-threads.d.ts +47 -0
- package/dist/src/github-app/review-threads.js +107 -0
- package/dist/src/github-app/reviewer.d.ts +121 -0
- package/dist/src/github-app/reviewer.js +598 -0
- package/dist/src/github-app/store.d.ts +59 -0
- package/dist/src/github-app/store.js +148 -0
- package/dist/src/github-app/triggers.d.ts +141 -0
- package/dist/src/github-app/triggers.js +441 -0
- package/dist/src/github-names.d.ts +15 -0
- package/dist/src/github-names.js +15 -0
- package/dist/src/glob-search.d.ts +61 -0
- package/dist/src/glob-search.js +180 -0
- package/dist/src/graph-health.js +6 -1
- package/dist/src/graph-manager-chat.js +1 -1
- package/dist/src/graph-preview.d.ts +48 -0
- package/dist/src/graph-preview.js +56 -0
- package/dist/src/graph-provider-portability.js +2 -1
- package/dist/src/graph-runner.js +65 -4
- package/dist/src/graph-server.js +7 -5
- package/dist/src/graph-sync.js +3 -3
- package/dist/src/graph-ui/app.js +121 -7
- package/dist/src/graph-ui/icons.js +2 -1
- package/dist/src/graph-ui/studio.js +15 -1
- package/dist/src/graph-ui/tokens.css +1 -1
- package/dist/src/graphs.d.ts +40 -1
- package/dist/src/graphs.js +164 -15
- package/dist/src/hardened-runtime.js +32 -21
- package/dist/src/image-input.d.ts +16 -0
- package/dist/src/image-input.js +41 -0
- package/dist/src/membership.d.ts +10 -0
- package/dist/src/membership.js +19 -4
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.d.ts +6 -0
- package/dist/src/model-metadata.js +35 -15
- package/dist/src/model-override.d.ts +2 -1
- package/dist/src/model-override.js +9 -0
- package/dist/src/model-relay/local.d.ts +116 -0
- package/dist/src/model-relay/local.js +468 -0
- package/dist/src/model-relay/remote.d.ts +129 -0
- package/dist/src/model-relay/remote.js +252 -0
- package/dist/src/model-relay/runs.d.ts +34 -0
- package/dist/src/model-relay/runs.js +146 -0
- package/dist/src/model-relay/wire.d.ts +5 -0
- package/dist/src/model-relay/wire.js +5 -0
- package/dist/src/model-tiers.d.ts +3 -0
- package/dist/src/model-tiers.js +3 -3
- package/dist/src/project-registry.d.ts +21 -0
- package/dist/src/project-registry.js +74 -0
- package/dist/src/provider-engine.d.ts +13 -1
- package/dist/src/provider-engine.js +74 -0
- package/dist/src/provider-import.d.ts +0 -12
- package/dist/src/provider-import.js +7 -195
- package/dist/src/providers.d.ts +28 -2
- package/dist/src/providers.js +59 -12
- package/dist/src/pull-request-logs.d.ts +12 -1
- package/dist/src/pull-request-logs.js +14 -3
- package/dist/src/pull-requests.d.ts +338 -8
- package/dist/src/pull-requests.js +482 -53
- package/dist/src/react-runtime.js +99 -16
- package/dist/src/remote/engine-pool.d.ts +88 -4
- package/dist/src/remote/engine-pool.js +367 -90
- package/dist/src/remote/roots.d.ts +19 -0
- package/dist/src/remote/roots.js +45 -7
- package/dist/src/remote/types.d.ts +0 -44
- package/dist/src/run-control.d.ts +7 -0
- package/dist/src/run-control.js +23 -0
- package/dist/src/run-records.d.ts +7 -2
- package/dist/src/run-records.js +71 -6
- package/dist/src/runtime.d.ts +34 -2
- package/dist/src/runtime.js +18 -2
- package/dist/src/session-changes.d.ts +35 -0
- package/dist/src/session-changes.js +194 -6
- package/dist/src/session-monitor.js +2 -1
- package/dist/src/session-reaper.d.ts +1 -1
- package/dist/src/session-reaper.js +6 -1
- package/dist/src/session-summary.d.ts +2 -1
- package/dist/src/session-summary.js +2 -1
- package/dist/src/sessions.d.ts +35 -1
- package/dist/src/sessions.js +70 -4
- package/dist/src/skills/bundled/bug-report/SKILL.md +51 -7
- package/dist/src/skills/bundled/diagram/SKILL.md +5 -3
- package/dist/src/skills/bundled/graph-manager/SKILL.md +7 -4
- package/dist/src/skills/bundled/provenance.json +3 -3
- package/dist/src/skills/runtime-skills.js +1 -1
- package/dist/src/task-checkout.d.ts +141 -0
- package/dist/src/task-checkout.js +558 -0
- package/dist/src/telemetry/emitter.d.ts +15 -0
- package/dist/src/telemetry/emitter.js +35 -1
- package/dist/src/telemetry/schema.d.ts +25 -2
- package/dist/src/telemetry/schema.js +52 -4
- package/dist/src/telemetry/surface.d.ts +2 -1
- package/dist/src/telemetry/surface.js +4 -1
- package/dist/src/terminal-ui.d.ts +1 -0
- package/dist/src/terminal-ui.js +10 -3
- package/dist/src/test-edit-guard.d.ts +37 -0
- package/dist/src/test-edit-guard.js +216 -3
- package/dist/src/thinking-level-detect.d.ts +11 -0
- package/dist/src/thinking-level-detect.js +47 -0
- package/dist/src/thinking-levels.d.ts +30 -0
- package/dist/src/thinking-levels.js +124 -0
- package/dist/src/timers.d.ts +3 -0
- package/dist/src/tool-catalog.js +1 -1
- package/dist/src/tools.js +59 -9
- package/dist/src/transcript.js +1 -1
- package/dist/src/types.d.ts +34 -0
- package/package.json +6 -1
- package/dist/src/remote/cert.d.ts +0 -11
- package/dist/src/remote/cert.js +0 -87
- package/dist/src/remote/client.d.ts +0 -119
- package/dist/src/remote/client.js +0 -544
- package/dist/src/remote/command.d.ts +0 -4
- package/dist/src/remote/command.js +0 -194
- package/dist/src/remote/errors.d.ts +0 -11
- package/dist/src/remote/errors.js +0 -14
- package/dist/src/remote/network.d.ts +0 -22
- package/dist/src/remote/network.js +0 -102
- package/dist/src/remote/pairing.d.ts +0 -63
- package/dist/src/remote/pairing.js +0 -299
- package/dist/src/remote/pem.d.ts +0 -2
- package/dist/src/remote/pem.js +0 -7
- package/dist/src/remote/serve.d.ts +0 -68
- package/dist/src/remote/serve.js +0 -244
- package/dist/src/remote/server.d.ts +0 -21
- package/dist/src/remote/server.js +0 -406
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export declare const PROTOCOL_VERSION = 1;
|
|
2
|
+
export declare const MAX_FRAME_BYTES: number;
|
|
3
|
+
/** The hello, the only frame the relay reads before `ready`, may be at most this large. */
|
|
4
|
+
export declare const PRE_HELLO_MAX_BYTES: number;
|
|
5
|
+
/** Once ready, a client sends `ping` this often, so both ends notice a dead socket while idle. */
|
|
6
|
+
export declare const CLIENT_PING_MS = 20000;
|
|
7
|
+
/** A client that has received no frame of any kind for this long treats the socket as dead and reconnects. */
|
|
8
|
+
export declare const CLIENT_DEAD_MS = 50000;
|
|
9
|
+
export type Host = {
|
|
10
|
+
hostname: string;
|
|
11
|
+
platform: string;
|
|
12
|
+
version: string;
|
|
13
|
+
};
|
|
14
|
+
export type EngineFrame = {
|
|
15
|
+
engine: string;
|
|
16
|
+
event: string;
|
|
17
|
+
data: Record<string, unknown>;
|
|
18
|
+
};
|
|
19
|
+
/** `version` is a desktop's own engine version, `major.minor.patch`; the relay copies only that shape into `open`. */
|
|
20
|
+
export type Hello = {
|
|
21
|
+
t: 'hello';
|
|
22
|
+
v: 1;
|
|
23
|
+
role: 'bridge' | 'desktop';
|
|
24
|
+
token: string;
|
|
25
|
+
host?: Host;
|
|
26
|
+
version?: string;
|
|
27
|
+
};
|
|
28
|
+
export type Auth = {
|
|
29
|
+
t: 'auth';
|
|
30
|
+
token: string;
|
|
31
|
+
};
|
|
32
|
+
export type Ping = {
|
|
33
|
+
t: 'ping';
|
|
34
|
+
};
|
|
35
|
+
export type Pong = {
|
|
36
|
+
t: 'pong';
|
|
37
|
+
};
|
|
38
|
+
export type DesktopOut = {
|
|
39
|
+
t: 'open';
|
|
40
|
+
env: string;
|
|
41
|
+
connectionId: string;
|
|
42
|
+
viewerWorkspaceId?: string;
|
|
43
|
+
} | {
|
|
44
|
+
t: 'request';
|
|
45
|
+
env: string;
|
|
46
|
+
id: string;
|
|
47
|
+
body: unknown;
|
|
48
|
+
} | {
|
|
49
|
+
t: 'host';
|
|
50
|
+
env: string;
|
|
51
|
+
id: string;
|
|
52
|
+
op: string;
|
|
53
|
+
params: Record<string, unknown>;
|
|
54
|
+
} | {
|
|
55
|
+
t: 'close';
|
|
56
|
+
env: string;
|
|
57
|
+
connectionId: string;
|
|
58
|
+
} | {
|
|
59
|
+
t: 'presence';
|
|
60
|
+
} | Ping;
|
|
61
|
+
export type DesktopIn = {
|
|
62
|
+
t: 'ready';
|
|
63
|
+
} | {
|
|
64
|
+
t: 'opened';
|
|
65
|
+
env: string;
|
|
66
|
+
connectionId: string;
|
|
67
|
+
host: Host;
|
|
68
|
+
} | {
|
|
69
|
+
t: 'answer';
|
|
70
|
+
env: string;
|
|
71
|
+
id: string;
|
|
72
|
+
answer: unknown;
|
|
73
|
+
} | {
|
|
74
|
+
t: 'event';
|
|
75
|
+
env: string;
|
|
76
|
+
connectionId: string;
|
|
77
|
+
frame: EngineFrame;
|
|
78
|
+
} | {
|
|
79
|
+
t: 'closed';
|
|
80
|
+
env: string;
|
|
81
|
+
connectionId?: string;
|
|
82
|
+
reason: 'offline' | 'not-found' | 'slow' | 'unlinked' | 'limit';
|
|
83
|
+
} | {
|
|
84
|
+
t: 'presence';
|
|
85
|
+
online: string[];
|
|
86
|
+
} | Pong;
|
|
87
|
+
export type BridgeIn = {
|
|
88
|
+
t: 'ready';
|
|
89
|
+
} | {
|
|
90
|
+
t: 'open';
|
|
91
|
+
viewer: string;
|
|
92
|
+
connectionId: string;
|
|
93
|
+
viewerWorkspaceId?: string;
|
|
94
|
+
version?: string;
|
|
95
|
+
} | {
|
|
96
|
+
t: 'request';
|
|
97
|
+
viewer: string;
|
|
98
|
+
id: string;
|
|
99
|
+
body: unknown;
|
|
100
|
+
} | {
|
|
101
|
+
t: 'host';
|
|
102
|
+
viewer: string;
|
|
103
|
+
id: string;
|
|
104
|
+
op: string;
|
|
105
|
+
params: Record<string, unknown>;
|
|
106
|
+
} | {
|
|
107
|
+
t: 'close';
|
|
108
|
+
viewer: string;
|
|
109
|
+
connectionId: string;
|
|
110
|
+
} | {
|
|
111
|
+
t: 'viewer-gone';
|
|
112
|
+
viewer: string;
|
|
113
|
+
} | Pong;
|
|
114
|
+
export type BridgeOut = {
|
|
115
|
+
t: 'opened';
|
|
116
|
+
viewer: string;
|
|
117
|
+
connectionId: string;
|
|
118
|
+
host: Host;
|
|
119
|
+
} | {
|
|
120
|
+
t: 'answer';
|
|
121
|
+
viewer: string;
|
|
122
|
+
id: string;
|
|
123
|
+
answer: unknown;
|
|
124
|
+
} | {
|
|
125
|
+
t: 'event';
|
|
126
|
+
viewer: string;
|
|
127
|
+
connectionId: string;
|
|
128
|
+
frame: EngineFrame;
|
|
129
|
+
} | Ping;
|
|
130
|
+
export declare const CLOSE: {
|
|
131
|
+
readonly unauthorized: 4401;
|
|
132
|
+
readonly replaced: 4409;
|
|
133
|
+
readonly protocol: 4400;
|
|
134
|
+
readonly tooLarge: 4413;
|
|
135
|
+
readonly expired: 4403;
|
|
136
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// The wire protocol between a bridge host, the relay and a desktop engine. Every frame is one JSON text
|
|
2
|
+
// message of at most MAX_FRAME_BYTES. The bridge host and the engine client keep a byte-for-byte copy of this file.
|
|
3
|
+
export const PROTOCOL_VERSION = 1;
|
|
4
|
+
export const MAX_FRAME_BYTES = 16 * 1024 * 1024;
|
|
5
|
+
/** The hello, the only frame the relay reads before `ready`, may be at most this large. */
|
|
6
|
+
export const PRE_HELLO_MAX_BYTES = 16 * 1024;
|
|
7
|
+
/** Once ready, a client sends `ping` this often, so both ends notice a dead socket while idle. */
|
|
8
|
+
export const CLIENT_PING_MS = 20_000;
|
|
9
|
+
/** A client that has received no frame of any kind for this long treats the socket as dead and reconnects. */
|
|
10
|
+
export const CLIENT_DEAD_MS = 50_000;
|
|
11
|
+
export const CLOSE = { unauthorized: 4401, replaced: 4409, protocol: 4400, tooLarge: 4413, expired: 4403 };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RemoteShare } from '../remote/types.js';
|
|
2
|
+
export interface BridgeIdentity {
|
|
3
|
+
environmentId: string;
|
|
4
|
+
name: string;
|
|
5
|
+
secret: string;
|
|
6
|
+
linkedAt: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function readBridgeIdentity(directory: string): Promise<BridgeIdentity | undefined>;
|
|
9
|
+
export declare function writeBridgeIdentity(directory: string, identity: BridgeIdentity): Promise<void>;
|
|
10
|
+
export declare function clearBridgeIdentity(directory: string): Promise<void>;
|
|
11
|
+
/** Shares a folder with the machine's desktops: the real path is stored, and a folder already shared keeps its id. */
|
|
12
|
+
export declare function shareFolder(directory: string, value: string, label?: string): Promise<RemoteShare>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { mkdir, readFile, realpath, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { randomBytes, randomUUID } from 'node:crypto';
|
|
4
|
+
import { changeConfigFile } from '../config.js';
|
|
5
|
+
const FILE = 'bridge.json';
|
|
6
|
+
const MAX_FOLDERS = 64;
|
|
7
|
+
function isIdentity(value) {
|
|
8
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
9
|
+
return false;
|
|
10
|
+
const found = value;
|
|
11
|
+
return ['environmentId', 'name', 'secret', 'linkedAt'].every(key => typeof found[key] === 'string' && found[key].length > 0);
|
|
12
|
+
}
|
|
13
|
+
export async function readBridgeIdentity(directory) {
|
|
14
|
+
try {
|
|
15
|
+
const parsed = JSON.parse(await readFile(join(directory, FILE), 'utf8'));
|
|
16
|
+
if (!isIdentity(parsed))
|
|
17
|
+
return undefined;
|
|
18
|
+
const { environmentId, name, secret, linkedAt } = parsed;
|
|
19
|
+
return { environmentId, name, secret, linkedAt };
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function writeBridgeIdentity(directory, identity) {
|
|
26
|
+
await mkdir(directory, { recursive: true });
|
|
27
|
+
const target = join(directory, FILE);
|
|
28
|
+
const temporary = `${target}.${randomUUID()}.tmp`;
|
|
29
|
+
try {
|
|
30
|
+
await writeFile(temporary, `${JSON.stringify(identity, null, 2)}\n`, { mode: 0o600 });
|
|
31
|
+
await rename(temporary, target);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
await rm(temporary, { force: true }).catch(() => undefined);
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export async function clearBridgeIdentity(directory) {
|
|
39
|
+
await rm(join(directory, FILE), { force: true });
|
|
40
|
+
}
|
|
41
|
+
/** Shares a folder with the machine's desktops: the real path is stored, and a folder already shared keeps its id. */
|
|
42
|
+
export async function shareFolder(directory, value, label) {
|
|
43
|
+
const real = await realpath(resolve(value)).catch(() => undefined);
|
|
44
|
+
if (!real)
|
|
45
|
+
throw new Error(`That folder does not exist: ${value}`);
|
|
46
|
+
if (!(await stat(real)).isDirectory())
|
|
47
|
+
throw new Error(`That path is not a folder: ${value}`);
|
|
48
|
+
let stored = { id: randomBytes(6).toString('hex'), path: real, ...(label === undefined ? {} : { label }) };
|
|
49
|
+
await changeConfigFile(directory, config => {
|
|
50
|
+
const current = config.bridge?.folders ?? [];
|
|
51
|
+
const existing = current.find(folder => folder.path === real);
|
|
52
|
+
if (existing) {
|
|
53
|
+
stored = existing;
|
|
54
|
+
return config;
|
|
55
|
+
}
|
|
56
|
+
if (current.length >= MAX_FOLDERS)
|
|
57
|
+
throw new Error('This machine already shares the maximum number of folders.');
|
|
58
|
+
return { ...config, bridge: { ...config.bridge, folders: [...current, stored] } };
|
|
59
|
+
});
|
|
60
|
+
return stored;
|
|
61
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The launcher (npx @andorra-labs/bridge) sets ANDORRA_BRIDGE_LAUNCHER=1 for every engine it starts; that machine has no "andorra" command. */
|
|
2
|
+
export declare function launchedFromEnvironment(): boolean;
|
|
3
|
+
/** How a person types a bridge command on this machine: the text is fixed here, the environment only selects it. */
|
|
4
|
+
export declare function bridgeCommand(name: string, launched?: boolean): string;
|
|
5
|
+
/** A command named to a desktop, which cannot tell how that machine runs the bridge: both forms. */
|
|
6
|
+
export declare function bothBridgeCommands(name: string): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** The launcher (npx @andorra-labs/bridge) sets ANDORRA_BRIDGE_LAUNCHER=1 for every engine it starts; that machine has no "andorra" command. */
|
|
2
|
+
export function launchedFromEnvironment() { return process.env.ANDORRA_BRIDGE_LAUNCHER === '1'; }
|
|
3
|
+
/** How a person types a bridge command on this machine: the text is fixed here, the environment only selects it. */
|
|
4
|
+
export function bridgeCommand(name, launched = launchedFromEnvironment()) {
|
|
5
|
+
return `${launched ? 'npx @andorra-labs/bridge' : 'andorra bridge'} ${name}`;
|
|
6
|
+
}
|
|
7
|
+
/** A command named to a desktop, which cannot tell how that machine runs the bridge: both forms. */
|
|
8
|
+
export function bothBridgeCommands(name) {
|
|
9
|
+
return `${bridgeCommand(name, false)}, or ${bridgeCommand(name, true)}`;
|
|
10
|
+
}
|
|
@@ -26,6 +26,12 @@ function withRailFields(target, predecessor, carryFiling) {
|
|
|
26
26
|
}
|
|
27
27
|
return target;
|
|
28
28
|
}
|
|
29
|
+
/** An archived task leaves the rail's list, so it does not stay pinned there (the engine's `sessions.setArchived` does the same). */
|
|
30
|
+
function withoutPinWhenArchived(target) {
|
|
31
|
+
if (target.archived === true)
|
|
32
|
+
delete target.pinned;
|
|
33
|
+
return target;
|
|
34
|
+
}
|
|
29
35
|
function terminalCompletion(completion, status) {
|
|
30
36
|
return completion.status === undefined ? { ...completion, status } : completion;
|
|
31
37
|
}
|
|
@@ -382,7 +388,7 @@ export async function startBrowserServer(options = {}) {
|
|
|
382
388
|
const now = new Date().toISOString();
|
|
383
389
|
const apply = (target) => change === 'rename'
|
|
384
390
|
? { ...target, name, renamed: true, updatedAt: now }
|
|
385
|
-
: { ...target, archived: body.archived };
|
|
391
|
+
: withoutPinWhenArchived({ ...target, archived: body.archived });
|
|
386
392
|
let copy;
|
|
387
393
|
try {
|
|
388
394
|
const { previousPrimaryDigest, ...saved } = JSON.parse(await readFile(join(folder, `${id}.json`), 'utf8'));
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
--shadow-raised: 0 1px 2px rgba(0,0,0,.32);
|
|
74
74
|
--shadow-knob: 0 1px 2px rgba(0,0,0,.4);
|
|
75
75
|
|
|
76
|
-
--z-raised: 10; --z-chrome: 30; --z-
|
|
76
|
+
--z-raised: 10; --z-chrome: 30; --z-dialog: 50; --z-menu: 60; --z-palette: 70; --z-toast: 80;
|
|
77
77
|
--z-lightbox: 90; --z-tooltip: 100;
|
|
78
78
|
|
|
79
79
|
--dur-0: 80ms; --dur-1: 120ms; --dur-2: 160ms; --dur-3: 200ms; --dur-4: 240ms;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** Byte limits the service enforces on the two attachments (infra/andorra-auth/bug_report.py). */
|
|
2
|
+
export declare const GRAPH_LIMIT = 8000;
|
|
3
|
+
export declare const TRAJECTORY_LIMIT = 12000;
|
|
4
|
+
export interface ReportSession {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
updatedAt: string;
|
|
8
|
+
current?: true;
|
|
9
|
+
}
|
|
10
|
+
export interface SessionAttachments {
|
|
11
|
+
graph?: string;
|
|
12
|
+
trajectory?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The sessions a report can be about: the newest saved ones, with the one this run belongs to first. Only the
|
|
16
|
+
* newest files are opened, so a home with thousands of sessions costs a directory listing and a few reads.
|
|
17
|
+
*/
|
|
18
|
+
export declare function listReportSessions(home: string, currentId?: string, limit?: number): Promise<ReportSession[]>;
|
|
19
|
+
/**
|
|
20
|
+
* A graph as one line per node and edge. Settings are listed; the text of an instruction, prompt or command is
|
|
21
|
+
* replaced by its length, because a bug in routing or tools is visible without the user's wording.
|
|
22
|
+
*/
|
|
23
|
+
export declare function graphOutline(value: unknown): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Reads a session's trajectory into the two attachments: the graph of the last run it reports, and each run as a short
|
|
26
|
+
* list of steps (nodes, tools, retries, refusals, how it stopped). It never copies a prompt, a model reply, tool
|
|
27
|
+
* arguments or a successful tool's output; a failed step keeps the first 200 characters of its error.
|
|
28
|
+
*/
|
|
29
|
+
export declare class TrajectoryDigest {
|
|
30
|
+
private readonly runs;
|
|
31
|
+
/** One line of the trajectory file. Model requests and replies are the bulk of the file and are skipped unparsed. */
|
|
32
|
+
add(line: string): void;
|
|
33
|
+
private run;
|
|
34
|
+
private at;
|
|
35
|
+
private flush;
|
|
36
|
+
private event;
|
|
37
|
+
/** `skipOpenRun` leaves out a last run that has not finished: in the reporting session, that run is the report itself. */
|
|
38
|
+
result(options?: {
|
|
39
|
+
skipOpenRun?: boolean;
|
|
40
|
+
}): SessionAttachments;
|
|
41
|
+
}
|
|
42
|
+
/** Whether this machine has a saved session or a trajectory under that id. */
|
|
43
|
+
export declare function sessionExists(home: string, sessionId: string): Promise<boolean>;
|
|
44
|
+
/** The graph and compressed trajectory of one saved session, or nothing when the session left no trajectory. */
|
|
45
|
+
export declare function sessionAttachments(home: string, sessionId: string, options?: {
|
|
46
|
+
current?: boolean;
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
}): Promise<SessionAttachments>;
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { createReadStream } from 'node:fs';
|
|
2
|
+
import { readFile, readdir, stat } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { createInterface } from 'node:readline';
|
|
5
|
+
import { redactSecrets } from './memory/redaction.js';
|
|
6
|
+
import { hiddenSession, validSavedSession } from './sessions.js';
|
|
7
|
+
/** Byte limits the service enforces on the two attachments (infra/andorra-auth/bug_report.py). */
|
|
8
|
+
export const GRAPH_LIMIT = 8000;
|
|
9
|
+
export const TRAJECTORY_LIMIT = 12000;
|
|
10
|
+
const ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
11
|
+
const CONTROL = /[\u0000-\u0008\u000B-\u001F\u007F-\u009F-----]/g;
|
|
12
|
+
const fields = (value) => value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
13
|
+
const word = (value) => typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
14
|
+
/** One line of attachment text: no line breaks or control characters, no credential, at most `limit` characters. */
|
|
15
|
+
function clip(value, limit) {
|
|
16
|
+
if (typeof value !== 'string')
|
|
17
|
+
return '';
|
|
18
|
+
const text = redactSecrets(value.replace(/\s+/g, ' ').replace(CONTROL, '').trim()).text;
|
|
19
|
+
return text.length <= limit ? text : `${text.slice(0, limit)}… [${text.length - limit} more characters]`;
|
|
20
|
+
}
|
|
21
|
+
/** Fit whole lines into a byte limit: the start and the end are kept, since the end is where a run went wrong. */
|
|
22
|
+
function fit(lines, limit) {
|
|
23
|
+
const size = (text) => Buffer.byteLength(text, 'utf8');
|
|
24
|
+
// A single line longer than the limit cannot be kept whole; every line here is already clipped far below it.
|
|
25
|
+
const kept = lines.filter(line => size(line) < limit / 4);
|
|
26
|
+
if (size(kept.join('\n')) <= limit)
|
|
27
|
+
return kept.join('\n');
|
|
28
|
+
const marker = (count) => `… ${count} lines left out to fit the limit …`;
|
|
29
|
+
const budget = limit - size(marker(kept.length)) - 2;
|
|
30
|
+
const head = [];
|
|
31
|
+
const tail = [];
|
|
32
|
+
let used = 0;
|
|
33
|
+
let first = 0;
|
|
34
|
+
let last = kept.length - 1;
|
|
35
|
+
while (first <= last && used + size(kept[first]) + 1 <= budget * 0.25) {
|
|
36
|
+
used += size(kept[first]) + 1;
|
|
37
|
+
head.push(kept[first++]);
|
|
38
|
+
}
|
|
39
|
+
while (last >= first && used + size(kept[last]) + 1 <= budget) {
|
|
40
|
+
used += size(kept[last]) + 1;
|
|
41
|
+
tail.unshift(kept[last--]);
|
|
42
|
+
}
|
|
43
|
+
return [...head, marker(last - first + 1), ...tail].join('\n');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The sessions a report can be about: the newest saved ones, with the one this run belongs to first. Only the
|
|
47
|
+
* newest files are opened, so a home with thousands of sessions costs a directory listing and a few reads.
|
|
48
|
+
*/
|
|
49
|
+
export async function listReportSessions(home, currentId, limit = 8) {
|
|
50
|
+
const directory = join(home, 'sessions');
|
|
51
|
+
let names;
|
|
52
|
+
try {
|
|
53
|
+
names = (await readdir(directory)).filter(name => name.endsWith('.json') && ID.test(name.slice(0, -5)));
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
const dated = (await Promise.all(names.map(async (name) => {
|
|
59
|
+
try {
|
|
60
|
+
return { name, modified: (await stat(join(directory, name))).mtimeMs };
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
}))).filter((entry) => !!entry).sort((a, b) => b.modified - a.modified);
|
|
66
|
+
const wanted = currentId && ID.test(currentId) ? `${currentId}.json` : undefined;
|
|
67
|
+
const order = [...(wanted && dated.some(entry => entry.name === wanted) ? [wanted] : []), ...dated.map(entry => entry.name).filter(name => name !== wanted)];
|
|
68
|
+
const sessions = [];
|
|
69
|
+
for (const name of order) {
|
|
70
|
+
if (sessions.length >= limit)
|
|
71
|
+
break;
|
|
72
|
+
try {
|
|
73
|
+
const value = JSON.parse(await readFile(join(directory, name), 'utf8'));
|
|
74
|
+
if (!validSavedSession(value) || `${value.id}.json` !== name || hiddenSession(value))
|
|
75
|
+
continue;
|
|
76
|
+
sessions.push({ id: value.id, name: clip(value.name, 80) || 'Untitled', updatedAt: value.updatedAt, ...(name === wanted ? { current: true } : {}) });
|
|
77
|
+
}
|
|
78
|
+
catch { }
|
|
79
|
+
}
|
|
80
|
+
return sessions;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A graph as one line per node and edge. Settings are listed; the text of an instruction, prompt or command is
|
|
84
|
+
* replaced by its length, because a bug in routing or tools is visible without the user's wording.
|
|
85
|
+
*/
|
|
86
|
+
export function graphOutline(value) {
|
|
87
|
+
const graph = fields(value);
|
|
88
|
+
const nodes = Object.values(fields(graph.nodes)).map(fields).filter(node => word(node.id));
|
|
89
|
+
if (!word(graph.id) || !nodes.length)
|
|
90
|
+
return undefined;
|
|
91
|
+
const lines = [`graph "${clip(graph.name, 80)}" (${clip(graph.id, 80)}) revision ${Number(graph.revision) || 0}, schema ${Number(graph.schemaVersion) || 0}, entry ${clip(graph.entry, 64)}`];
|
|
92
|
+
const limits = Object.entries(fields(graph.limits)).filter(([, amount]) => typeof amount === 'number').map(([name, amount]) => `${name}=${amount}`);
|
|
93
|
+
if (limits.length)
|
|
94
|
+
lines.push(`limits ${limits.join(' ')}`);
|
|
95
|
+
for (const node of nodes) {
|
|
96
|
+
const parts = [`node ${clip(node.id, 64)} "${clip(node.name, 60)}" ${clip(node.type, 16)}`];
|
|
97
|
+
for (const name of ['agentRole', 'executor', 'provider', 'model', 'maxIterations', 'maxSubagents', 'jevEnabled']) {
|
|
98
|
+
const setting = node[name];
|
|
99
|
+
if (typeof setting === 'string' || typeof setting === 'number' || typeof setting === 'boolean')
|
|
100
|
+
parts.push(`${name}=${clip(String(setting), 80)}`);
|
|
101
|
+
}
|
|
102
|
+
for (const name of ['instruction', 'systemPrompt', 'prompt']) {
|
|
103
|
+
if (typeof node[name] === 'string' && node[name])
|
|
104
|
+
parts.push(`${name}=[${node[name].length} characters]`);
|
|
105
|
+
}
|
|
106
|
+
if (Array.isArray(node.tools))
|
|
107
|
+
parts.push(`tools=${node.tools.filter(tool => typeof tool === 'string').map(tool => clip(tool, 48)).join(',') || 'none'}`);
|
|
108
|
+
const capabilities = Object.entries(fields(node.capabilities)).filter(([, level]) => typeof level === 'string').map(([name, level]) => `${name}:${clip(level, 24)}`);
|
|
109
|
+
if (capabilities.length)
|
|
110
|
+
parts.push(`capabilities=${capabilities.join(',')}`);
|
|
111
|
+
const completion = fields(node.completion);
|
|
112
|
+
if (completion.mode === 'single')
|
|
113
|
+
parts.push(`completion=single[${clip(completion.outcome, 48)}]`);
|
|
114
|
+
else if (Array.isArray(completion.outcomes))
|
|
115
|
+
parts.push(`completion=outcomes[${completion.outcomes.map(outcome => clip(outcome, 48)).join(',')}]`);
|
|
116
|
+
const nodeLimits = Object.entries(fields(node.limits)).filter(([, amount]) => typeof amount === 'number').map(([name, amount]) => `${name}=${amount}`);
|
|
117
|
+
if (nodeLimits.length)
|
|
118
|
+
parts.push(`limits=${nodeLimits.join(',')}`);
|
|
119
|
+
const retry = fields(node.retry);
|
|
120
|
+
if (typeof retry.maxAttempts === 'number')
|
|
121
|
+
parts.push(`retry=${retry.maxAttempts}${fields(retry.fallback).provider ? '+fallback' : ''}`);
|
|
122
|
+
const roles = fields(node.subagents).roles;
|
|
123
|
+
if (Array.isArray(roles))
|
|
124
|
+
parts.push(`subagentRoles=${roles.length}`);
|
|
125
|
+
if (fields(node.join).mode)
|
|
126
|
+
parts.push(`join=${clip(fields(node.join).mode, 8)}`);
|
|
127
|
+
if (typeof fields(node.loop).maxIterations === 'number')
|
|
128
|
+
parts.push(`loop=${fields(node.loop).maxIterations}`);
|
|
129
|
+
if (word(fields(node.condition).source))
|
|
130
|
+
parts.push(`condition=${clip(fields(node.condition).source, 64)}.${clip(fields(node.condition).path, 64)}`);
|
|
131
|
+
const action = fields(node.action);
|
|
132
|
+
if (word(action.kind))
|
|
133
|
+
parts.push(`action=${clip(action.kind, 16)}[${typeof action.command === 'string' ? action.command.length : 0} characters]`);
|
|
134
|
+
if (typeof fields(node.review).rounds === 'number')
|
|
135
|
+
parts.push(`review=${fields(node.review).rounds} rounds`);
|
|
136
|
+
lines.push(parts.join(' '));
|
|
137
|
+
}
|
|
138
|
+
for (const edge of Array.isArray(graph.edges) ? graph.edges.map(fields) : []) {
|
|
139
|
+
if (!word(edge.source) || !word(edge.target))
|
|
140
|
+
continue;
|
|
141
|
+
lines.push(`edge ${clip(edge.source, 64)} -> ${clip(edge.target, 64)}${word(edge.outcome) ? ` [${clip(edge.outcome, 48)}]` : ''}${word(edge.toInput) ? ` as ${clip(edge.toInput, 48)}` : ''}`);
|
|
142
|
+
}
|
|
143
|
+
return fit(lines, GRAPH_LIMIT);
|
|
144
|
+
}
|
|
145
|
+
const seconds = (ms) => typeof ms === 'number' && Number.isFinite(ms) ? `${(ms / 1000).toFixed(1)}s` : '';
|
|
146
|
+
const count = (value) => {
|
|
147
|
+
const amount = typeof value === 'number' && Number.isFinite(value) ? value : 0;
|
|
148
|
+
return amount >= 1e6 ? `${(amount / 1e6).toFixed(1)}M` : amount >= 1e3 ? `${Math.round(amount / 1e3)}k` : String(amount);
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Reads a session's trajectory into the two attachments: the graph of the last run it reports, and each run as a short
|
|
152
|
+
* list of steps (nodes, tools, retries, refusals, how it stopped). It never copies a prompt, a model reply, tool
|
|
153
|
+
* arguments or a successful tool's output; a failed step keeps the first 200 characters of its error.
|
|
154
|
+
*/
|
|
155
|
+
export class TrajectoryDigest {
|
|
156
|
+
runs = [];
|
|
157
|
+
/** One line of the trajectory file. Model requests and replies are the bulk of the file and are skipped unparsed. */
|
|
158
|
+
add(line) {
|
|
159
|
+
if (!line || line.startsWith('{"type":"model.'))
|
|
160
|
+
return;
|
|
161
|
+
let record;
|
|
162
|
+
try {
|
|
163
|
+
record = fields(JSON.parse(line));
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const time = Date.parse(String(record.time ?? ''));
|
|
169
|
+
if (record.type === 'run.started') {
|
|
170
|
+
const run = this.run(word(record.runId), time);
|
|
171
|
+
const graph = typeof record.graph === 'string' ? record.graph : fields(record.graph).id;
|
|
172
|
+
run.lines.push(`run started ${Number.isFinite(time) ? new Date(time).toISOString() : ''} graph=${clip(graph, 80) || 'default'} model=${clip(record.provider, 48)}/${clip(record.model, 64)}`.replace(/\s+/g, ' '));
|
|
173
|
+
}
|
|
174
|
+
else if (record.type === 'run.finished') {
|
|
175
|
+
const run = this.run(word(record.runId), time);
|
|
176
|
+
this.flush(run);
|
|
177
|
+
const usage = fields(record.usage);
|
|
178
|
+
// A run that fails before its graph starts (a model check, a graph that does not load) leaves its reason only here.
|
|
179
|
+
const error = clip(record.error, 200);
|
|
180
|
+
run.lines.push(`${this.at(run, time)} run finished: ${clip(record.status, 32)} · ${count(usage.requests)} requests, ${count(record.toolCalls)} tool calls, ${count(usage.inputTokens)} in / ${count(usage.outputTokens)} out${error ? ` — ${error}` : ''}`);
|
|
181
|
+
run.finished = true;
|
|
182
|
+
}
|
|
183
|
+
else if (record.type === 'runtime.event') {
|
|
184
|
+
const event = fields(record.event);
|
|
185
|
+
this.event(String(event.type ?? ''), fields(event.data), Date.parse(String(event.time ?? record.time ?? '')));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
run(id, time) {
|
|
189
|
+
const found = id ? this.runs.find(run => run.id === id) : this.runs.at(-1);
|
|
190
|
+
if (found) {
|
|
191
|
+
if (found.started === undefined && Number.isFinite(time))
|
|
192
|
+
found.started = time;
|
|
193
|
+
return found;
|
|
194
|
+
}
|
|
195
|
+
const run = { id: id ?? `run-${this.runs.length + 1}`, ...(Number.isFinite(time) ? { started: time } : {}), finished: false, lines: [] };
|
|
196
|
+
this.runs.push(run);
|
|
197
|
+
return run;
|
|
198
|
+
}
|
|
199
|
+
at(run, time) {
|
|
200
|
+
if (run.started === undefined || !Number.isFinite(time))
|
|
201
|
+
return '+??:??';
|
|
202
|
+
const elapsed = Math.max(0, Math.round((time - run.started) / 1000));
|
|
203
|
+
return `+${String(Math.floor(elapsed / 60)).padStart(2, '0')}:${String(elapsed % 60).padStart(2, '0')}`;
|
|
204
|
+
}
|
|
205
|
+
flush(run) {
|
|
206
|
+
const tool = run.tool;
|
|
207
|
+
if (!tool)
|
|
208
|
+
return;
|
|
209
|
+
run.tool = undefined;
|
|
210
|
+
run.lines.push(`${tool.at} ${tool.node ? `[${tool.node}] ` : ''}${tool.name}${tool.count > 1 ? ` ×${tool.count}` : ''} ok ${seconds(tool.ms)}`.trimEnd());
|
|
211
|
+
}
|
|
212
|
+
event(type, data, time) {
|
|
213
|
+
if (!type)
|
|
214
|
+
return;
|
|
215
|
+
// Kept with its run: the graph of the run that is reporting the bug must not stand in for the one that had it.
|
|
216
|
+
if (type === 'graph.started') {
|
|
217
|
+
if (word(fields(data.graph).id))
|
|
218
|
+
this.run(word(data.runId), time).graph = data.graph;
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const quiet = type === 'node.tool.completed';
|
|
222
|
+
const telling = quiet || /^(?:graph\.(?:node\.(?:started|completed)|edge\.activated|stopped)|node\.tool\.failed|agent\.(?:model\.retry|completion\.(?:rejected|coerced)|turn\.continued|clarification\.requested))$/.test(type) || /(?:error|\.failed)$/.test(type);
|
|
223
|
+
if (!telling)
|
|
224
|
+
return;
|
|
225
|
+
const run = this.run(word(data.runId), time);
|
|
226
|
+
const at = this.at(run, time);
|
|
227
|
+
const node = clip(data.nodeName ?? data.nodeId, 48);
|
|
228
|
+
const name = clip(data.name, 64);
|
|
229
|
+
if (quiet) {
|
|
230
|
+
const ms = typeof data.durationMs === 'number' ? data.durationMs : 0;
|
|
231
|
+
if (run.tool && run.tool.name === name && run.tool.node === node) {
|
|
232
|
+
run.tool.count++;
|
|
233
|
+
run.tool.ms += ms;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
this.flush(run);
|
|
237
|
+
run.tool = { name, node, count: 1, ms, at };
|
|
238
|
+
}
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
this.flush(run);
|
|
242
|
+
const where = node ? `[${node}] ` : '';
|
|
243
|
+
const line = (text) => run.lines.push(`${at} ${text}`.trimEnd());
|
|
244
|
+
switch (type) {
|
|
245
|
+
case 'graph.node.started':
|
|
246
|
+
line(`node ${node} (${clip(data.nodeType, 16)}) started, visit ${Number(data.visit) || 1}${word(data.model) ? `, model=${clip(data.provider, 48)}/${clip(data.model, 64)}` : ''}`);
|
|
247
|
+
break;
|
|
248
|
+
case 'graph.node.completed':
|
|
249
|
+
line(`node ${node} completed${word(fields(data.completion).outcome) ? `: ${clip(fields(data.completion).outcome, 48)}` : ''}`);
|
|
250
|
+
break;
|
|
251
|
+
case 'graph.edge.activated':
|
|
252
|
+
line(`edge ${clip(data.source, 64)} -> ${clip(data.target, 64)}${word(data.outcome) ? ` [${clip(data.outcome, 48)}]` : ''}`);
|
|
253
|
+
break;
|
|
254
|
+
case 'graph.stopped':
|
|
255
|
+
line(`${where}graph stopped: ${clip(data.status, 32)}${word(data.reason) ? `, ${clip(data.reason, 64)}` : ''}${word(data.reasonText) ? ` — ${clip(data.reasonText, 200)}` : ''}`);
|
|
256
|
+
break;
|
|
257
|
+
case 'node.tool.failed':
|
|
258
|
+
line(`${where}${name} failed ${seconds(data.durationMs)}: ${clip(data.output, 200)}`.replace(/\s+/g, ' '));
|
|
259
|
+
break;
|
|
260
|
+
case 'agent.model.retry':
|
|
261
|
+
line(`${where}model retry ${Number(data.retry) || 0}/${Number(data.maxRetries) || 0}: ${clip(data.reason, 200)}`);
|
|
262
|
+
break;
|
|
263
|
+
case 'agent.completion.rejected':
|
|
264
|
+
line(`${where}completion rejected: ${clip(data.reason, 200)}`);
|
|
265
|
+
break;
|
|
266
|
+
case 'agent.completion.coerced':
|
|
267
|
+
line(`${where}completion coerced`);
|
|
268
|
+
break;
|
|
269
|
+
case 'agent.turn.continued':
|
|
270
|
+
line(`${where}turn continued: ${clip(data.reason, 80)}`);
|
|
271
|
+
break;
|
|
272
|
+
case 'agent.clarification.requested':
|
|
273
|
+
line(`${where}asked the user a question`);
|
|
274
|
+
break;
|
|
275
|
+
default: line(`${where}${clip(type, 64)}: ${clip(data.message ?? data.reason ?? data.error ?? data.detail, 200)}`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/** `skipOpenRun` leaves out a last run that has not finished: in the reporting session, that run is the report itself. */
|
|
279
|
+
result(options = {}) {
|
|
280
|
+
const runs = options.skipOpenRun && this.runs.at(-1)?.finished === false ? this.runs.slice(0, -1) : this.runs;
|
|
281
|
+
const lines = [];
|
|
282
|
+
runs.forEach((run, index) => {
|
|
283
|
+
this.flush(run);
|
|
284
|
+
if (!run.lines.length)
|
|
285
|
+
return;
|
|
286
|
+
if (!run.lines[0].startsWith('run started'))
|
|
287
|
+
lines.push(`run ${index + 1}`);
|
|
288
|
+
lines.push(...run.lines.map((line, at) => at === 0 && line.startsWith('run started') ? `run ${index + 1}: ${line.slice(4)}` : ` ${line}`));
|
|
289
|
+
});
|
|
290
|
+
const graph = graphOutline(runs.findLast(run => run.graph !== undefined)?.graph);
|
|
291
|
+
return { ...(graph ? { graph } : {}), ...(lines.length ? { trajectory: fit(lines, TRAJECTORY_LIMIT) } : {}) };
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/** Whether this machine has a saved session or a trajectory under that id. */
|
|
295
|
+
export async function sessionExists(home, sessionId) {
|
|
296
|
+
if (!ID.test(sessionId))
|
|
297
|
+
return false;
|
|
298
|
+
const present = (path) => stat(path).then(entry => entry.isFile(), () => false);
|
|
299
|
+
return await present(join(home, 'sessions', `${sessionId}.json`)) || await present(join(home, 'trajectories', `${sessionId}.jsonl`));
|
|
300
|
+
}
|
|
301
|
+
/** The graph and compressed trajectory of one saved session, or nothing when the session left no trajectory. */
|
|
302
|
+
export async function sessionAttachments(home, sessionId, options = {}) {
|
|
303
|
+
if (!ID.test(sessionId))
|
|
304
|
+
return {};
|
|
305
|
+
let trajectoryId = sessionId;
|
|
306
|
+
try {
|
|
307
|
+
const saved = JSON.parse(await readFile(join(home, 'sessions', `${sessionId}.json`), 'utf8'));
|
|
308
|
+
if (validSavedSession(saved) && saved.id === sessionId && saved.trajectoryId && ID.test(saved.trajectoryId))
|
|
309
|
+
trajectoryId = saved.trajectoryId;
|
|
310
|
+
}
|
|
311
|
+
catch { }
|
|
312
|
+
const digest = new TrajectoryDigest();
|
|
313
|
+
const stream = createReadStream(join(home, 'trajectories', `${trajectoryId}.jsonl`), { encoding: 'utf8', ...(options.signal ? { signal: options.signal } : {}) });
|
|
314
|
+
try {
|
|
315
|
+
for await (const line of createInterface({ input: stream, crlfDelay: Infinity }))
|
|
316
|
+
digest.add(line);
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
options.signal?.throwIfAborted();
|
|
320
|
+
if (error.code !== 'ENOENT')
|
|
321
|
+
throw error;
|
|
322
|
+
}
|
|
323
|
+
finally {
|
|
324
|
+
stream.destroy();
|
|
325
|
+
}
|
|
326
|
+
return digest.result({ skipOpenRun: options.current === true });
|
|
327
|
+
}
|