@andorra-labs/code 0.1.8 → 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/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 +57 -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 +120 -1
- package/dist/src/app-server/protocol.js +8 -1
- 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 +32 -0
- package/dist/src/app-server.js +214 -21
- package/dist/src/auth/AuthManager.d.ts +15 -0
- package/dist/src/auth/AuthManager.js +66 -7
- 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-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 +123 -28
- 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 +31 -9
- 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 +3 -2
- package/dist/src/completion-gates.d.ts +35 -0
- package/dist/src/completion-gates.js +25 -0
- package/dist/src/completion.d.ts +7 -1
- package/dist/src/completion.js +37 -4
- 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/checks.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/file-diff.d.ts +105 -0
- package/dist/src/file-diff.js +244 -0
- 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 +171 -20
- package/dist/src/graph-studio-features.js +2 -2
- package/dist/src/graph-sync.js +5 -2
- package/dist/src/graph-ui/app.js +369 -183
- 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 +32 -17
- package/dist/src/graph-ui/icons.js +1 -0
- package/dist/src/graph-ui/index.html +4 -4
- 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/skill-picker.js +6 -6
- package/dist/src/graph-ui/studio-canvas.js +17 -15
- package/dist/src/graph-ui/studio.css +24 -23
- package/dist/src/graph-ui/studio.js +69 -48
- package/dist/src/graph-ui/style.css +128 -93
- package/dist/src/graph-ui/theme.js +2 -2
- package/dist/src/graph-ui/tokens.css +217 -151
- package/dist/src/graphs.d.ts +76 -2
- package/dist/src/graphs.js +172 -9
- package/dist/src/hardened-runtime.js +8 -2
- package/dist/src/mcp.d.ts +75 -0
- package/dist/src/mcp.js +240 -8
- 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/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/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 +46 -0
- package/dist/src/qa/index.d.ts +1 -8
- package/dist/src/qa/index.js +1 -16
- package/dist/src/qa/profile/QaProfile.d.ts +5 -1
- package/dist/src/qa/profile/QaProfile.js +6 -2
- package/dist/src/qa/runtime/ProcessManager.d.ts +20 -2
- package/dist/src/qa/runtime/ProcessManager.js +69 -13
- package/dist/src/qa/tools.d.ts +19 -1
- package/dist/src/qa/tools.js +20 -145
- package/dist/src/react-runtime.d.ts +11 -0
- package/dist/src/react-runtime.js +203 -53
- package/dist/src/remote/engine-pool.js +21 -6
- 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/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/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 +33 -0
- package/dist/src/stall-recovery.js +83 -0
- package/dist/src/subagent-run.js +1 -2
- package/dist/src/telemetry/schema.d.ts +1 -1
- package/dist/src/telemetry/schema.js +1 -2
- package/dist/src/terminal-ui.d.ts +66 -22
- package/dist/src/terminal-ui.js +327 -92
- 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 +23 -3
- package/dist/src/types.d.ts +24 -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/guides/tui.md +9 -9
- 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
- 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
|
@@ -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,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A file's change as a reader checks it: hunks of a line diff with the line numbers of both sides.
|
|
3
|
+
*
|
|
4
|
+
* The transcript used to show an edit as the text the model asked to replace and the text it asked to
|
|
5
|
+
* write. That is the request, not the change: there are no line numbers, and a Write over an existing
|
|
6
|
+
* file shows every line as new. This module diffs the file as it was against the file as it is, the
|
|
7
|
+
* way `git diff` would, and returns the result as data a view can lay out — each line marked as kept,
|
|
8
|
+
* added or removed, numbered on the side it belongs to.
|
|
9
|
+
*
|
|
10
|
+
* The output is bounded twice. The diff itself is exact up to an edit distance the timeout allows;
|
|
11
|
+
* past that the changed middle is shown as removed then added, which is still a true diff, only a
|
|
12
|
+
* coarse one. The lines and characters returned are capped separately, and `hiddenLines` says how
|
|
13
|
+
* many diff lines the cap left out, so a view can say "N more lines" instead of implying the end.
|
|
14
|
+
*/
|
|
15
|
+
export interface FileDiffLine {
|
|
16
|
+
kind: 'context' | 'add' | 'del';
|
|
17
|
+
/** The line without its terminator (a trailing CR of a CRLF line is removed too). */
|
|
18
|
+
text: string;
|
|
19
|
+
/** The line's number in the file before the change; absent on an added line. */
|
|
20
|
+
oldLine?: number;
|
|
21
|
+
/** The line's number in the file after the change; absent on a removed line. */
|
|
22
|
+
newLine?: number;
|
|
23
|
+
/** This is the last line of its side and has no line terminator. */
|
|
24
|
+
noNewline?: true;
|
|
25
|
+
/** The text was cut at the per-line bound. */
|
|
26
|
+
clipped?: true;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* One hunk in unified-diff terms: a count of 0 is an empty side, whose start is the line before it.
|
|
30
|
+
* The counts describe the whole hunk; when the bound cut it, `lines` stops short of them.
|
|
31
|
+
*/
|
|
32
|
+
export interface FileDiffHunk {
|
|
33
|
+
oldStart: number;
|
|
34
|
+
oldLines: number;
|
|
35
|
+
newStart: number;
|
|
36
|
+
newLines: number;
|
|
37
|
+
lines: FileDiffLine[];
|
|
38
|
+
}
|
|
39
|
+
export interface FileDiff {
|
|
40
|
+
hunks: FileDiffHunk[];
|
|
41
|
+
/** Lines the whole change added and removed, whether or not the bound returned them. */
|
|
42
|
+
linesAdded: number;
|
|
43
|
+
linesRemoved: number;
|
|
44
|
+
/** Diff lines (context included) left out by the bound; 0 when the hunks are complete. */
|
|
45
|
+
hiddenLines: number;
|
|
46
|
+
/** A side had more than `DIFF_LINE_LIMIT` lines: there are no hunks, and the counts are coarse. */
|
|
47
|
+
coarse?: true;
|
|
48
|
+
}
|
|
49
|
+
/** One side of a diff: the file's bytes or text, or `null` for a file that does not exist. */
|
|
50
|
+
export type DiffSide = Buffer | string | null;
|
|
51
|
+
export type FileDiffResult = {
|
|
52
|
+
kind: 'text';
|
|
53
|
+
diff: FileDiff;
|
|
54
|
+
}
|
|
55
|
+
/** Either side is not UTF-8 text (a NUL byte, or bytes that do not decode). */
|
|
56
|
+
| {
|
|
57
|
+
kind: 'binary';
|
|
58
|
+
}
|
|
59
|
+
/** A side is past the size the line diff runs on; the counts are a cheaper measure, when it could be taken. */
|
|
60
|
+
| {
|
|
61
|
+
kind: 'too-large';
|
|
62
|
+
linesAdded?: number;
|
|
63
|
+
linesRemoved?: number;
|
|
64
|
+
};
|
|
65
|
+
export interface FileDiffOptions {
|
|
66
|
+
/** Unchanged lines kept around each change. */
|
|
67
|
+
context?: number;
|
|
68
|
+
/** The most diff lines returned, context included. */
|
|
69
|
+
maxLines?: number;
|
|
70
|
+
/** The most characters of line text returned, summed over every returned line. */
|
|
71
|
+
maxChars?: number;
|
|
72
|
+
/** A line longer than this is clipped. */
|
|
73
|
+
lineChars?: number;
|
|
74
|
+
}
|
|
75
|
+
/** Past this size a side is not line-diffed: the write limit of the file tools. */
|
|
76
|
+
export declare const DIFF_BYTE_LIMIT: number;
|
|
77
|
+
/**
|
|
78
|
+
* Past this many lines on either side a text is not split into lines: a newline-dense file inside the byte
|
|
79
|
+
* limit would otherwise cost one string per line before any bound applies.
|
|
80
|
+
*/
|
|
81
|
+
export declare const DIFF_LINE_LIMIT = 200000;
|
|
82
|
+
/** The text a side holds, `null` for an absent file, or `undefined` for content that is not UTF-8 text. */
|
|
83
|
+
export declare function decodeText(side: DiffSide): string | null | undefined;
|
|
84
|
+
/** How many lines a text has, without splitting it: a final line without a terminator counts. */
|
|
85
|
+
export declare function lineCount(text: string): number;
|
|
86
|
+
/** The diff between two sides of one file. */
|
|
87
|
+
export declare function fileDiff(before: DiffSide, after: DiffSide, options?: FileDiffOptions): FileDiffResult;
|
|
88
|
+
/**
|
|
89
|
+
* The diff of two texts, as `fileDiff` returns it for text sides.
|
|
90
|
+
*
|
|
91
|
+
* Work and memory are bounded by the change, not the file: the shared head and tail are trimmed before the
|
|
92
|
+
* match, the result is kept as stretches rather than one record per line, and lines past the output bound
|
|
93
|
+
* are counted without being built. A side with more than `DIFF_LINE_LIMIT` lines is not split into lines at
|
|
94
|
+
* all: the counts come from a scan of the shared ends, and `coarse` says there are no hunks for that reason.
|
|
95
|
+
*/
|
|
96
|
+
export declare function textDiff(oldText: string, newText: string, options?: FileDiffOptions): FileDiff;
|
|
97
|
+
/**
|
|
98
|
+
* Added and removed counts without splitting either text: the shared head and tail (whole lines) are found
|
|
99
|
+
* by scanning characters from each end, and every line between them counts as changed. Memory is the two
|
|
100
|
+
* strings; time is one pass over them.
|
|
101
|
+
*/
|
|
102
|
+
export declare function coarseCounts(oldText: string, newText: string): {
|
|
103
|
+
linesAdded: number;
|
|
104
|
+
linesRemoved: number;
|
|
105
|
+
};
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { diffArrays } from 'diff';
|
|
2
|
+
/** Past this size a side is not line-diffed: the write limit of the file tools. */
|
|
3
|
+
export const DIFF_BYTE_LIMIT = 8 * 1024 * 1024;
|
|
4
|
+
/**
|
|
5
|
+
* Past this many lines on either side a text is not split into lines: a newline-dense file inside the byte
|
|
6
|
+
* limit would otherwise cost one string per line before any bound applies.
|
|
7
|
+
*/
|
|
8
|
+
export const DIFF_LINE_LIMIT = 200_000;
|
|
9
|
+
/** How long the exact match may take before the changed middle is shown as a replacement. */
|
|
10
|
+
const MATCH_TIMEOUT_MS = 250;
|
|
11
|
+
/** The edit distance the exact match gives up at, whatever the time. */
|
|
12
|
+
const MATCH_EDIT_LIMIT = 4_000;
|
|
13
|
+
const DEFAULT_CONTEXT = 3;
|
|
14
|
+
const DEFAULT_MAX_LINES = 2_000;
|
|
15
|
+
const DEFAULT_MAX_CHARS = 512 * 1024;
|
|
16
|
+
const DEFAULT_LINE_CHARS = 2_000;
|
|
17
|
+
/** The text a side holds, `null` for an absent file, or `undefined` for content that is not UTF-8 text. */
|
|
18
|
+
export function decodeText(side) {
|
|
19
|
+
if (side === null)
|
|
20
|
+
return null;
|
|
21
|
+
if (typeof side === 'string')
|
|
22
|
+
return side.includes('\0') ? undefined : side;
|
|
23
|
+
if (side.includes(0))
|
|
24
|
+
return undefined;
|
|
25
|
+
try {
|
|
26
|
+
return new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(side);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function byteLength(side) {
|
|
33
|
+
if (side === null)
|
|
34
|
+
return 0;
|
|
35
|
+
return typeof side === 'string' ? Buffer.byteLength(side) : side.length;
|
|
36
|
+
}
|
|
37
|
+
/** A text's lines, each keeping its terminator so that a final line without one compares as different. */
|
|
38
|
+
function tokens(text) {
|
|
39
|
+
return text === '' ? [] : text.split(/(?<=\n)/);
|
|
40
|
+
}
|
|
41
|
+
/** How many lines a text has, without splitting it: a final line without a terminator counts. */
|
|
42
|
+
export function lineCount(text) {
|
|
43
|
+
if (text === '')
|
|
44
|
+
return 0;
|
|
45
|
+
let count = 0;
|
|
46
|
+
for (let at = text.indexOf('\n'); at >= 0; at = text.indexOf('\n', at + 1))
|
|
47
|
+
count++;
|
|
48
|
+
return text.endsWith('\n') ? count : count + 1;
|
|
49
|
+
}
|
|
50
|
+
function display(token) {
|
|
51
|
+
return token.endsWith('\r\n') ? token.slice(0, -2) : token.endsWith('\n') ? token.slice(0, -1) : token;
|
|
52
|
+
}
|
|
53
|
+
/** The diff between two sides of one file. */
|
|
54
|
+
export function fileDiff(before, after, options = {}) {
|
|
55
|
+
const oldText = decodeText(before);
|
|
56
|
+
const newText = decodeText(after);
|
|
57
|
+
if (oldText === undefined || newText === undefined)
|
|
58
|
+
return { kind: 'binary' };
|
|
59
|
+
if (byteLength(before) > DIFF_BYTE_LIMIT || byteLength(after) > DIFF_BYTE_LIMIT) {
|
|
60
|
+
return { kind: 'too-large', ...coarseCounts(oldText ?? '', newText ?? '') };
|
|
61
|
+
}
|
|
62
|
+
const diff = textDiff(oldText ?? '', newText ?? '', options);
|
|
63
|
+
if (diff.coarse)
|
|
64
|
+
return { kind: 'too-large', linesAdded: diff.linesAdded, linesRemoved: diff.linesRemoved };
|
|
65
|
+
return { kind: 'text', diff };
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The diff of two texts, as `fileDiff` returns it for text sides.
|
|
69
|
+
*
|
|
70
|
+
* Work and memory are bounded by the change, not the file: the shared head and tail are trimmed before the
|
|
71
|
+
* match, the result is kept as stretches rather than one record per line, and lines past the output bound
|
|
72
|
+
* are counted without being built. A side with more than `DIFF_LINE_LIMIT` lines is not split into lines at
|
|
73
|
+
* all: the counts come from a scan of the shared ends, and `coarse` says there are no hunks for that reason.
|
|
74
|
+
*/
|
|
75
|
+
export function textDiff(oldText, newText, options = {}) {
|
|
76
|
+
const context = Math.max(0, options.context ?? DEFAULT_CONTEXT);
|
|
77
|
+
const maxLines = Math.max(0, options.maxLines ?? DEFAULT_MAX_LINES);
|
|
78
|
+
const maxChars = Math.max(0, options.maxChars ?? DEFAULT_MAX_CHARS);
|
|
79
|
+
const lineChars = Math.max(1, options.lineChars ?? DEFAULT_LINE_CHARS);
|
|
80
|
+
if (lineCount(oldText) > DIFF_LINE_LIMIT || lineCount(newText) > DIFF_LINE_LIMIT) {
|
|
81
|
+
return { hunks: [], ...coarseCounts(oldText, newText), hiddenLines: 0, coarse: true };
|
|
82
|
+
}
|
|
83
|
+
const a = tokens(oldText);
|
|
84
|
+
const b = tokens(newText);
|
|
85
|
+
let head = 0;
|
|
86
|
+
while (head < a.length && head < b.length && a[head] === b[head])
|
|
87
|
+
head += 1;
|
|
88
|
+
let tail = 0;
|
|
89
|
+
while (tail < a.length - head && tail < b.length - head && a[a.length - 1 - tail] === b[b.length - 1 - tail])
|
|
90
|
+
tail += 1;
|
|
91
|
+
const midA = a.slice(head, a.length - tail);
|
|
92
|
+
const midB = b.slice(head, b.length - tail);
|
|
93
|
+
// The exact match runs on the changed middle only, bounded in time and edit distance; past either bound
|
|
94
|
+
// the middle is shown as removed then added, which is still a true diff.
|
|
95
|
+
let changes = midA.length && midB.length
|
|
96
|
+
? diffArrays(midA, midB, { timeout: MATCH_TIMEOUT_MS, maxEditLength: MATCH_EDIT_LIMIT })
|
|
97
|
+
: undefined;
|
|
98
|
+
changes ??= [
|
|
99
|
+
...(midA.length ? [{ value: midA, added: false, removed: true }] : []),
|
|
100
|
+
...(midB.length ? [{ value: midB, added: true, removed: false }] : []),
|
|
101
|
+
];
|
|
102
|
+
const runs = [];
|
|
103
|
+
if (head)
|
|
104
|
+
runs.push({ kind: 'context', oldStart: 1, newStart: 1, count: head, lines: a, offset: 0 });
|
|
105
|
+
let oldPos = head + 1, newPos = head + 1;
|
|
106
|
+
let linesAdded = 0, linesRemoved = 0;
|
|
107
|
+
for (const change of changes) {
|
|
108
|
+
const kind = change.added ? 'add' : change.removed ? 'del' : 'context';
|
|
109
|
+
runs.push({ kind, oldStart: oldPos, newStart: newPos, count: change.value.length, lines: change.value, offset: 0 });
|
|
110
|
+
if (kind !== 'add')
|
|
111
|
+
oldPos += change.value.length;
|
|
112
|
+
if (kind !== 'del')
|
|
113
|
+
newPos += change.value.length;
|
|
114
|
+
if (kind === 'add')
|
|
115
|
+
linesAdded += change.value.length;
|
|
116
|
+
else if (kind === 'del')
|
|
117
|
+
linesRemoved += change.value.length;
|
|
118
|
+
}
|
|
119
|
+
if (tail)
|
|
120
|
+
runs.push({ kind: 'context', oldStart: oldPos, newStart: newPos, count: tail, lines: a, offset: a.length - tail });
|
|
121
|
+
// Hunks: every changed stretch with `context` kept lines on each side, merged when the kept lines between
|
|
122
|
+
// two changes are no more than twice the context.
|
|
123
|
+
const grouped = [];
|
|
124
|
+
for (let index = 0; index < runs.length;) {
|
|
125
|
+
if (runs[index].kind === 'context') {
|
|
126
|
+
index++;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const parts = [];
|
|
130
|
+
const before = runs[index - 1];
|
|
131
|
+
if (before && context)
|
|
132
|
+
parts.push({ run: before, from: Math.max(0, before.count - context), to: before.count });
|
|
133
|
+
let at = index;
|
|
134
|
+
for (;;) {
|
|
135
|
+
parts.push({ run: runs[at], from: 0, to: runs[at].count });
|
|
136
|
+
const next = runs[at + 1];
|
|
137
|
+
if (!next) {
|
|
138
|
+
at += 1;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
if (next.kind !== 'context') {
|
|
142
|
+
at += 1;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (runs[at + 2] && next.count <= 2 * context) {
|
|
146
|
+
parts.push({ run: next, from: 0, to: next.count });
|
|
147
|
+
at += 2;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (context)
|
|
151
|
+
parts.push({ run: next, from: 0, to: Math.min(context, next.count) });
|
|
152
|
+
at += 2;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
grouped.push(parts);
|
|
156
|
+
index = at;
|
|
157
|
+
}
|
|
158
|
+
const hunks = [];
|
|
159
|
+
let emitted = 0, chars = 0, hidden = 0, full = maxLines === 0;
|
|
160
|
+
for (const parts of grouped) {
|
|
161
|
+
let oldLines = 0, newLines = 0;
|
|
162
|
+
for (const part of parts) {
|
|
163
|
+
if (part.run.kind !== 'add')
|
|
164
|
+
oldLines += part.to - part.from;
|
|
165
|
+
if (part.run.kind !== 'del')
|
|
166
|
+
newLines += part.to - part.from;
|
|
167
|
+
}
|
|
168
|
+
const first = parts[0];
|
|
169
|
+
const firstOld = parts.find(part => part.run.kind !== 'add');
|
|
170
|
+
const firstNew = parts.find(part => part.run.kind !== 'del');
|
|
171
|
+
// An empty side starts at the line before the change, as unified diff headers do.
|
|
172
|
+
const oldStart = firstOld ? firstOld.run.oldStart + firstOld.from : first.run.oldStart - 1;
|
|
173
|
+
const newStart = firstNew ? firstNew.run.newStart + firstNew.from : first.run.newStart - 1;
|
|
174
|
+
const lines = [];
|
|
175
|
+
for (const part of parts) {
|
|
176
|
+
if (full) {
|
|
177
|
+
hidden += part.to - part.from;
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
for (let k = part.from; k < part.to; k++) {
|
|
181
|
+
const token = part.run.lines[part.run.offset + k];
|
|
182
|
+
const whole = display(token);
|
|
183
|
+
const text = whole.length > lineChars ? whole.slice(0, lineChars) : whole;
|
|
184
|
+
if (emitted >= maxLines || chars + text.length > maxChars) {
|
|
185
|
+
full = true;
|
|
186
|
+
hidden += part.to - k;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
const line = { kind: part.run.kind, text };
|
|
190
|
+
if (part.run.kind !== 'add')
|
|
191
|
+
line.oldLine = part.run.oldStart + k;
|
|
192
|
+
if (part.run.kind !== 'del')
|
|
193
|
+
line.newLine = part.run.newStart + k;
|
|
194
|
+
if (!token.endsWith('\n'))
|
|
195
|
+
line.noNewline = true;
|
|
196
|
+
if (text.length < whole.length)
|
|
197
|
+
line.clipped = true;
|
|
198
|
+
lines.push(line);
|
|
199
|
+
emitted++;
|
|
200
|
+
chars += text.length;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (lines.length)
|
|
204
|
+
hunks.push({ oldStart, oldLines, newStart, newLines, lines });
|
|
205
|
+
}
|
|
206
|
+
return { hunks, linesAdded, linesRemoved, hiddenLines: hidden };
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Added and removed counts without splitting either text: the shared head and tail (whole lines) are found
|
|
210
|
+
* by scanning characters from each end, and every line between them counts as changed. Memory is the two
|
|
211
|
+
* strings; time is one pass over them.
|
|
212
|
+
*/
|
|
213
|
+
export function coarseCounts(oldText, newText) {
|
|
214
|
+
if (oldText === newText)
|
|
215
|
+
return { linesAdded: 0, linesRemoved: 0 };
|
|
216
|
+
const a = oldText, b = newText;
|
|
217
|
+
const min = Math.min(a.length, b.length);
|
|
218
|
+
let prefix = 0;
|
|
219
|
+
while (prefix < min && a.charCodeAt(prefix) === b.charCodeAt(prefix))
|
|
220
|
+
prefix++;
|
|
221
|
+
// Whole lines of the shared prefix: a line is shared only with its terminator.
|
|
222
|
+
let head = 0, headEnd = 0;
|
|
223
|
+
for (let at = a.indexOf('\n'); at >= 0 && at < prefix; at = a.indexOf('\n', at + 1)) {
|
|
224
|
+
head++;
|
|
225
|
+
headEnd = at + 1;
|
|
226
|
+
}
|
|
227
|
+
// The shared suffix, never reaching back into the shared head.
|
|
228
|
+
const room = Math.min(a.length - headEnd, b.length - headEnd);
|
|
229
|
+
let suffix = 0;
|
|
230
|
+
while (suffix < room && a.charCodeAt(a.length - 1 - suffix) === b.charCodeAt(b.length - 1 - suffix))
|
|
231
|
+
suffix++;
|
|
232
|
+
// Whole lines of the shared suffix: the lines that start inside it on both sides.
|
|
233
|
+
const startA = a.length - suffix, startB = b.length - suffix;
|
|
234
|
+
let tail = 0;
|
|
235
|
+
if (suffix > 0) {
|
|
236
|
+
for (let at = a.indexOf('\n', startA); at >= 0 && at < a.length - 1; at = a.indexOf('\n', at + 1))
|
|
237
|
+
tail++;
|
|
238
|
+
const lineStartA = startA === 0 || a.charCodeAt(startA - 1) === 10;
|
|
239
|
+
const lineStartB = startB === 0 || b.charCodeAt(startB - 1) === 10;
|
|
240
|
+
if (lineStartA && lineStartB)
|
|
241
|
+
tail++;
|
|
242
|
+
}
|
|
243
|
+
return { linesAdded: Math.max(0, lineCount(b) - head - tail), linesRemoved: Math.max(0, lineCount(a) - head - tail) };
|
|
244
|
+
}
|