@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
|
@@ -2,7 +2,8 @@ import { createHash, randomUUID } from 'node:crypto';
|
|
|
2
2
|
import { chmod, lstat, mkdir, open, readFile, readdir, realpath, rename, rm, rmdir, unlink, writeFile } from 'node:fs/promises';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { acquireSaveLock, SaveLockBusyError } from './save-lock.js';
|
|
5
|
-
import { fileDiff } from './file-diff.js';
|
|
5
|
+
import { decodeText, fileDiff } from './file-diff.js';
|
|
6
|
+
import { carriedUserLines, lineMap, linesWords, markAuthors, rangesOf, userLines, userRemovedLines } from './change-authors.js';
|
|
6
7
|
export const BASELINE_BYTE_LIMIT = 16 * 1024 * 1024;
|
|
7
8
|
export const LIST_DIFF_LINES = 200;
|
|
8
9
|
export const MAX_DIFF_LINES = 20_000;
|
|
@@ -124,7 +125,7 @@ async function readBlob(home, sessionId, hash) {
|
|
|
124
125
|
return bytes;
|
|
125
126
|
}
|
|
126
127
|
async function collectBlobs(home, sessionId, state) {
|
|
127
|
-
const referenced = new Set(state.changes.flatMap(change => change.baseline.kind === 'file' ? [change.baseline.hash] : []));
|
|
128
|
+
const referenced = new Set(state.changes.flatMap(change => [...(change.baseline.kind === 'file' ? [change.baseline.hash] : []), ...(change.agentSide ? [change.agentSide.hash] : [])]));
|
|
128
129
|
let names;
|
|
129
130
|
try {
|
|
130
131
|
names = await readdir(blobFolder(home, sessionId));
|
|
@@ -280,6 +281,7 @@ function summary(change) {
|
|
|
280
281
|
path: change.path, status: change.status, linesAdded: change.linesAdded, linesRemoved: change.linesRemoved,
|
|
281
282
|
...(change.binary ? { binary: true } : {}), ...(change.tooLarge ? { tooLarge: true } : {}),
|
|
282
283
|
...(change.modeChange ? { modeChange: change.modeChange } : {}), ...(change.lineEndings ? { lineEndings: change.lineEndings } : {}),
|
|
284
|
+
...(change.editedByUser ? { editedByUser: change.editedByUser } : {}),
|
|
283
285
|
undoable: change.baseline.kind !== 'unavailable', version: change.version,
|
|
284
286
|
firstChangedAt: change.firstChangedAt, updatedAt: change.updatedAt,
|
|
285
287
|
};
|
|
@@ -432,7 +434,7 @@ export class SessionChangeStore {
|
|
|
432
434
|
await collectBlobs(this.home, sessionId, state);
|
|
433
435
|
return snapshot(sessionId, state);
|
|
434
436
|
}
|
|
435
|
-
async recordWrite(sessionId, state, root, relative, before, created, review = true) {
|
|
437
|
+
async recordWrite(sessionId, state, root, relative, before, created, review = true, by = 'agent') {
|
|
436
438
|
const target = path.join(root, ...relative.split('/'));
|
|
437
439
|
if (before.kind === 'other')
|
|
438
440
|
return false;
|
|
@@ -472,8 +474,15 @@ export class SessionChangeStore {
|
|
|
472
474
|
const { binary: _binary, tooLarge: _tooLarge, modeChange: _modeChange, lineEndings: _lineEndings, diffLines: _diffLines, ...rest } = entry;
|
|
473
475
|
const modeChange = modeChangeOf(entry.baseline, after);
|
|
474
476
|
const lineEndings = lineEndingsOf(result, baselineBytes, after.kind === 'file' ? after.bytes : null);
|
|
475
|
-
|
|
476
|
-
|
|
477
|
+
// Who changed the file: a save from the Files tab marks it the person's, and an agent write to a file only they had
|
|
478
|
+
// changed makes it both of theirs. The record of what was last written follows either, so neither is "changed on disk".
|
|
479
|
+
const editedByUser = by === 'user' ? (index < 0 || entry.editedByUser === 'only' ? 'only' : 'also')
|
|
480
|
+
: entry.editedByUser === 'only' ? 'also' : entry.editedByUser;
|
|
481
|
+
const { editedByUser: _editedByUser, agentSide: _agentSide, ...unattributed } = rest;
|
|
482
|
+
const agentSide = await this.nextAgentSide(sessionId, entry, index < 0, by, before, after, baselineBytes);
|
|
483
|
+
entry = { ...unattributed, ...measured(result), ...(modeChange ? { modeChange } : {}), ...(lineEndings ? { lineEndings } : {}),
|
|
484
|
+
...(result.kind === 'text' ? { diffLines: result.diff.hiddenLines } : {}), ...(editedByUser ? { editedByUser } : {}),
|
|
485
|
+
...(agentSide ? { agentSide } : {}),
|
|
477
486
|
written, status: statusOf(entry.baseline, after), version: state.revision + 1, updatedAt: now };
|
|
478
487
|
if (index < 0)
|
|
479
488
|
state.changes.push(entry);
|
|
@@ -481,6 +490,80 @@ export class SessionChangeStore {
|
|
|
481
490
|
state.changes[index] = entry;
|
|
482
491
|
return true;
|
|
483
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* The agent's side of a file after a write (see `agentSide`). The person's first save over the agent's work keeps the
|
|
495
|
+
* file as the save found it; their later saves change nothing. An agent write to a file the person edited keeps what
|
|
496
|
+
* it wrote, and which of the person's lines it carried over. A file only the person changed has none.
|
|
497
|
+
*/
|
|
498
|
+
async nextAgentSide(sessionId, entry, fresh, by, before, after, baselineBytes) {
|
|
499
|
+
try {
|
|
500
|
+
if (by === 'user') {
|
|
501
|
+
if (fresh || entry.agentSide || entry.editedByUser === 'only')
|
|
502
|
+
return entry.agentSide;
|
|
503
|
+
// A file already both of theirs without an agent side (a record from before the split, or one whose agent side
|
|
504
|
+
// was dropped) cannot be told apart: what the save found holds the person's earlier lines too.
|
|
505
|
+
if (entry.editedByUser === 'also')
|
|
506
|
+
return undefined;
|
|
507
|
+
const bytes = before.kind === 'file' ? before.bytes : before.kind === 'stored' ? await readBlob(this.home, sessionId, before.hash) : undefined;
|
|
508
|
+
if (!bytes || decodeText(bytes) === undefined)
|
|
509
|
+
return undefined;
|
|
510
|
+
const hash = hashOf(bytes);
|
|
511
|
+
await writeBlob(this.home, sessionId, hash, bytes);
|
|
512
|
+
return { hash, size: bytes.length };
|
|
513
|
+
}
|
|
514
|
+
if (!entry.agentSide && entry.editedByUser !== 'only')
|
|
515
|
+
return undefined;
|
|
516
|
+
if (after.kind !== 'file')
|
|
517
|
+
return undefined;
|
|
518
|
+
// What this write replaced must be what was last recorded: lines written some other way (the shell, another
|
|
519
|
+
// editor) are no one's we know, so the split is dropped rather than giving them to the person.
|
|
520
|
+
const beforeHash = before.kind === 'file' ? hashOf(before.bytes) : before.kind === 'stored' ? before.hash : undefined;
|
|
521
|
+
if (entry.written.kind !== 'file' || beforeHash !== entry.written.hash)
|
|
522
|
+
return undefined;
|
|
523
|
+
const afterText = decodeText(after.bytes);
|
|
524
|
+
const previous = entry.agentSide ? await readBlob(this.home, sessionId, entry.agentSide.hash) : baselineBytes;
|
|
525
|
+
const previousText = previous === null ? '' : decodeText(previous);
|
|
526
|
+
const beforeBytes = before.kind === 'file' ? before.bytes : before.kind === 'stored' ? await readBlob(this.home, sessionId, before.hash) : before.kind === 'absent' ? Buffer.alloc(0) : undefined;
|
|
527
|
+
const beforeText = beforeBytes === undefined ? undefined : decodeText(beforeBytes);
|
|
528
|
+
if (typeof afterText !== 'string' || typeof previousText !== 'string' || typeof beforeText !== 'string')
|
|
529
|
+
return undefined;
|
|
530
|
+
const baselineText = baselineBytes === null ? '' : decodeText(baselineBytes);
|
|
531
|
+
if (typeof baselineText !== 'string')
|
|
532
|
+
return undefined;
|
|
533
|
+
const carried = carriedUserLines(previousText, entry.agentSide?.userLines ?? [], beforeText, afterText);
|
|
534
|
+
const removedBefore = userRemovedLines(baselineText, previousText, beforeText, entry.agentSide?.userRemoved ?? []);
|
|
535
|
+
if (carried === undefined || removedBefore === undefined)
|
|
536
|
+
return undefined;
|
|
537
|
+
// Of the lines the person removed, those the agent's text still lacks stay theirs.
|
|
538
|
+
const gone = lineMap(baselineText, afterText)?.removed;
|
|
539
|
+
const removed = gone ? rangesOf([...removedBefore].filter(line => gone.has(line))) : [];
|
|
540
|
+
const hash = hashOf(after.bytes);
|
|
541
|
+
await writeBlob(this.home, sessionId, hash, after.bytes);
|
|
542
|
+
return { hash, size: after.bytes.length, ...(carried.length ? { userLines: carried } : {}), ...(removed.length ? { userRemoved: removed } : {}) };
|
|
543
|
+
}
|
|
544
|
+
catch {
|
|
545
|
+
return undefined;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
/** The texts that tell the person's lines from the agent's, or undefined when the file's record cannot. */
|
|
549
|
+
async authorTexts(sessionId, stored, baselineBytes, current) {
|
|
550
|
+
if (!stored.editedByUser || current.kind !== 'file')
|
|
551
|
+
return undefined;
|
|
552
|
+
if (stored.editedByUser === 'also' && !stored.agentSide)
|
|
553
|
+
return undefined;
|
|
554
|
+
try {
|
|
555
|
+
const baseline = baselineBytes === null ? '' : decodeText(baselineBytes);
|
|
556
|
+
const agentBytes = stored.agentSide ? await readBlob(this.home, sessionId, stored.agentSide.hash) : baselineBytes;
|
|
557
|
+
const agent = agentBytes === null ? '' : decodeText(agentBytes);
|
|
558
|
+
const now = decodeText(current.bytes);
|
|
559
|
+
if (typeof baseline !== 'string' || typeof agent !== 'string' || typeof now !== 'string')
|
|
560
|
+
return undefined;
|
|
561
|
+
return { baseline, agent, current: now, carried: stored.agentSide?.userLines ?? [], carriedRemoved: stored.agentSide?.userRemoved ?? [] };
|
|
562
|
+
}
|
|
563
|
+
catch {
|
|
564
|
+
return undefined;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
484
567
|
async pending(sessionId) {
|
|
485
568
|
return snapshot(sessionId, await readState(this.home, sessionId));
|
|
486
569
|
}
|
|
@@ -536,6 +619,12 @@ export class SessionChangeStore {
|
|
|
536
619
|
}
|
|
537
620
|
result = fileDiff(baselineBytes, current.kind === 'file' ? current.bytes : null, { maxLines: Math.max(0, maxLines), maxChars: Math.max(0, maxChars), lineChars: LINE_CHARS });
|
|
538
621
|
}
|
|
622
|
+
// Lines changed outside the recorded writes are no one's we know, so a file changed on disk is not split.
|
|
623
|
+
if (result.kind === 'text' && result.diff.hunks.length && sameAsWritten(stored.written, current)) {
|
|
624
|
+
const texts = await this.authorTexts(sessionId, stored, baselineBytes, current);
|
|
625
|
+
if (texts)
|
|
626
|
+
markAuthors(result.diff.hunks, texts.baseline, texts.agent, texts.current, texts.carried, texts.carriedRemoved);
|
|
627
|
+
}
|
|
539
628
|
const { binary: _binary, tooLarge: _tooLarge, modeChange: _modeChange, lineEndings: _lineEndings, ...base } = summary(stored);
|
|
540
629
|
const modeChange = modeChangeOf(stored.baseline, current);
|
|
541
630
|
const lineEndings = lineEndingsOf(result, baselineBytes, current.kind === 'file' ? current.bytes : null);
|
|
@@ -608,6 +697,14 @@ export class SessionChangeStore {
|
|
|
608
697
|
failed.push({ path: change.path, message: errorText(error) });
|
|
609
698
|
continue;
|
|
610
699
|
}
|
|
700
|
+
if (!force && change.editedByUser && sameAsWritten(change.written, current)) {
|
|
701
|
+
const lines = await this.userLinesNow(sessionId, change, current);
|
|
702
|
+
const yours = lines?.length ? ` ${linesWords(lines)}` : '';
|
|
703
|
+
conflicts.push({ path: change.path, reason: 'user-edited', ...(lines?.length ? { userLines: lines } : {}), message: change.editedByUser === 'only'
|
|
704
|
+
? `You edited this file${yours ? ` (${yours.trim()})` : ''} in the Files tab. Undo puts back the file from before your edits.`
|
|
705
|
+
: `You also edited${yours || ' this file'} in the Files tab. Undo puts back the file from before the agent, which discards ${yours ? 'those lines' : 'your edits'} too.` });
|
|
706
|
+
continue;
|
|
707
|
+
}
|
|
611
708
|
if (!force && !sameAsWritten(change.written, current)) {
|
|
612
709
|
conflicts.push({ path: change.path, reason: 'changed-on-disk', message: current.kind === 'absent'
|
|
613
710
|
? 'The file was deleted after the agent last wrote it.'
|
|
@@ -617,7 +714,7 @@ export class SessionChangeStore {
|
|
|
617
714
|
}
|
|
618
715
|
ready.push({ change, current });
|
|
619
716
|
}
|
|
620
|
-
const blocked = !force && conflicts.some(conflict => conflict.reason === 'changed-on-disk');
|
|
717
|
+
const blocked = !force && conflicts.some(conflict => conflict.reason === 'changed-on-disk' || conflict.reason === 'user-edited');
|
|
621
718
|
const reverted = [];
|
|
622
719
|
if (!blocked) {
|
|
623
720
|
if (ready.length)
|
|
@@ -641,6 +738,22 @@ export class SessionChangeStore {
|
|
|
641
738
|
}
|
|
642
739
|
return { ...snapshot(sessionId, state), reverted, conflicts, failed };
|
|
643
740
|
}
|
|
741
|
+
/** The person's lines in the file now, as ranges, or undefined when they cannot be told apart. */
|
|
742
|
+
async userLinesNow(sessionId, change, current) {
|
|
743
|
+
let baselineBytes = null;
|
|
744
|
+
try {
|
|
745
|
+
if (change.baseline.kind === 'file')
|
|
746
|
+
baselineBytes = await readBlob(this.home, sessionId, change.baseline.hash);
|
|
747
|
+
}
|
|
748
|
+
catch {
|
|
749
|
+
return undefined;
|
|
750
|
+
}
|
|
751
|
+
const texts = await this.authorTexts(sessionId, change, baselineBytes, current);
|
|
752
|
+
if (!texts)
|
|
753
|
+
return undefined;
|
|
754
|
+
const lines = userLines(texts.agent, texts.current, texts.carried);
|
|
755
|
+
return lines ? rangesOf(lines) : undefined;
|
|
756
|
+
}
|
|
644
757
|
async restore(sessionId, change, current) {
|
|
645
758
|
const root = await realpath(change.root);
|
|
646
759
|
const target = path.join(root, ...change.path.split('/'));
|
|
@@ -677,12 +790,87 @@ export class SessionChangeStore {
|
|
|
677
790
|
throw error;
|
|
678
791
|
}
|
|
679
792
|
}
|
|
793
|
+
/**
|
|
794
|
+
* Saves a file from the Files tab, only if it still holds what the person loaded (`expectedHash`, the SHA-256 of its
|
|
795
|
+
* bytes), so a save never replaces a newer copy the agent wrote. The file is written in place (its mode, owner and
|
|
796
|
+
* links stay), under the same per-file lock the agent's writes take. With a session, the save is recorded as the
|
|
797
|
+
* person's in that session's changes: the record of the written content moves with it, so the file is not reported
|
|
798
|
+
* "changed on disk", and a file the agent never touched becomes a change of theirs.
|
|
799
|
+
*/
|
|
800
|
+
async userWrite(input) {
|
|
801
|
+
const { sessionId, root, relative, bytes, expectedHash, onError } = input;
|
|
802
|
+
if (sessionId !== undefined)
|
|
803
|
+
sessionChangesId(sessionId);
|
|
804
|
+
const target = path.join(root, ...relative.split('/'));
|
|
805
|
+
if (!within(root, target) || target === root)
|
|
806
|
+
throw new Error('The path is outside the project');
|
|
807
|
+
const releaseFiles = await holdFiles(this.home, [fileLockKey(root, relative)]);
|
|
808
|
+
try {
|
|
809
|
+
const write = async () => {
|
|
810
|
+
const before = await observe(target, this.baselineLimit);
|
|
811
|
+
if (before.kind === 'absent')
|
|
812
|
+
return { written: false, reason: 'deleted' };
|
|
813
|
+
if (before.kind !== 'file')
|
|
814
|
+
return { written: false, reason: 'changed' };
|
|
815
|
+
const current = hashOf(before.bytes);
|
|
816
|
+
if (current !== expectedHash)
|
|
817
|
+
return { written: false, reason: 'changed', hash: current };
|
|
818
|
+
const hash = hashOf(bytes);
|
|
819
|
+
// The same bytes: nothing to write, and nothing the person changed.
|
|
820
|
+
if (hash === current)
|
|
821
|
+
return { written: true, hash, size: bytes.length };
|
|
822
|
+
await writeInPlace(target, bytes, before.bytes);
|
|
823
|
+
if (sessionId === undefined)
|
|
824
|
+
return { written: true, hash, size: bytes.length };
|
|
825
|
+
let changes;
|
|
826
|
+
try {
|
|
827
|
+
const state = await readState(this.home, sessionId);
|
|
828
|
+
if (await this.recordWrite(sessionId, state, root, relative, before, [], true, 'user')) {
|
|
829
|
+
state.revision += 1;
|
|
830
|
+
await writeState(this.home, sessionId, state);
|
|
831
|
+
await collectBlobs(this.home, sessionId, state);
|
|
832
|
+
changes = snapshot(sessionId, state);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
catch (error) {
|
|
836
|
+
// The file is saved; only its place in the review could not be recorded.
|
|
837
|
+
onError?.(error);
|
|
838
|
+
await readState(this.home, sessionId).then(state => collectBlobs(this.home, sessionId, state)).catch(() => { });
|
|
839
|
+
}
|
|
840
|
+
return { written: true, hash, size: bytes.length, ...(changes ? { changes } : {}) };
|
|
841
|
+
};
|
|
842
|
+
return sessionId === undefined ? await write() : await withSession(this.home, sessionId, write);
|
|
843
|
+
}
|
|
844
|
+
finally {
|
|
845
|
+
await releaseFiles();
|
|
846
|
+
}
|
|
847
|
+
}
|
|
680
848
|
async remove(sessionId) {
|
|
681
849
|
await withSession(this.home, sessionId, async () => {
|
|
682
850
|
await rm(sessionFolder(this.home, sessionId), { recursive: true, force: true });
|
|
683
851
|
});
|
|
684
852
|
}
|
|
685
853
|
}
|
|
854
|
+
/**
|
|
855
|
+
* Writes a file in place (its mode, owner and links stay), never creating it: a file removed since it was checked is
|
|
856
|
+
* an error, not a new file. A write that fails part way puts the old bytes back.
|
|
857
|
+
*/
|
|
858
|
+
async function writeInPlace(target, bytes, previous) {
|
|
859
|
+
const handle = await open(target, 'r+');
|
|
860
|
+
try {
|
|
861
|
+
try {
|
|
862
|
+
await handle.write(bytes, 0, bytes.length, 0);
|
|
863
|
+
await handle.truncate(bytes.length);
|
|
864
|
+
}
|
|
865
|
+
catch (error) {
|
|
866
|
+
await handle.write(previous, 0, previous.length, 0).then(() => handle.truncate(previous.length)).catch(() => { });
|
|
867
|
+
throw error;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
finally {
|
|
871
|
+
await handle.close();
|
|
872
|
+
}
|
|
873
|
+
}
|
|
686
874
|
async function nearestExisting(folder, root) {
|
|
687
875
|
for (let current = folder;; current = path.dirname(current)) {
|
|
688
876
|
try {
|
|
@@ -262,7 +262,8 @@ export async function getAgentSession(directory, sessionId, historyLimit = 0, hi
|
|
|
262
262
|
throw new SessionQueryError('INVALID_SESSION_ID', 'sessionId must be a valid UUID.');
|
|
263
263
|
nonnegativeInt(historyLimit, 'historyLimit', 20);
|
|
264
264
|
nonnegativeInt(historyOffset, 'historyOffset', 100_000);
|
|
265
|
-
|
|
265
|
+
// Asked for by id, a hidden session (a review run's) is found too; only the lists leave it out.
|
|
266
|
+
const state = await loadSessionQueryState(directory, () => store.list(undefined, { includeHidden: true }));
|
|
266
267
|
const session = state.all.find(item => item.id === sessionId);
|
|
267
268
|
if (!session)
|
|
268
269
|
throw new SessionQueryError('SESSION_NOT_FOUND', 'Session ' + sessionId + ' was not found.');
|
|
@@ -5,4 +5,4 @@ export interface AutoArchivePlan {
|
|
|
5
5
|
restore: string[];
|
|
6
6
|
}
|
|
7
7
|
export declare function idleFor(session: Pick<SavedSession, 'updatedAt'>, days: number, now: number): boolean;
|
|
8
|
-
export declare function planAutoArchive(sessions: readonly Pick<SavedSession, 'id' | 'updatedAt' | 'archived' | 'autoArchived'>[], days: number | undefined, now: number, busy?: (id: string) => boolean): AutoArchivePlan;
|
|
8
|
+
export declare function planAutoArchive(sessions: readonly Pick<SavedSession, 'id' | 'updatedAt' | 'archived' | 'autoArchived' | 'pinned' | 'parentId' | 'ancestors'>[], days: number | undefined, now: number, busy?: (id: string) => boolean): AutoArchivePlan;
|
|
@@ -5,6 +5,11 @@ export function idleFor(session, days, now) {
|
|
|
5
5
|
}
|
|
6
6
|
export function planAutoArchive(sessions, days, now, busy = () => false) {
|
|
7
7
|
const plan = { archive: [], restore: [] };
|
|
8
|
+
// A pin holds its whole family on the rail: the continuation of a pinned task is often the live conversation.
|
|
9
|
+
const pinned = new Set(sessions.filter(session => session.pinned === true && session.archived !== true).map(session => session.id));
|
|
10
|
+
const held = (session) => session.pinned === true
|
|
11
|
+
|| (session.parentId !== undefined && pinned.has(session.parentId))
|
|
12
|
+
|| (session.ancestors ?? []).some(id => pinned.has(id));
|
|
8
13
|
for (const session of sessions) {
|
|
9
14
|
if (busy(session.id))
|
|
10
15
|
continue;
|
|
@@ -12,7 +17,7 @@ export function planAutoArchive(sessions, days, now, busy = () => false) {
|
|
|
12
17
|
if (session.autoArchived === true && (days === undefined || !idleFor(session, days, now)))
|
|
13
18
|
plan.restore.push(session.id);
|
|
14
19
|
}
|
|
15
|
-
else if (days !== undefined && idleFor(session, days, now))
|
|
20
|
+
else if (!held(session) && days !== undefined && idleFor(session, days, now))
|
|
16
21
|
plan.archive.push(session.id);
|
|
17
22
|
}
|
|
18
23
|
return plan;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ProviderConfig } from './providers.js';
|
|
2
2
|
import type { ModelAdapter } from './types.js';
|
|
3
|
-
|
|
3
|
+
/** A relayed provider's model is on the desktop; a title is not worth a request there. */
|
|
4
|
+
export declare const titleRequestSupported: (provider: Pick<ProviderConfig, "type">) => boolean;
|
|
4
5
|
export declare const SESSION_SUMMARY_TIMEOUT_MS = 120000;
|
|
5
6
|
export declare const MAX_SESSION_TITLE_CHARS = 80;
|
|
6
7
|
export declare function summarizeSessionPrompt(prompt: string, adapter: ModelAdapter, model: string, signal?: AbortSignal): Promise<string>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { stripVTControlCharacters } from 'node:util';
|
|
2
2
|
import { redactSecrets } from './secret-redaction.js';
|
|
3
|
-
|
|
3
|
+
/** A relayed provider's model is on the desktop; a title is not worth a request there. */
|
|
4
|
+
export const titleRequestSupported = (provider) => provider.type !== 'relayed';
|
|
4
5
|
export const SESSION_SUMMARY_TIMEOUT_MS = 120_000;
|
|
5
6
|
export const MAX_SESSION_TITLE_CHARS = 80;
|
|
6
7
|
const MAX_PROMPT_CHARS = 4_000;
|
package/dist/src/sessions.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ConversationTurn } from './commands.js';
|
|
2
2
|
import { type SessionGoal } from './session-goal.js';
|
|
3
|
+
import { type SessionCheckout } from './task-checkout.js';
|
|
3
4
|
import type { Usage } from './types.js';
|
|
4
5
|
export declare const sessionName: (prompt: string) => string;
|
|
5
6
|
export interface SavedWidget {
|
|
@@ -36,11 +37,41 @@ export interface SavedSession {
|
|
|
36
37
|
context?: SavedContextReading;
|
|
37
38
|
archived?: boolean;
|
|
38
39
|
autoArchived?: boolean;
|
|
40
|
+
/** Pinned by the user to the top of its project in the rail. Archiving clears it, and auto-archive leaves a pinned session alone. */
|
|
41
|
+
pinned?: boolean;
|
|
39
42
|
renamed?: boolean;
|
|
40
43
|
goal?: SessionGoal;
|
|
41
44
|
jevEnabled?: boolean;
|
|
45
|
+
/** Set on a session another part of Andorra started for itself, such as a review run; such a session is kept out of every list. */
|
|
46
|
+
origin?: SessionOrigin;
|
|
47
|
+
/** Where the task works: its own worktree, or the project folder. Absent on tasks from before it was recorded. */
|
|
48
|
+
checkout?: SessionCheckout;
|
|
49
|
+
/**
|
|
50
|
+
* The newest completed turn waiting for the lead's review in Needs you, and when they marked it reviewed. Set when a
|
|
51
|
+
* turn completes; a turn that fails or is interrupted clears it, and the next completed turn replaces it.
|
|
52
|
+
*/
|
|
53
|
+
review?: SessionReview;
|
|
42
54
|
}
|
|
55
|
+
/** `headline`: the first line of the turn's summary, for the line under the task in Needs you. */
|
|
56
|
+
/** `unverified`: requested outcomes the turn did not observe (not checked, or only agent-reported), for the ledger's line. */
|
|
57
|
+
export interface SessionReview {
|
|
58
|
+
runId: string;
|
|
59
|
+
finishedAt: string;
|
|
60
|
+
reviewedAt?: string;
|
|
61
|
+
headline?: string;
|
|
62
|
+
unverified?: string[];
|
|
63
|
+
}
|
|
64
|
+
export type SessionOrigin = 'andorra-review';
|
|
65
|
+
/** A session the review loop's reviewer saved: it stays on disk and opens by id, but no task list, search or stats shows it. */
|
|
66
|
+
export declare const hiddenSession: (session: Pick<SavedSession, "origin">) => boolean;
|
|
43
67
|
export declare const MAX_LINEAGE_ENTRIES = 64;
|
|
68
|
+
/**
|
|
69
|
+
* The review a session carries after a turn is saved: a completed newest turn waits for review (keeping the mark of one
|
|
70
|
+
* already reviewed), and any other ending clears it.
|
|
71
|
+
*/
|
|
72
|
+
export declare function reviewAfterTurn(history: SavedSession['history'], previous: SessionReview | undefined, finishedAt: string): SessionReview | undefined;
|
|
73
|
+
/** The first sentence-bearing line of a summary, without Markdown marks, at most 200 characters. */
|
|
74
|
+
export declare function reviewHeadline(summary: unknown): string | undefined;
|
|
44
75
|
export declare function canExtendLineage(ancestors: string[] | undefined): boolean;
|
|
45
76
|
export declare function lineageThrough(ancestors: string[] | undefined, id: string): string[];
|
|
46
77
|
export declare function lineagePoints(parent: {
|
|
@@ -88,7 +119,10 @@ export declare class SessionStore {
|
|
|
88
119
|
private readonly directory;
|
|
89
120
|
constructor(directory: string);
|
|
90
121
|
save(session: SavedSession, assertCanWrite?: () => void): Promise<void>;
|
|
91
|
-
|
|
122
|
+
/** The saved sessions, newest first. A hidden session (a review run's) is left out unless includeHidden is set. */
|
|
123
|
+
list(workspace?: string, options?: {
|
|
124
|
+
includeHidden?: boolean;
|
|
125
|
+
}): Promise<SavedSession[]>;
|
|
92
126
|
stats(): Promise<SessionStats>;
|
|
93
127
|
}
|
|
94
128
|
export {};
|
package/dist/src/sessions.js
CHANGED
|
@@ -5,6 +5,8 @@ import { join, resolve } from 'node:path';
|
|
|
5
5
|
import { stripVTControlCharacters } from 'node:util';
|
|
6
6
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
7
7
|
import { validSessionGoal } from './session-goal.js';
|
|
8
|
+
import { validCheckout } from './task-checkout.js';
|
|
9
|
+
import { unverified } from './evidence.js';
|
|
8
10
|
import { decodeDoubleEscapedSummary, stripEchoedEnvelope } from './completion.js';
|
|
9
11
|
import { redactSecrets } from './secret-redaction.js';
|
|
10
12
|
export const sessionName = (prompt) => {
|
|
@@ -20,7 +22,51 @@ export const sessionName = (prompt) => {
|
|
|
20
22
|
const useful = words.filter(word => !/^(please|can|could|you|would|the|a|an|my|me|to|i|want|need|inside)$/i.test(word));
|
|
21
23
|
return [...(useful.length ? useful : words).slice(0, 5), 'coding', 'task', 'session'].slice(0, Math.max(3, Math.min(5, useful.length || words.length))).map(word => word.slice(0, 32)).join(' ');
|
|
22
24
|
};
|
|
25
|
+
/** A session the review loop's reviewer saved: it stays on disk and opens by id, but no task list, search or stats shows it. */
|
|
26
|
+
export const hiddenSession = (session) => session.origin !== undefined;
|
|
23
27
|
export const MAX_LINEAGE_ENTRIES = 64;
|
|
28
|
+
function validReview(value) {
|
|
29
|
+
if (value === null || typeof value !== 'object')
|
|
30
|
+
return false;
|
|
31
|
+
const entry = value;
|
|
32
|
+
return typeof entry.runId === 'string' && entry.runId.length > 0 && entry.runId.length <= 128
|
|
33
|
+
&& typeof entry.finishedAt === 'string' && Number.isFinite(Date.parse(entry.finishedAt))
|
|
34
|
+
&& (entry.reviewedAt === undefined || (typeof entry.reviewedAt === 'string' && Number.isFinite(Date.parse(entry.reviewedAt))))
|
|
35
|
+
&& (entry.headline === undefined || (typeof entry.headline === 'string' && entry.headline.length <= 400))
|
|
36
|
+
&& (entry.unverified === undefined || (Array.isArray(entry.unverified) && entry.unverified.length <= 20 && entry.unverified.every(item => typeof item === 'string' && item.length <= 400)));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The review a session carries after a turn is saved: a completed newest turn waits for review (keeping the mark of one
|
|
40
|
+
* already reviewed), and any other ending clears it.
|
|
41
|
+
*/
|
|
42
|
+
export function reviewAfterTurn(history, previous, finishedAt) {
|
|
43
|
+
const last = history[history.length - 1];
|
|
44
|
+
if (last === undefined || typeof last.runId !== 'string' || !last.runId)
|
|
45
|
+
return previous;
|
|
46
|
+
if ((last.completion?.status ?? 'succeeded') !== 'succeeded')
|
|
47
|
+
return undefined;
|
|
48
|
+
if (previous?.runId === last.runId)
|
|
49
|
+
return previous;
|
|
50
|
+
const headline = reviewHeadline(stripEchoedEnvelope(decodeDoubleEscapedSummary(last.completion?.summary ?? ''), last.completion?.outcome));
|
|
51
|
+
const open = unverified(last.completion?.evidence).slice(0, 20).map(item => item.slice(0, 300));
|
|
52
|
+
return { runId: last.runId, finishedAt, ...(headline ? { headline } : {}), ...(open.length ? { unverified: open } : {}) };
|
|
53
|
+
}
|
|
54
|
+
/** The first sentence-bearing line of a summary, without Markdown marks, at most 200 characters. */
|
|
55
|
+
export function reviewHeadline(summary) {
|
|
56
|
+
if (typeof summary !== 'string')
|
|
57
|
+
return undefined;
|
|
58
|
+
const lines = summary.split('\n').map(text => text.trim()).filter(Boolean);
|
|
59
|
+
// A heading such as "## Summary" names the section; the line under it says what happened.
|
|
60
|
+
const chosen = lines.find(text => !/^#{1,6}\s/.test(text)) ?? lines[0];
|
|
61
|
+
if (chosen === undefined)
|
|
62
|
+
return undefined;
|
|
63
|
+
// Only paired marks are Markdown: snake_case names and globs keep their underscores and asterisks.
|
|
64
|
+
const line = chosen.replace(/^(?:#{1,6}\s+|[-*+]\s+|\d+\.\s+|>\s*)/, '')
|
|
65
|
+
.replace(/`([^`]+)`/g, '$1').replace(/\*\*([^*]+)\*\*/g, '$1').replace(/(^|[\s(])__([^_]+)__(?=[\s).,;:!?]|$)/g, '$1$2').trim();
|
|
66
|
+
if (!line)
|
|
67
|
+
return undefined;
|
|
68
|
+
return line.length > 200 ? `${line.slice(0, 199).trimEnd()}…` : line;
|
|
69
|
+
}
|
|
24
70
|
export function canExtendLineage(ancestors) {
|
|
25
71
|
return (ancestors?.length ?? 0) < MAX_LINEAGE_ENTRIES;
|
|
26
72
|
}
|
|
@@ -31,7 +77,7 @@ export function lineagePoints(parent, parentUsage, parentTurns) {
|
|
|
31
77
|
return [...(parent.lineage ?? []), { usage: parentUsage, turns: parentTurns }].slice(-MAX_LINEAGE_ENTRIES);
|
|
32
78
|
}
|
|
33
79
|
export function savedSessionFields(session) {
|
|
34
|
-
const { version, id, name, workspace, updatedAt, history, usage, contextHistory, parentId, inheritedUsage, inheritedTurns, ancestors, lineage, projectId, trajectoryId, widgets, context, archived, autoArchived, renamed, goal, jevEnabled } = session;
|
|
80
|
+
const { version, id, name, workspace, updatedAt, history, usage, contextHistory, parentId, inheritedUsage, inheritedTurns, ancestors, lineage, projectId, trajectoryId, widgets, context, archived, autoArchived, pinned, renamed, goal, jevEnabled, origin, checkout, review } = session;
|
|
35
81
|
return { version, id, name, workspace, updatedAt, history, usage, contextHistory, parentId, projectId, widgets,
|
|
36
82
|
...(context === undefined ? {} : { context }),
|
|
37
83
|
...(inheritedUsage === undefined ? {} : { inheritedUsage }),
|
|
@@ -40,9 +86,13 @@ export function savedSessionFields(session) {
|
|
|
40
86
|
...(lineage === undefined ? {} : { lineage }),
|
|
41
87
|
...(trajectoryId === undefined ? {} : { trajectoryId }),
|
|
42
88
|
...(archived === undefined ? {} : { archived }), ...(autoArchived === undefined ? {} : { autoArchived }),
|
|
89
|
+
...(pinned === undefined ? {} : { pinned }),
|
|
43
90
|
...(renamed === undefined ? {} : { renamed }),
|
|
44
91
|
...(goal === undefined ? {} : { goal }),
|
|
45
|
-
...(jevEnabled === undefined ? {} : { jevEnabled })
|
|
92
|
+
...(jevEnabled === undefined ? {} : { jevEnabled }),
|
|
93
|
+
...(origin === undefined ? {} : { origin }),
|
|
94
|
+
...(checkout === undefined ? {} : { checkout }),
|
|
95
|
+
...(review === undefined ? {} : { review }) };
|
|
46
96
|
}
|
|
47
97
|
export const primaryDigest = (session) => createHash('sha256').update(JSON.stringify(savedSessionFields(session))).digest('hex');
|
|
48
98
|
async function readRunUsage(path) {
|
|
@@ -77,6 +127,15 @@ export function carryRailOwnedFields(record, stored) {
|
|
|
77
127
|
record.autoArchived = stored.autoArchived;
|
|
78
128
|
else
|
|
79
129
|
delete record.autoArchived;
|
|
130
|
+
if (stored.pinned !== undefined)
|
|
131
|
+
record.pinned = stored.pinned;
|
|
132
|
+
else
|
|
133
|
+
delete record.pinned;
|
|
134
|
+
// Needs you's review mark is the app's to set: a writer that loaded an older copy keeps the stored one.
|
|
135
|
+
if (stored.review !== undefined)
|
|
136
|
+
record.review = stored.review;
|
|
137
|
+
else
|
|
138
|
+
delete record.review;
|
|
80
139
|
}
|
|
81
140
|
export function displayHistory(history) {
|
|
82
141
|
return history.map(turn => {
|
|
@@ -157,6 +216,8 @@ export function validSavedSession(value) {
|
|
|
157
216
|
&& session.inheritedTurns >= 0 && session.inheritedTurns <= session.history.length)) &&
|
|
158
217
|
(session.lineage === undefined || validLineage(session.lineage, session.usage, session.history.length, { usage: session.inheritedUsage, turns: session.inheritedTurns })) &&
|
|
159
218
|
(session.projectId === undefined || typeof session.projectId === 'string') &&
|
|
219
|
+
(session.checkout === undefined || validCheckout(session.checkout)) &&
|
|
220
|
+
(session.review === undefined || validReview(session.review)) &&
|
|
160
221
|
(session.trajectoryId === undefined || (typeof session.trajectoryId === 'string' && /^[A-Za-z0-9_-]{1,64}$/.test(session.trajectoryId))) &&
|
|
161
222
|
(session.widgets === undefined || Array.isArray(session.widgets) && session.widgets.every(widget => !!widget && typeof widget === 'object' && typeof widget.id === 'string' && typeof widget.name === 'string'
|
|
162
223
|
&& typeof widget.description === 'string' && typeof widget.value === 'string')) &&
|
|
@@ -166,9 +227,11 @@ export function validSavedSession(value) {
|
|
|
166
227
|
&& (session.context.cacheRead === undefined || (Number.isSafeInteger(session.context.cacheRead) && session.context.cacheRead >= 0)))) &&
|
|
167
228
|
(session.archived === undefined || typeof session.archived === 'boolean') &&
|
|
168
229
|
(session.autoArchived === undefined || typeof session.autoArchived === 'boolean') &&
|
|
230
|
+
(session.pinned === undefined || typeof session.pinned === 'boolean') &&
|
|
169
231
|
(session.renamed === undefined || typeof session.renamed === 'boolean') &&
|
|
170
232
|
(session.goal === undefined || validSessionGoal(session.goal)) &&
|
|
171
233
|
(session.jevEnabled === undefined || typeof session.jevEnabled === 'boolean') &&
|
|
234
|
+
(session.origin === undefined || session.origin === 'andorra-review') &&
|
|
172
235
|
validUsage(session.usage) &&
|
|
173
236
|
(session.inheritedUsage === undefined || (validUsage(session.inheritedUsage)
|
|
174
237
|
&& (!session.usage || (session.inheritedUsage.inputTokens <= session.usage.inputTokens
|
|
@@ -242,7 +305,8 @@ export class SessionStore {
|
|
|
242
305
|
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
243
306
|
await writeSessionSnapshot(join(directory, `${session.id}.json`), JSON.stringify(session) + '\n', assertCanWrite);
|
|
244
307
|
}
|
|
245
|
-
|
|
308
|
+
/** The saved sessions, newest first. A hidden session (a review run's) is left out unless includeHidden is set. */
|
|
309
|
+
async list(workspace, options = {}) {
|
|
246
310
|
const directory = join(this.directory, 'sessions');
|
|
247
311
|
let names;
|
|
248
312
|
try {
|
|
@@ -261,6 +325,8 @@ export class SessionStore {
|
|
|
261
325
|
const value = JSON.parse(await readFile(join(directory, name), 'utf8'));
|
|
262
326
|
if (!validSavedSession(value) || name !== `${value.id}.json` || workspace !== undefined && resolve(value.workspace) !== resolve(workspace))
|
|
263
327
|
continue;
|
|
328
|
+
if (hiddenSession(value) && options.includeHidden !== true)
|
|
329
|
+
continue;
|
|
264
330
|
sessions.push(value);
|
|
265
331
|
}
|
|
266
332
|
catch { }
|
|
@@ -287,7 +353,7 @@ export class SessionStore {
|
|
|
287
353
|
continue;
|
|
288
354
|
try {
|
|
289
355
|
const value = JSON.parse(await readFile(join(directory, name), 'utf8'));
|
|
290
|
-
if (!validSavedSession(value) || name !== `${value.id}.json`)
|
|
356
|
+
if (!validSavedSession(value) || name !== `${value.id}.json` || hiddenSession(value))
|
|
291
357
|
continue;
|
|
292
358
|
stats.total += 1;
|
|
293
359
|
if (value.archived === true)
|