@andorra-labs/code 0.1.8 → 0.1.9
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/THIRD_PARTY_NOTICES.md +2 -1
- package/dist/src/account-presentation.d.ts +11 -0
- package/dist/src/account-presentation.js +29 -2
- package/dist/src/agent-execution.js +37 -4
- package/dist/src/agent-mcp.d.ts +12 -0
- package/dist/src/agent-mcp.js +81 -2
- package/dist/src/app-server/protocol.d.ts +12 -0
- package/dist/src/app-server/reasoning.d.ts +0 -8
- package/dist/src/app-server/reasoning.js +15 -28
- package/dist/src/app-server.d.ts +7 -0
- package/dist/src/app-server.js +59 -11
- package/dist/src/auth/AuthManager.d.ts +15 -0
- package/dist/src/auth/AuthManager.js +66 -7
- package/dist/src/browser-runner.js +1 -2
- package/dist/src/browser-server.js +10 -2
- package/dist/src/browser-session.js +6 -2
- package/dist/src/browser-stealth.d.ts +29 -0
- package/dist/src/browser-stealth.js +166 -0
- package/dist/src/browser-ui/app.js +108 -13
- package/dist/src/browser-ui/icons/chevron-right.svg +8 -0
- package/dist/src/browser-ui/index.html +8 -8
- package/dist/src/browser-ui/style.css +199 -171
- package/dist/src/browser-ui/tokens.css +198 -0
- package/dist/src/browser-view.d.ts +57 -9
- package/dist/src/browser-view.js +187 -36
- package/dist/src/cli.js +21 -4
- package/dist/src/coding-tools.js +9 -5
- package/dist/src/command-screens.js +4 -4
- package/dist/src/commands.d.ts +1 -1
- package/dist/src/commands.js +2 -1
- package/dist/src/completion-gates.d.ts +35 -0
- package/dist/src/completion-gates.js +25 -0
- package/dist/src/completion.d.ts +6 -0
- package/dist/src/completion.js +36 -3
- package/dist/src/config.d.ts +1 -1
- package/dist/src/config.js +2 -2
- package/dist/src/context-budget.d.ts +11 -0
- package/dist/src/context-budget.js +13 -0
- package/dist/src/decision/DecisionEngine.d.ts +5 -1
- package/dist/src/decision/DecisionManager.d.ts +1 -0
- package/dist/src/decision/DecisionManager.js +14 -3
- package/dist/src/decision/FactContinuations.d.ts +6 -0
- package/dist/src/decision/FactContinuations.js +9 -1
- package/dist/src/decision/FactServiceGate.js +1 -1
- package/dist/src/decision/hostedSkills.d.ts +37 -0
- package/dist/src/decision/hostedSkills.js +64 -0
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +10 -2
- package/dist/src/decision/providers/AndorraDecisionProvider.js +121 -10
- package/dist/src/default-graph.d.ts +11 -0
- package/dist/src/default-graph.js +20 -0
- package/dist/src/duration.d.ts +13 -2
- package/dist/src/duration.js +27 -3
- package/dist/src/graph-manager-chat.d.ts +302 -0
- package/dist/src/graph-manager-chat.js +940 -0
- package/dist/src/graph-runner.js +6 -0
- package/dist/src/graph-server.d.ts +9 -0
- package/dist/src/graph-server.js +167 -16
- package/dist/src/graph-studio-features.js +2 -2
- package/dist/src/graph-sync.js +5 -2
- package/dist/src/graph-ui/app.js +252 -71
- package/dist/src/graph-ui/controls.css +55 -32
- package/dist/src/graph-ui/controls.js +85 -9
- package/dist/src/graph-ui/edge-router.js +114 -13
- package/dist/src/graph-ui/embed.js +23 -8
- package/dist/src/graph-ui/index.html +3 -3
- package/dist/src/graph-ui/library.css +4 -10
- package/dist/src/graph-ui/manager-markdown.js +155 -0
- package/dist/src/graph-ui/manager-state.js +191 -0
- package/dist/src/graph-ui/manager.css +161 -0
- package/dist/src/graph-ui/manager.js +700 -0
- package/dist/src/graph-ui/studio-canvas.js +2 -0
- package/dist/src/graph-ui/studio.css +24 -23
- package/dist/src/graph-ui/studio.js +29 -8
- package/dist/src/graph-ui/style.css +125 -92
- package/dist/src/graph-ui/tokens.css +217 -151
- package/dist/src/graphs.d.ts +69 -1
- package/dist/src/graphs.js +160 -7
- package/dist/src/hardened-runtime.js +8 -2
- package/dist/src/membership-errors.d.ts +14 -0
- package/dist/src/membership-errors.js +24 -1
- package/dist/src/membership.d.ts +20 -0
- package/dist/src/membership.js +45 -16
- package/dist/src/palette.d.ts +25 -8
- package/dist/src/palette.js +26 -8
- package/dist/src/provider-engine.d.ts +4 -4
- package/dist/src/provider-engine.js +39 -22
- package/dist/src/providers.d.ts +24 -0
- package/dist/src/providers.js +47 -2
- package/dist/src/qa/guidance.d.ts +26 -0
- package/dist/src/qa/guidance.js +59 -0
- package/dist/src/qa/index.d.ts +1 -6
- package/dist/src/qa/index.js +1 -14
- package/dist/src/qa/runtime/ProcessManager.d.ts +20 -2
- package/dist/src/qa/runtime/ProcessManager.js +69 -13
- package/dist/src/react-runtime.d.ts +11 -0
- package/dist/src/react-runtime.js +190 -51
- package/dist/src/remote/engine-pool.js +4 -1
- package/dist/src/run-progress.d.ts +6 -0
- package/dist/src/run-progress.js +7 -0
- package/dist/src/runtime.d.ts +8 -0
- package/dist/src/session-skills.d.ts +75 -0
- package/dist/src/session-skills.js +151 -0
- package/dist/src/side-panel.d.ts +1 -1
- package/dist/src/side-panel.js +6 -12
- package/dist/src/skill-commands.js +1 -1
- package/dist/src/skills/bundled/control-browser/SKILL.md +9 -1
- package/dist/src/skills/bundled/graph-manager/SKILL.md +8 -0
- package/dist/src/skills/bundled/provenance.json +3 -3
- package/dist/src/skills/bundled/web-gui-tester/SKILL.md +1 -1
- package/dist/src/stall-recovery.d.ts +22 -0
- package/dist/src/stall-recovery.js +71 -0
- package/dist/src/subagent-run.js +1 -2
- package/dist/src/terminal-ui.d.ts +2 -2
- package/dist/src/terminal-ui.js +18 -13
- package/dist/src/transcript.js +9 -1
- package/dist/src/types.d.ts +18 -4
- package/dist/src/usage-analytics.d.ts +7 -0
- package/dist/src/usage-analytics.js +55 -15
- package/docs/concepts/README.md +1 -1
- package/docs/concepts/limits.md +9 -0
- package/docs/guides/desktop-app.md +1 -1
- package/docs/guides/graph-builder.md +16 -1
- package/docs/reference/slash-commands.md +2 -1
- package/docs/superpowers/plans/2026-11-13-graph-manager-chat.md +203 -0
- package/docs/superpowers/plans/2026-11-14-jev-fair-use-pricing.md +79 -0
- package/docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md +182 -0
- package/docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md +156 -0
- package/package.json +1 -1
- package/tests/chat-side-panel-test-plan.md +1 -1
|
@@ -2,6 +2,7 @@ import { normalizeAnswers } from './HttpDecisionProvider.js';
|
|
|
2
2
|
import { validateBatch } from '../DecisionPolicy.js';
|
|
3
3
|
import { clipFactText, factProbability, FACT_LIMITS } from '../facts.js';
|
|
4
4
|
import { parseToolRouteEvidence } from '../routeTools.js';
|
|
5
|
+
import { abstainSkill, chunkSkills, expandSkillAnswer, HOSTED_SKILLS_PER_REQUEST, LEGACY_HOSTED_SKILLS_PER_REQUEST, mergeNoSkill } from '../hostedSkills.js';
|
|
5
6
|
const HOSTED_REQUEST_BYTES = 32_768;
|
|
6
7
|
const CLIP_MARKER = '\n…[Jev routing context clipped]…\n';
|
|
7
8
|
const DEFAULT_LIMITS = { task: 4096, instruction: 1536, skill: 256, result: 512, candidate: 256, failure: 256 };
|
|
@@ -115,16 +116,123 @@ async function decisionErrorBody(response, signal) {
|
|
|
115
116
|
reader.releaseLock();
|
|
116
117
|
}
|
|
117
118
|
}
|
|
119
|
+
/** How long before the caller's deadline skill-only requests are abandoned, leaving time to answer. */
|
|
120
|
+
const SKILL_DEADLINE_MARGIN_MS = 100;
|
|
121
|
+
/**
|
|
122
|
+
* Holds the response receipts of a batched preflight and publishes their sum as one, because
|
|
123
|
+
* consumers key usage by the logical request. A total stays missing if any part is missing.
|
|
124
|
+
*/
|
|
125
|
+
class UsageReceipts {
|
|
126
|
+
downstream;
|
|
127
|
+
receipts = [];
|
|
128
|
+
started = Date.now();
|
|
129
|
+
constructor(downstream) {
|
|
130
|
+
this.downstream = downstream;
|
|
131
|
+
}
|
|
132
|
+
dispatched = 0;
|
|
133
|
+
observe = observation => {
|
|
134
|
+
if (observation.kind === 'response') {
|
|
135
|
+
this.receipts.push(observation);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
this.dispatched++;
|
|
139
|
+
try {
|
|
140
|
+
this.downstream?.(observation);
|
|
141
|
+
}
|
|
142
|
+
catch { /* Metrics never change execution. */ }
|
|
143
|
+
};
|
|
144
|
+
publish() {
|
|
145
|
+
if (!this.receipts.length)
|
|
146
|
+
return;
|
|
147
|
+
// A request that was sent but returned no receipt (reset, aborted) makes every total unknown.
|
|
148
|
+
const complete = this.receipts.length >= this.dispatched;
|
|
149
|
+
const total = (key) => complete && this.receipts.every(receipt => receipt[key] !== undefined) ? this.receipts.reduce((sum, receipt) => sum + receipt[key], 0) : undefined;
|
|
150
|
+
const models = new Set(this.receipts.map(receipt => receipt.model));
|
|
151
|
+
try {
|
|
152
|
+
this.downstream?.({ kind: 'response', model: models.size === 1 ? this.receipts[0].model : undefined, physicalRequests: total('physicalRequests'),
|
|
153
|
+
inputTokens: total('inputTokens'), outputTokens: total('outputTokens'), cacheRead: total('cacheRead'), latencyMs: Date.now() - this.started });
|
|
154
|
+
}
|
|
155
|
+
catch { /* Metrics never change execution. */ }
|
|
156
|
+
}
|
|
157
|
+
}
|
|
118
158
|
/** Shared Jev credentials never enter the harness; only user access tokens cross this boundary. */
|
|
119
159
|
export class AndorraDecisionProvider {
|
|
120
160
|
dependencies;
|
|
121
161
|
constructor(dependencies) {
|
|
122
162
|
this.dependencies = dependencies;
|
|
123
163
|
}
|
|
124
|
-
async evaluate(state, questions, signal, observe) {
|
|
164
|
+
async evaluate(state, questions, signal, observe, options) {
|
|
165
|
+
signal?.throwIfAborted();
|
|
166
|
+
const skills = questionChoice(questions, 'skill_role').filter(id => id !== 'none');
|
|
167
|
+
if (skills.length <= LEGACY_HOSTED_SKILLS_PER_REQUEST)
|
|
168
|
+
return this.evaluateOnce(state, questions, signal, observe);
|
|
169
|
+
// Skill-only requests stop just before the caller's deadline, so a slow one costs its skills,
|
|
170
|
+
// not the answers that already arrived.
|
|
171
|
+
const remaining = options?.deadlineAt === undefined ? undefined : options.deadlineAt - Date.now() - SKILL_DEADLINE_MARGIN_MS;
|
|
172
|
+
const skillSignal = remaining === undefined ? signal : AbortSignal.any([...(signal ? [signal] : []), AbortSignal.timeout(Math.max(0, remaining))]);
|
|
173
|
+
// One preflight is one logical request: its batches' receipts are reported together, once.
|
|
174
|
+
const receipts = new UsageReceipts(observe);
|
|
175
|
+
try {
|
|
176
|
+
try {
|
|
177
|
+
return await this.evaluateBatched(state, questions, HOSTED_SKILLS_PER_REQUEST, signal, skillSignal, receipts.observe);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
// A proxy deployed before the 31-skill contract rejects 17 or more skills with a 400.
|
|
181
|
+
if (error.httpStatus !== 400)
|
|
182
|
+
throw error;
|
|
183
|
+
return await this.evaluateBatched(state, questions, LEGACY_HOSTED_SKILLS_PER_REQUEST, signal, skillSignal, receipts.observe);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
receipts.publish();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The skill question split into parallel requests of `size` skills, covering at most HOSTED_SKILL_LIMIT
|
|
192
|
+
* skills. The first request also carries every other question and runs on the caller's signal; the
|
|
193
|
+
* skill-only ones run on `skillSignal`. Each batch's probabilities only compare the skills it saw, so
|
|
194
|
+
* when two or more batches pick a skill their winners go to one final request.
|
|
195
|
+
*/
|
|
196
|
+
async evaluateBatched(state, questions, size, signal, skillSignal, observe) {
|
|
197
|
+
const choices = questionChoice(questions, 'skill_role');
|
|
198
|
+
const chunks = chunkSkills(choices.filter(id => id !== 'none'), size);
|
|
199
|
+
const skillQuestion = (ids) => ({ id: 'skill_role', type: 'choice', choices: ['none', ...ids] });
|
|
200
|
+
const others = questions.filter(question => question.id !== 'skill_role');
|
|
201
|
+
const settled = await Promise.allSettled(chunks.map((ids, index) => index === 0
|
|
202
|
+
? this.evaluateOnce(state, [...others, skillQuestion(ids)], signal, observe)
|
|
203
|
+
: this.evaluateOnce(state, [skillQuestion(ids)], skillSignal, observe)));
|
|
204
|
+
signal?.throwIfAborted();
|
|
205
|
+
const first = settled[0];
|
|
206
|
+
if (first.status === 'rejected')
|
|
207
|
+
throw first.reason;
|
|
208
|
+
const legacyRejection = settled.find(result => result.status === 'rejected' && result.reason.httpStatus === 400 && size > LEGACY_HOSTED_SKILLS_PER_REQUEST);
|
|
209
|
+
if (legacyRejection?.status === 'rejected')
|
|
210
|
+
throw legacyRejection.reason;
|
|
211
|
+
// A failed skill-only batch costs only its skills; the other questions are already answered.
|
|
212
|
+
const answers = settled.flatMap(result => result.status === 'fulfilled' && result.value.skill_role?.type === 'choice' ? [result.value.skill_role] : []);
|
|
213
|
+
const winners = answers.filter(answer => answer.choice !== 'none');
|
|
214
|
+
const { skill_role: _skill, ...rest } = first.value;
|
|
215
|
+
let skill_role;
|
|
216
|
+
if (!winners.length)
|
|
217
|
+
skill_role = mergeNoSkill(answers, choices);
|
|
218
|
+
else if (winners.length === 1)
|
|
219
|
+
skill_role = expandSkillAnswer(winners[0], choices);
|
|
220
|
+
else {
|
|
221
|
+
try {
|
|
222
|
+
const final = (await this.evaluateOnce(state, [skillQuestion(winners.map(answer => answer.choice))], skillSignal, observe)).skill_role;
|
|
223
|
+
skill_role = final?.type === 'choice' ? expandSkillAnswer(final, choices) : abstainSkill(choices);
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
signal?.throwIfAborted();
|
|
227
|
+
skill_role = abstainSkill(choices);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return validateBatch({ ...rest, skill_role }, questions);
|
|
231
|
+
}
|
|
232
|
+
async evaluateOnce(state, questions, signal, observe) {
|
|
125
233
|
signal?.throwIfAborted();
|
|
126
234
|
const contract = hostedSkillContract(questions);
|
|
127
|
-
const responseBody = await this.post(hostedBody(state, questions, contract), signal,
|
|
235
|
+
const responseBody = await this.post(hostedBody(state, questions, contract), signal, observe);
|
|
128
236
|
const batch = normalizeAnswers(responseBody.answers, contract.questions);
|
|
129
237
|
const skill = batch.skill_role;
|
|
130
238
|
if (!contract.originals.size || skill?.type !== 'choice')
|
|
@@ -144,7 +252,7 @@ export class AndorraDecisionProvider {
|
|
|
144
252
|
const body = JSON.stringify({ fact: fact.id, state: hostedFactState(fact) });
|
|
145
253
|
if (Buffer.byteLength(body, 'utf8') > HOSTED_REQUEST_BYTES)
|
|
146
254
|
throw new Error('decision_input_too_large');
|
|
147
|
-
const responseBody = await this.post(body, signal,
|
|
255
|
+
const responseBody = await this.post(body, signal, observe);
|
|
148
256
|
const answers = responseBody.answers;
|
|
149
257
|
if (!answers || typeof answers !== 'object' || Array.isArray(answers) || Object.keys(answers).length !== 1)
|
|
150
258
|
throw new Error('invalid_response');
|
|
@@ -158,13 +266,13 @@ export class AndorraDecisionProvider {
|
|
|
158
266
|
const body = JSON.stringify({ toolMenu: request });
|
|
159
267
|
if (Buffer.byteLength(body, 'utf8') > HOSTED_REQUEST_BYTES)
|
|
160
268
|
throw new Error('decision_input_too_large');
|
|
161
|
-
const response = await this.post(body, signal,
|
|
269
|
+
const response = await this.post(body, signal, observe);
|
|
162
270
|
const evidence = parseToolRouteEvidence(response.routing, request.options.map(option => option.id));
|
|
163
271
|
if (!evidence)
|
|
164
272
|
throw new Error('invalid_response');
|
|
165
273
|
return evidence;
|
|
166
274
|
}
|
|
167
|
-
async post(body, signal,
|
|
275
|
+
async post(body, signal, observe) {
|
|
168
276
|
const auth = this.dependencies ?? await (async () => {
|
|
169
277
|
const { getAccessToken, getAuthConfiguration } = await import('../../auth/index.js');
|
|
170
278
|
return { getAccessToken, apiBaseUrl: getAuthConfiguration().apiBaseUrl, fetch };
|
|
@@ -186,12 +294,15 @@ export class AndorraDecisionProvider {
|
|
|
186
294
|
const errorBody = await decisionErrorBody(response, signal);
|
|
187
295
|
if (errorBody)
|
|
188
296
|
reportDecisionUsage(errorBody, Date.now() - started, observe);
|
|
189
|
-
|
|
297
|
+
// The service keeps the daily error code for every allowance so older clients back off;
|
|
298
|
+
// `limitScope: 'window'` names the rolling 30-day allowance.
|
|
299
|
+
const quota = response.status === 429 && errorBody?.error === 'daily_limit_reached';
|
|
300
|
+
const windowQuota = quota && errorBody?.limitScope === 'window';
|
|
190
301
|
signal?.throwIfAborted();
|
|
191
|
-
// The
|
|
192
|
-
//
|
|
193
|
-
const reason =
|
|
194
|
-
:
|
|
302
|
+
// The request contract is compiled into the client. A 400/404/422 is the service refusing
|
|
303
|
+
// this request's shape, not an outage (and, for a fact, not evidence that it is false).
|
|
304
|
+
const reason = windowQuota ? 'decision_window_limit_reached' : quota ? 'decision_daily_limit_reached' : [401, 403].includes(response.status) ? 'authentication_required'
|
|
305
|
+
: [400, 404, 422].includes(response.status) ? 'decision_protocol_unsupported' : 'decision_service_unavailable';
|
|
195
306
|
throw Object.assign(new Error(reason), { httpStatus: response.status });
|
|
196
307
|
}
|
|
197
308
|
const reader = response.body?.getReader();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Graph } from './graphs.js';
|
|
2
|
+
/**
|
|
3
|
+
* The single Andorra Agent graph that a Default run executes: one agent and no Orchestrator intake.
|
|
4
|
+
*
|
|
5
|
+
* Both the run graph (`SOFTWARE_ENGINEER_HARNESS` in membership.ts) and the latest bundled `default`
|
|
6
|
+
* revision that Graph Studio shows (`DEFAULT_GRAPH` in graphs.ts) are built from this, so the editor
|
|
7
|
+
* cannot drift from what runs. It lives in its own module with no runtime imports because
|
|
8
|
+
* graphs.ts reaches membership.ts through its import graph; defining it in either one would leave
|
|
9
|
+
* the other reading it before initialization.
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEFAULT_AGENT_GRAPH: Pick<Graph, 'name' | 'entry' | 'nodes' | 'edges'>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single Andorra Agent graph that a Default run executes: one agent and no Orchestrator intake.
|
|
3
|
+
*
|
|
4
|
+
* Both the run graph (`SOFTWARE_ENGINEER_HARNESS` in membership.ts) and the latest bundled `default`
|
|
5
|
+
* revision that Graph Studio shows (`DEFAULT_GRAPH` in graphs.ts) are built from this, so the editor
|
|
6
|
+
* cannot drift from what runs. It lives in its own module with no runtime imports because
|
|
7
|
+
* graphs.ts reaches membership.ts through its import graph; defining it in either one would leave
|
|
8
|
+
* the other reading it before initialization.
|
|
9
|
+
*/
|
|
10
|
+
export const DEFAULT_AGENT_GRAPH = {
|
|
11
|
+
name: 'Andorra Agent', entry: 'engineer',
|
|
12
|
+
nodes: {
|
|
13
|
+
engineer: { id: 'engineer', name: 'Andorra Agent', type: 'agent', executor: 'react-basic',
|
|
14
|
+
instruction: 'Handle the user\'s task end to end, whether it is a coding task or a general one: implement code and verify changes with appropriate tools, and answer general research, writing and analysis directly from the available sources. Ask for clarification when needed. Report the result and any remaining issues. For follow-up questions, use the retained conversation and prior results first. Answer directly when they contain the answer; do not restart completed work or scan unrelated files. If no pull request was created or its number is unknown, say so rather than guessing. Start new implementation work only when the user requests it.',
|
|
15
|
+
contextPolicy: { history: true }, jevEnabled: true,
|
|
16
|
+
subagents: { enabled: false }, position: { x: 120, y: 120 } },
|
|
17
|
+
done: { id: 'done', name: 'Done', type: 'end', position: { x: 440, y: 120 } },
|
|
18
|
+
},
|
|
19
|
+
edges: [{ id: 'engineer-done', source: 'engineer', target: 'done', outcome: 'completed' }],
|
|
20
|
+
};
|
package/dist/src/duration.d.ts
CHANGED
|
@@ -17,9 +17,20 @@
|
|
|
17
17
|
*/
|
|
18
18
|
export declare function durationMs(ms: unknown): number | undefined;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
* one-decimal seconds (`1.2s`, `65.0s`).
|
|
20
|
+
* Whole seconds as spaced elapsed units: `45s`, `2m 3s`, `1h 2m 3s`.
|
|
22
21
|
*
|
|
22
|
+
* Every duration the terminal prints past a minute takes this one form: largest unit first, a
|
|
23
|
+
* space between units, and every unit below the largest carried down to the second so a boundary
|
|
24
|
+
* never hides where the figure stands (`1h 0m 5s`, not `1h 5s`). Minutes never run past 59 — a
|
|
25
|
+
* stretch of 105 minutes reads `1h 45m 18s`. Fractions floor and negatives clamp to `0s`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function formatHms(totalSeconds: number): string;
|
|
28
|
+
/**
|
|
29
|
+
* Renders a duration for display: whole milliseconds below one second (`123ms`, `0ms`),
|
|
30
|
+
* one-decimal seconds below a minute (`1.2s`, `59.4s`), then {@link formatHms} (`1m 5s`,
|
|
31
|
+
* `1h 45m 18s`).
|
|
32
|
+
*
|
|
33
|
+
* The minute cutoff is taken on the rounded figure, so 59.96 s reads `1m 0s` rather than `60.0s`.
|
|
23
34
|
* Returns `undefined` for anything `durationMs` rejects so the caller can omit the suffix
|
|
24
35
|
* entirely; this function never returns `NaN` or `undefined` as text.
|
|
25
36
|
*/
|
package/dist/src/duration.js
CHANGED
|
@@ -27,9 +27,30 @@ export function durationMs(ms) {
|
|
|
27
27
|
return value;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
* one-decimal seconds (`1.2s`, `65.0s`).
|
|
30
|
+
* Whole seconds as spaced elapsed units: `45s`, `2m 3s`, `1h 2m 3s`.
|
|
32
31
|
*
|
|
32
|
+
* Every duration the terminal prints past a minute takes this one form: largest unit first, a
|
|
33
|
+
* space between units, and every unit below the largest carried down to the second so a boundary
|
|
34
|
+
* never hides where the figure stands (`1h 0m 5s`, not `1h 5s`). Minutes never run past 59 — a
|
|
35
|
+
* stretch of 105 minutes reads `1h 45m 18s`. Fractions floor and negatives clamp to `0s`.
|
|
36
|
+
*/
|
|
37
|
+
export function formatHms(totalSeconds) {
|
|
38
|
+
const seconds = Math.max(0, Math.floor(totalSeconds));
|
|
39
|
+
const hours = Math.floor(seconds / 3600);
|
|
40
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
41
|
+
const rest = seconds % 60;
|
|
42
|
+
if (hours > 0)
|
|
43
|
+
return `${hours}h ${minutes}m ${rest}s`;
|
|
44
|
+
if (minutes > 0)
|
|
45
|
+
return `${minutes}m ${rest}s`;
|
|
46
|
+
return `${rest}s`;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Renders a duration for display: whole milliseconds below one second (`123ms`, `0ms`),
|
|
50
|
+
* one-decimal seconds below a minute (`1.2s`, `59.4s`), then {@link formatHms} (`1m 5s`,
|
|
51
|
+
* `1h 45m 18s`).
|
|
52
|
+
*
|
|
53
|
+
* The minute cutoff is taken on the rounded figure, so 59.96 s reads `1m 0s` rather than `60.0s`.
|
|
33
54
|
* Returns `undefined` for anything `durationMs` rejects so the caller can omit the suffix
|
|
34
55
|
* entirely; this function never returns `NaN` or `undefined` as text.
|
|
35
56
|
*/
|
|
@@ -39,7 +60,10 @@ export function formatDuration(ms) {
|
|
|
39
60
|
return undefined;
|
|
40
61
|
if (value < 1000)
|
|
41
62
|
return `${Math.round(value)}ms`;
|
|
42
|
-
|
|
63
|
+
const seconds = (value / 1000).toFixed(1);
|
|
64
|
+
if (Number(seconds) < 60)
|
|
65
|
+
return `${seconds}s`;
|
|
66
|
+
return formatHms(Math.round(value / 1000));
|
|
43
67
|
}
|
|
44
68
|
/** Monotonic clock source for a per-call start reading. */
|
|
45
69
|
export const monotonicNow = () => performance.now();
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import type { Readable, Writable } from 'node:stream';
|
|
2
|
+
/** The canvas a message is about: the editor's current definition, saved or not. */
|
|
3
|
+
export interface ManagerGraphContext {
|
|
4
|
+
graph: Record<string, unknown>;
|
|
5
|
+
saved: boolean;
|
|
6
|
+
revision?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ManagerTurn extends ManagerGraphContext {
|
|
9
|
+
provider: string;
|
|
10
|
+
model: string;
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
export type ManagerEvent = {
|
|
14
|
+
type: 'snapshot';
|
|
15
|
+
events: ManagerEvent[];
|
|
16
|
+
state: ManagerState;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'user';
|
|
19
|
+
text: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'assistant';
|
|
22
|
+
text: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* One tool call, opened `running` and settled in place by `tool.settled`. `text` is the whole
|
|
26
|
+
* line (also what an approval for the call says); `verb` and `target` are the same call split the
|
|
27
|
+
* way the app's transcript draws a row: what it did, and to what.
|
|
28
|
+
*/
|
|
29
|
+
| {
|
|
30
|
+
type: 'tool';
|
|
31
|
+
id: string;
|
|
32
|
+
text: string;
|
|
33
|
+
verb: string;
|
|
34
|
+
target?: string;
|
|
35
|
+
status: ManagerToolStatus;
|
|
36
|
+
reason?: string;
|
|
37
|
+
startedAt: number;
|
|
38
|
+
endedAt?: number;
|
|
39
|
+
} | {
|
|
40
|
+
type: 'tool.settled';
|
|
41
|
+
id: string;
|
|
42
|
+
status: Exclude<ManagerToolStatus, 'running'>;
|
|
43
|
+
reason?: string;
|
|
44
|
+
endedAt: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* One model call's reasoning: opened `thinking` (or reopened when a retried request restarts it),
|
|
48
|
+
* grown by `thought.delta`, and settled `done` with the authoritative text. A call that streamed
|
|
49
|
+
* no reasoning is `thought.removed`. Reasoning is display-only: it is kept in this conversation's
|
|
50
|
+
* memory for the panels and never written anywhere.
|
|
51
|
+
*/
|
|
52
|
+
| {
|
|
53
|
+
type: 'thought';
|
|
54
|
+
id: string;
|
|
55
|
+
text: string;
|
|
56
|
+
status: 'thinking' | 'done';
|
|
57
|
+
startedAt: number;
|
|
58
|
+
durationMs?: number;
|
|
59
|
+
truncated?: boolean;
|
|
60
|
+
} | {
|
|
61
|
+
type: 'thought.delta';
|
|
62
|
+
id: string;
|
|
63
|
+
text: string;
|
|
64
|
+
} | {
|
|
65
|
+
type: 'thought.removed';
|
|
66
|
+
id: string;
|
|
67
|
+
} | {
|
|
68
|
+
type: 'approval';
|
|
69
|
+
id: string;
|
|
70
|
+
text: string;
|
|
71
|
+
} | {
|
|
72
|
+
type: 'question';
|
|
73
|
+
id: string;
|
|
74
|
+
question: string;
|
|
75
|
+
choices?: string[];
|
|
76
|
+
} | {
|
|
77
|
+
type: 'resolved';
|
|
78
|
+
id: string;
|
|
79
|
+
} | {
|
|
80
|
+
type: 'state';
|
|
81
|
+
state: ManagerState;
|
|
82
|
+
} | {
|
|
83
|
+
type: 'error';
|
|
84
|
+
message: string;
|
|
85
|
+
} | {
|
|
86
|
+
type: 'graph.saved';
|
|
87
|
+
graphId: string;
|
|
88
|
+
revision: number;
|
|
89
|
+
name?: string;
|
|
90
|
+
}
|
|
91
|
+
/** The graph's latest revision is a deletion. It is never a revision to load. */
|
|
92
|
+
| {
|
|
93
|
+
type: 'graph.deleted';
|
|
94
|
+
graphId: string;
|
|
95
|
+
};
|
|
96
|
+
/** A graph's latest stored revision. Deleting a graph publishes one more, marked `metadata.deletedAt`. */
|
|
97
|
+
export interface ManagerGraphRevision {
|
|
98
|
+
revision: number;
|
|
99
|
+
deleted: boolean;
|
|
100
|
+
}
|
|
101
|
+
export type ManagerState = 'idle' | 'starting' | 'working' | 'awaiting';
|
|
102
|
+
/** `stopped` is a call the run ended without reporting the end of. */
|
|
103
|
+
export type ManagerToolStatus = 'running' | 'done' | 'failed' | 'stopped';
|
|
104
|
+
export interface EngineChild {
|
|
105
|
+
stdin: Writable;
|
|
106
|
+
stdout: Readable;
|
|
107
|
+
stderr: Readable;
|
|
108
|
+
once(event: 'close', fn: (code: number | null) => void): unknown;
|
|
109
|
+
on(event: 'error', fn: (e: Error) => void): unknown;
|
|
110
|
+
kill(): boolean;
|
|
111
|
+
}
|
|
112
|
+
export interface GraphManagerChatOptions {
|
|
113
|
+
/** The config directory (ANDORRACODE_HOME) the engine runs against. */
|
|
114
|
+
directory: string;
|
|
115
|
+
/** Starts the engine in `cwd`. The default spawns this build's `app-server --stdio`. */
|
|
116
|
+
spawnEngine?: (cwd: string) => EngineChild;
|
|
117
|
+
/** The latest stored revision of a graph and whether it is a deletion, or undefined when it has none. */
|
|
118
|
+
readRevision: (graphId: string) => Promise<ManagerGraphRevision | undefined>;
|
|
119
|
+
/** How long an idle engine with no subscriber is kept. Default ten minutes. */
|
|
120
|
+
idleMs?: number;
|
|
121
|
+
/** The clock rows are stamped with, in epoch milliseconds. Default `Date.now`. */
|
|
122
|
+
now?: () => number;
|
|
123
|
+
}
|
|
124
|
+
/** Mirrors `MAX_TASK_CHARS` in `app-server.ts`: the engine refuses a longer `run.start` task or `run.steer` text. */
|
|
125
|
+
export declare const MANAGER_TASK_MAX_CHARS = 100000;
|
|
126
|
+
/**
|
|
127
|
+
* One line saying what a tool call or an approval is about, for the tools Graph Manager works with:
|
|
128
|
+
* the `graphs` action and the graph it names, the skill being read, the server being connected.
|
|
129
|
+
* A publish names only its draft, so `graphOfDraft` supplies the graph when the caller knows it.
|
|
130
|
+
* Every other tool keeps the transcript's wording. The line is at most 120 characters.
|
|
131
|
+
*/
|
|
132
|
+
export declare function describeManagerTool(name: string, value: unknown, graphOfDraft?: (draftId: string) => string | undefined): string;
|
|
133
|
+
/**
|
|
134
|
+
* A tool call split the way the app's transcript draws it: the verb, and the thing it acted on.
|
|
135
|
+
* A node is named by its name when the call carries one; a connection reads `source → target`
|
|
136
|
+
* with its outcome. The graph the call is about is left out when it is the open one, which every
|
|
137
|
+
* call of a conversation usually is. Any other tool keeps the transcript's one line as its verb.
|
|
138
|
+
*/
|
|
139
|
+
export declare function managerToolParts(name: string, value: unknown, openGraphId?: string): {
|
|
140
|
+
verb: string;
|
|
141
|
+
target?: string;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* The environment the chat's engine starts in: the parent's own, so the engine is signed in as the
|
|
145
|
+
* parent is. Stored credentials are scoped to an explicitly named home (`credentialIdentity`), so
|
|
146
|
+
* naming even the default home would move the engine to an empty credential slot. The home is
|
|
147
|
+
* named only when the chat runs against a different one than the environment already selects.
|
|
148
|
+
*
|
|
149
|
+
* The engine is marked as a worker, as the automation runner marks its own. An unmarked engine is a
|
|
150
|
+
* window's: it runs the user's automations, watches their pull requests and archives old sessions.
|
|
151
|
+
* This one is stopped when idle and when the editor closes, which would interrupt an automation it
|
|
152
|
+
* had claimed. The mark switches off those three background services and nothing else.
|
|
153
|
+
*
|
|
154
|
+
* A relative inherited home means the parent's working directory, and the engine starts in its own
|
|
155
|
+
* workspace, where the same words would name another folder with another configuration and another
|
|
156
|
+
* credential slot. It is handed the absolute path instead, which `credentialIdentity` resolves to
|
|
157
|
+
* the scope the parent reads.
|
|
158
|
+
*/
|
|
159
|
+
export declare function managerEngineEnvironment(directory: string, environment?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
160
|
+
/**
|
|
161
|
+
* What the agent is given with every message: which graph is open, the canvas as the user sees it
|
|
162
|
+
* now (unsaved edits included), the model the panel has selected, and the user's own words.
|
|
163
|
+
*/
|
|
164
|
+
export declare function managerTask(turn: ManagerTurn): string;
|
|
165
|
+
/**
|
|
166
|
+
* One Graph Manager conversation, run on an engine of its own.
|
|
167
|
+
*
|
|
168
|
+
* The engine that hosts Graph Studio may be busy with the user's task and runs one task at a time,
|
|
169
|
+
* so the chat spawns a dedicated `app-server --stdio` child in an empty workspace and speaks the
|
|
170
|
+
* same line protocol the automation runner does. Every panel connected to the graph server shares
|
|
171
|
+
* this one conversation: each subscriber is caught up with a snapshot and then receives the stream.
|
|
172
|
+
*
|
|
173
|
+
* Failures on the engine's side are reported as `error` events rather than rejections, because the
|
|
174
|
+
* message that failed is already on every panel's transcript and the stream is where panels listen.
|
|
175
|
+
*/
|
|
176
|
+
export declare class GraphManagerChat {
|
|
177
|
+
private readonly options;
|
|
178
|
+
private readonly directory;
|
|
179
|
+
private readonly workspace;
|
|
180
|
+
private readonly idleMs;
|
|
181
|
+
private readonly listeners;
|
|
182
|
+
private transcript;
|
|
183
|
+
private state;
|
|
184
|
+
private engine;
|
|
185
|
+
private sessionId;
|
|
186
|
+
private runId;
|
|
187
|
+
/** The run whose terminal event has been handled; its late `run.start` answer must not revive it. */
|
|
188
|
+
private finishedRunId;
|
|
189
|
+
/** Approvals and questions the panel has been shown and nobody has settled yet. */
|
|
190
|
+
private readonly prompts;
|
|
191
|
+
/** `graphs` calls in flight, by tool call id: the line shown for each, and the graph a begin opens or a publish saves. */
|
|
192
|
+
private readonly graphCalls;
|
|
193
|
+
/** Which graph each draft is of, learned from `andorra_graph_begin`, so a publish can name its graph. */
|
|
194
|
+
private readonly drafts;
|
|
195
|
+
/** The latest revision reported for each graph the agent saved other than the open one. */
|
|
196
|
+
private readonly otherRevisions;
|
|
197
|
+
/** The model the latest message chose, for a steering message that has to be sent again as a run. */
|
|
198
|
+
private lastModel;
|
|
199
|
+
/**
|
|
200
|
+
* Messages a run ended without reading, oldest first, each already a whole task. The engine keeps
|
|
201
|
+
* them out of the session's history, so they stay here until an engine has accepted them.
|
|
202
|
+
*/
|
|
203
|
+
private unread;
|
|
204
|
+
/** The pair the latest run was started on or last switched to, to tell when a message changes it. */
|
|
205
|
+
private runModel;
|
|
206
|
+
private openGraphId;
|
|
207
|
+
private lastRevision;
|
|
208
|
+
private revisionCheck;
|
|
209
|
+
private cancelling;
|
|
210
|
+
/** How many times Stop was pressed, so a message still waiting to be sent can tell it was stopped too. */
|
|
211
|
+
private stops;
|
|
212
|
+
private closed;
|
|
213
|
+
/** Messages and resets are delivered one at a time, in the order they were asked for. */
|
|
214
|
+
private queue;
|
|
215
|
+
private idleTimer;
|
|
216
|
+
private idleWaiters;
|
|
217
|
+
private readonly now;
|
|
218
|
+
/** Names the rows of tool calls the engine reported without an id of their own. */
|
|
219
|
+
private toolRows;
|
|
220
|
+
constructor(options: GraphManagerChatOptions);
|
|
221
|
+
/** The listener is first handed the conversation so far as one snapshot, then every later event. */
|
|
222
|
+
subscribe(listener: (event: ManagerEvent) => void): () => void;
|
|
223
|
+
/** Start the conversation, continue it, or steer the run that is working. */
|
|
224
|
+
send(turn: ManagerTurn): Promise<void>;
|
|
225
|
+
approve(id: string, approved: boolean): Promise<void>;
|
|
226
|
+
answer(id: string, value: string): Promise<void>;
|
|
227
|
+
cancel(): Promise<void>;
|
|
228
|
+
/** Forget the session and the transcript. The engine stays for the next conversation. */
|
|
229
|
+
reset(): Promise<void>;
|
|
230
|
+
/** Cancel the run, stop the child and clear the timers. Nothing is started afterwards. */
|
|
231
|
+
close(): Promise<void>;
|
|
232
|
+
private enqueue;
|
|
233
|
+
private deliver;
|
|
234
|
+
/**
|
|
235
|
+
* Hands the engine every message a run ended without reading. A message leaves `unread` only when
|
|
236
|
+
* it is on its way to an engine: as the next run when nothing is working, else steered into the run
|
|
237
|
+
* that is. A run that is itself ending refuses the steer, and the message then waits for the run after it.
|
|
238
|
+
*/
|
|
239
|
+
private deliverUnread;
|
|
240
|
+
/**
|
|
241
|
+
* Moves the working run to the pair a message chose, when it differs from the pair the run is on.
|
|
242
|
+
* `overrideAllNodes: false` is the scope `run.start` gave the first pair: the run's own, which
|
|
243
|
+
* Graph Manager's one agent node (it names no model) and whatever it delegates to answer from.
|
|
244
|
+
* Undefined when the run is on the pair; otherwise why it is not.
|
|
245
|
+
*/
|
|
246
|
+
private switchRunModel;
|
|
247
|
+
private start;
|
|
248
|
+
private cancelRun;
|
|
249
|
+
private ensureEngine;
|
|
250
|
+
private spawnDefault;
|
|
251
|
+
private wire;
|
|
252
|
+
private request;
|
|
253
|
+
/** A deliberate stop: EOF lets the engine finish its own cleanup, and it is reaped if it does not. */
|
|
254
|
+
private stopEngine;
|
|
255
|
+
private onEngineEvent;
|
|
256
|
+
private onRunEvent;
|
|
257
|
+
/** Settles a tool row in place. A call reported without an id, or never opened, has no row to settle. */
|
|
258
|
+
private settleTool;
|
|
259
|
+
/**
|
|
260
|
+
* One model call's reasoning, folded into a single row the way the app's transcript folds it: a
|
|
261
|
+
* retried request restarts the row, deltas grow it, and the completion settles it with the
|
|
262
|
+
* authoritative text, or takes it away when the call streamed no reasoning at all.
|
|
263
|
+
*/
|
|
264
|
+
private onReasoning;
|
|
265
|
+
/**
|
|
266
|
+
* Rows a run left open when it ended: a call it never reported the end of is stopped, a thought
|
|
267
|
+
* still streaming keeps what it streamed, and one that streamed nothing is taken away.
|
|
268
|
+
*/
|
|
269
|
+
private settleOpenRows;
|
|
270
|
+
private describe;
|
|
271
|
+
private endGraphCall;
|
|
272
|
+
/**
|
|
273
|
+
* The `graphs` tool also lists and reads, so a save is told by the stored revision rising. The
|
|
274
|
+
* open graph is checked after every call. A publish of another graph (the only way the agent can
|
|
275
|
+
* save its work on the bundled preset) is checked under that graph's id, and reported with the
|
|
276
|
+
* name it was begun with so the panel can offer to open it; so is a delete or a restore of one.
|
|
277
|
+
*
|
|
278
|
+
* Deleting a graph also raises its revision: the new one carries `metadata.deletedAt`. That is
|
|
279
|
+
* reported as `graph.deleted`, never as a save, so no panel loads a deleted graph as an editable
|
|
280
|
+
* one. A restore publishes a live revision above it, which is a save like any other.
|
|
281
|
+
*/
|
|
282
|
+
private checkRevision;
|
|
283
|
+
/** The run is over, however it ended. */
|
|
284
|
+
private finish;
|
|
285
|
+
private resolvePrompt;
|
|
286
|
+
private resolvePrompts;
|
|
287
|
+
private setState;
|
|
288
|
+
/** Read through a call so a check after an await sees the state as it is then. */
|
|
289
|
+
private isIdle;
|
|
290
|
+
private whenIdle;
|
|
291
|
+
/** An engine is kept while a run is working or waiting on the user, and while any panel is connected. */
|
|
292
|
+
private armIdleStop;
|
|
293
|
+
private emit;
|
|
294
|
+
/** Sends an event without adding a row: it changes a row the transcript already holds. */
|
|
295
|
+
private broadcast;
|
|
296
|
+
/**
|
|
297
|
+
* Replaces the latest row `match` finds with `next` of it, and tells the panels with `event`.
|
|
298
|
+
* False when no row matches, so the caller can add one instead.
|
|
299
|
+
*/
|
|
300
|
+
private replace;
|
|
301
|
+
private deliverTo;
|
|
302
|
+
}
|