@intentic/sandbox-contract 1.369.0 → 1.371.0
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/contracts/agent.contract.d.ts +9 -0
- package/dist/contracts/agent.contract.d.ts.map +1 -1
- package/dist/contracts/agents.contract.d.ts +2 -0
- package/dist/contracts/agents.contract.d.ts.map +1 -1
- package/dist/contracts/ci.contract.d.ts +2 -0
- package/dist/contracts/ci.contract.d.ts.map +1 -1
- package/dist/contracts/runner.contract.d.ts +29 -0
- package/dist/contracts/runner.contract.d.ts.map +1 -1
- package/dist/contracts/sessions.contract.d.ts +1 -0
- package/dist/contracts/sessions.contract.d.ts.map +1 -1
- package/dist/contracts/system.contract.d.ts +3 -0
- package/dist/contracts/system.contract.d.ts.map +1 -1
- package/dist/events/agent-events.d.ts +16 -0
- package/dist/events/agent-events.d.ts.map +1 -1
- package/dist/events/agent-events.js +2 -0
- package/dist/events/agent-events.js.map +1 -1
- package/dist/events/agent-transcript.d.ts +1 -0
- package/dist/events/agent-transcript.d.ts.map +1 -1
- package/dist/events/agent-words.d.ts +1 -0
- package/dist/events/agent-words.d.ts.map +1 -1
- package/dist/events/agent-words.js +9 -1
- package/dist/events/agent-words.js.map +1 -1
- package/dist/events/refusal-incidents.d.ts +13 -0
- package/dist/events/refusal-incidents.d.ts.map +1 -0
- package/dist/events/refusal-incidents.js +57 -0
- package/dist/events/refusal-incidents.js.map +1 -0
- package/dist/events/sandbox-notice.d.ts +27 -0
- package/dist/events/sandbox-notice.d.ts.map +1 -1
- package/dist/events/sandbox-notice.js +15 -0
- package/dist/events/sandbox-notice.js.map +1 -1
- package/dist/events/system-events.d.ts +2 -0
- package/dist/events/system-events.d.ts.map +1 -1
- package/dist/events/system-events.js +1 -0
- package/dist/events/system-events.js.map +1 -1
- package/dist/events/transcript.d.ts +6 -0
- package/dist/events/transcript.d.ts.map +1 -1
- package/dist/events/transcript.js +1 -0
- package/dist/events/transcript.js.map +1 -1
- package/dist/index.d.ts +47 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/models/plan-pools.d.ts +6 -5
- package/dist/models/plan-pools.d.ts.map +1 -1
- package/dist/models/plan-pools.js +10 -6
- package/dist/models/plan-pools.js.map +1 -1
- package/dist/protocol/sse.d.ts.map +1 -1
- package/dist/protocol/sse.js +35 -17
- package/dist/protocol/sse.js.map +1 -1
- package/dist/schemas/ci.d.ts +2 -0
- package/dist/schemas/ci.d.ts.map +1 -1
- package/dist/schemas/ci.js +10 -0
- package/dist/schemas/ci.js.map +1 -1
- package/dist/schemas/providers/plan-limits.js +1 -1
- package/dist/schemas/providers/plan-limits.js.map +1 -1
- package/dist/schemas/providers/switched.d.ts +30 -0
- package/dist/schemas/providers/switched.d.ts.map +1 -0
- package/dist/schemas/providers/switched.js +45 -0
- package/dist/schemas/providers/switched.js.map +1 -0
- package/dist/schemas/workspace/name-order.d.ts +9 -0
- package/dist/schemas/workspace/name-order.d.ts.map +1 -0
- package/dist/schemas/workspace/name-order.js +4 -0
- package/dist/schemas/workspace/name-order.js.map +1 -0
- package/dist/state/fix-stance.d.ts.map +1 -1
- package/dist/state/fix-stance.js +8 -0
- package/dist/state/fix-stance.js.map +1 -1
- package/dist/text/notice-rows.d.ts +7 -1
- package/dist/text/notice-rows.d.ts.map +1 -1
- package/dist/text/notice-rows.js +15 -0
- package/dist/text/notice-rows.js.map +1 -1
- package/dist/text/transcript-fold.d.ts.map +1 -1
- package/dist/text/transcript-fold.js +4 -5
- package/dist/text/transcript-fold.js.map +1 -1
- package/package.json +5 -5
- package/src/events/agent-events.ts +3 -0
- package/src/events/agent-words.test.ts +7 -0
- package/src/events/agent-words.ts +14 -1
- package/src/events/refusal-incidents.ts +109 -0
- package/src/events/sandbox-notice.ts +23 -0
- package/src/events/system-events.ts +4 -0
- package/src/events/transcript.ts +1 -0
- package/src/models/plan-pools.test.ts +13 -0
- package/src/models/plan-pools.ts +30 -10
- package/src/protocol/sse.test.ts +45 -1
- package/src/protocol/sse.ts +38 -19
- package/src/schemas/ci.ts +14 -0
- package/src/schemas/providers/plan-limits.ts +1 -1
- package/src/schemas/providers/switched.test.ts +46 -0
- package/src/schemas/providers/switched.ts +72 -0
- package/src/schemas/workspace/name-order.test.ts +30 -0
- package/src/schemas/workspace/name-order.ts +18 -0
- package/src/state/fix-stance.test.ts +15 -0
- package/src/state/fix-stance.ts +11 -0
- package/src/text/notice-rows.ts +28 -3
- package/src/text/transcript-fold.test.ts +115 -1
- package/src/text/transcript-fold.ts +6 -7
package/src/text/notice-rows.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import type { AgentEvent } from "../events/agent-events.js";
|
|
2
2
|
import type { TranscriptRow } from "../events/transcript.js";
|
|
3
|
-
import { noticeCode } from "../events/sandbox-notice.js";
|
|
3
|
+
import { noticeCode, type SandboxNotice } from "../events/sandbox-notice.js";
|
|
4
4
|
import { contextTrimLine, contextTrimNotice } from "../schemas/context-trim.js";
|
|
5
5
|
import { freshStartLine, freshStartNotice, handedOffLine, handedOffNotice } from "../schemas/providers/handoff.js";
|
|
6
|
+
import { switchedLine, switchedNotice } from "../schemas/providers/switched.js";
|
|
6
7
|
|
|
7
8
|
// The notices that say what a turn was given to start from, each a row of its own worded from its frame's facts: what
|
|
8
|
-
// the window left out of the message, how a held turn continued,
|
|
9
|
-
|
|
9
|
+
// the window left out of the message, how a held turn continued, where a home's session started over, and what the
|
|
10
|
+
// turn switched to since the one before it.
|
|
11
|
+
type StartingFrame = Extract<AgentEvent, { kind: "context_trim" | "handoff" | "fresh_start" | "switched" }>;
|
|
12
|
+
const STARTING_KINDS: ReadonlySet<AgentEvent["kind"]> = new Set<StartingFrame["kind"]>(["context_trim", "handoff", "fresh_start", "switched"]);
|
|
13
|
+
|
|
14
|
+
/** Whether the frame is one of those notices. */
|
|
15
|
+
export const isStartingFrame = (event: AgentEvent): event is StartingFrame => STARTING_KINDS.has(event.kind);
|
|
10
16
|
|
|
11
17
|
/** A starting frame's row, in the English the record keeps, with the code a reader words it from. */
|
|
12
18
|
export const startingRow = (event: StartingFrame): TranscriptRow => {
|
|
@@ -17,5 +23,24 @@ export const startingRow = (event: StartingFrame): TranscriptRow => {
|
|
|
17
23
|
return { role: "notice", text: handedOffLine(event), noticeCode: noticeCode(handedOffNotice(event)) };
|
|
18
24
|
case "fresh_start":
|
|
19
25
|
return { role: "notice", text: freshStartLine(event), noticeCode: noticeCode(freshStartNotice(event)) };
|
|
26
|
+
case "switched":
|
|
27
|
+
return { role: "notice", text: switchedLine(event), noticeCode: noticeCode(switchedNotice(event)) };
|
|
20
28
|
}
|
|
21
29
|
};
|
|
30
|
+
|
|
31
|
+
/** A move off one account onto another before a turn ran, as its notice carries it. */
|
|
32
|
+
export type AccountMoved = Extract<SandboxNotice, { code: "accountMoved" }>["params"];
|
|
33
|
+
|
|
34
|
+
// Each names both accounts, since "moved" alone leaves the reader to work out from where and to where.
|
|
35
|
+
const MOVED_LINES = {
|
|
36
|
+
refused: ({ from, to }) => `Ran on ${to}: the ${from} account's plan or organization does not allow it.`,
|
|
37
|
+
reach: ({ from, to }) => `Ran on ${to}: the people this conversation works for may not use the ${from} account.`,
|
|
38
|
+
cold: ({ from, to }) => `Moved from ${from} to ${to}, which has more room left: the cache had expired, so moving cost nothing.`,
|
|
39
|
+
} as const satisfies Readonly<Record<AccountMoved["why"], (move: AccountMoved) => string>>;
|
|
40
|
+
|
|
41
|
+
/** The row a turn moved to another account opens with, so the reader learns where it ran and why without asking. */
|
|
42
|
+
export const accountMovedRow = (move: AccountMoved): TranscriptRow => ({
|
|
43
|
+
role: "notice",
|
|
44
|
+
text: MOVED_LINES[move.why](move),
|
|
45
|
+
noticeCode: noticeCode({ code: "accountMoved", params: move }),
|
|
46
|
+
});
|
|
@@ -4,9 +4,11 @@ import { type TranscriptPatch, type TranscriptRow, TranscriptRowSchema, type Tra
|
|
|
4
4
|
import { sandboxNoticeOf } from "../events/sandbox-notice.js";
|
|
5
5
|
import { watchWakePrompt } from "../events/watch-wake.js";
|
|
6
6
|
import { LAND_CONFLICT_OPENING } from "../events/land-conflict.js";
|
|
7
|
-
import { RESUME_NOTES } from "../events/resume.js";
|
|
7
|
+
import { RESUME_NOTES,resumeDisclosure,resumeNoticeRow } from "../events/resume.js";
|
|
8
8
|
import { childReportPrompt, peerMessagePrompt } from "../events/agent-words.js";
|
|
9
9
|
import { applyTranscriptPatch, foldTurn, mapTool, TranscriptFold, userRow } from "./transcript-fold.js";
|
|
10
|
+
import { transcriptIncidents } from "../events/refusal-incidents.js";
|
|
11
|
+
import { accountMovedRow } from "./notice-rows.js";
|
|
10
12
|
|
|
11
13
|
// Epoch ms stamped on the opening user row's sentAt.
|
|
12
14
|
const SENT_AT = 1_767_225_600_000;
|
|
@@ -515,6 +517,21 @@ describe("foldTurn", () => {
|
|
|
515
517
|
});
|
|
516
518
|
});
|
|
517
519
|
|
|
520
|
+
// A turn that went out on another provider, account, loop or model than the one before it: a row of its own, in
|
|
521
|
+
// the record, so every window shows the same switch.
|
|
522
|
+
it("marks a turn's switch with a row of its own, coded for the reader's language", () => {
|
|
523
|
+
expect(foldOf("go", [{ kind: "switched", segment: "provider", provider: "codex", model: "gpt-5-codex", loop: "Codex", fresh: true }]).at(-1)).toEqual({
|
|
524
|
+
role: "notice",
|
|
525
|
+
text: "Switched to Codex: this message started a fresh session, with the conversation so far carried over.",
|
|
526
|
+
noticeCode: { code: "switched", params: { segment: "provider", provider: "codex", model: "gpt-5-codex", loop: "Codex", fresh: true } },
|
|
527
|
+
});
|
|
528
|
+
expect(foldOf("go", [{ kind: "switched", segment: "model", provider: "claude", model: "claude-sonnet-5", fresh: false }]).at(-1)).toEqual({
|
|
529
|
+
role: "notice",
|
|
530
|
+
text: "Switched to Claude Sonnet 5: same session, so the model re-reads the conversation once.",
|
|
531
|
+
noticeCode: { code: "switched", params: { segment: "model", provider: "claude", model: "claude-sonnet-5", fresh: false } },
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
|
|
518
535
|
// A spawned child's work goes into its parent's checkout, as the parent's in-process subagents' edits do: the row
|
|
519
536
|
// says so, never that it reached the owner's workspace, and says who is to bring in a clash.
|
|
520
537
|
it("says a child's work went into its parent's checkout, or was held off it by a clash", () => {
|
|
@@ -1339,3 +1356,100 @@ describe("TranscriptFold with a clock", () => {
|
|
|
1339
1356
|
]);
|
|
1340
1357
|
});
|
|
1341
1358
|
});
|
|
1359
|
+
|
|
1360
|
+
// The pile one disabled organization left on 2026-10-28: the peer's message, a rebase, then a refusal, its re-send, the
|
|
1361
|
+
// same refusal again and the move that got it through, each a row of its own. One problem is one row: the run is found
|
|
1362
|
+
// over the rows as stored, the last of it drawn and every attempt behind its details.
|
|
1363
|
+
describe("transcriptIncidents", () => {
|
|
1364
|
+
const ORG_OFF = "Your organization has disabled Claude subscription access for Claude Code";
|
|
1365
|
+
const refusal = { kind: "error", code: "claude-not-entitled", message: ORG_OFF, held: { ran: false } } as const satisfies AgentEvent;
|
|
1366
|
+
// A turn refused at the door, folded as the daemon folds it, on its clock.
|
|
1367
|
+
const refusedAt = (at: number): TranscriptRow => {
|
|
1368
|
+
const fold = new TranscriptFold([], () => at);
|
|
1369
|
+
fold.apply(refusal);
|
|
1370
|
+
return fold.rows.at(-1)!;
|
|
1371
|
+
};
|
|
1372
|
+
const resent = (): TranscriptRow => {
|
|
1373
|
+
const disclosure = resumeDisclosure(RESUME_NOTES.door);
|
|
1374
|
+
if (disclosure?.kind !== "notice") {
|
|
1375
|
+
throw new Error("the door re-run is disclosed as a notice");
|
|
1376
|
+
}
|
|
1377
|
+
return resumeNoticeRow(disclosure);
|
|
1378
|
+
};
|
|
1379
|
+
const moved = accountMovedRow({ why: "refused", from: "Work", to: "radarsu@gmail.com", said: ORG_OFF });
|
|
1380
|
+
const peer: TranscriptRow = { role: "notice", text: "Message from another conversation", agentWords: { kind: "peer", from: "stout-raven-owob", sent: "look" } };
|
|
1381
|
+
const rebased: TranscriptRow = { role: "notice", text: "rebased", noticeCode: { code: "synced", params: { commits: 53 } } };
|
|
1382
|
+
|
|
1383
|
+
it("folds a refusal, its re-sends, the same refusal again and the move that ended it into one row", () => {
|
|
1384
|
+
const rows = [peer, rebased, refusedAt(1_000), resent(), refusedAt(2_000), resent(), moved];
|
|
1385
|
+
expect(transcriptIncidents(rows)).toEqual([
|
|
1386
|
+
{
|
|
1387
|
+
from: 2,
|
|
1388
|
+
to: 6,
|
|
1389
|
+
attempts: [
|
|
1390
|
+
{ at: 1_000, said: ORG_OFF },
|
|
1391
|
+
{ at: 2_000, said: ORG_OFF },
|
|
1392
|
+
],
|
|
1393
|
+
resolved: true,
|
|
1394
|
+
},
|
|
1395
|
+
]);
|
|
1396
|
+
});
|
|
1397
|
+
|
|
1398
|
+
// THE FAILURE THIS PREVENTS: the same sentence twice, a row apart, read as two problems.
|
|
1399
|
+
it("never leaves two identical refusals side by side as two rows", () => {
|
|
1400
|
+
expect(transcriptIncidents([refusedAt(1), refusedAt(2)])).toEqual([{ from: 0, to: 1, attempts: [{ at: 1, said: ORG_OFF }, { at: 2, said: ORG_OFF }], resolved: false }]);
|
|
1401
|
+
});
|
|
1402
|
+
|
|
1403
|
+
// A re-send still in flight is the latest word: the turn is being tried again, which the refusal under it no longer says.
|
|
1404
|
+
it("draws a re-send in flight as the run's last row, unresolved", () => {
|
|
1405
|
+
expect(transcriptIncidents([refusedAt(1), resent()])).toEqual([{ from: 0, to: 1, attempts: [{ at: 1, said: ORG_OFF }], resolved: false }]);
|
|
1406
|
+
});
|
|
1407
|
+
|
|
1408
|
+
it("leaves a lone refusal, a lone move and the rows around a run as they are", () => {
|
|
1409
|
+
expect(transcriptIncidents([peer, refusedAt(1)])).toEqual([]);
|
|
1410
|
+
expect(transcriptIncidents([moved])).toEqual([]);
|
|
1411
|
+
// The person's own words between two refusals are part of the story: neither run reaches across them.
|
|
1412
|
+
expect(transcriptIncidents([refusedAt(1), userRow("again", SENT_AT, []), refusedAt(2)])).toEqual([]);
|
|
1413
|
+
});
|
|
1414
|
+
|
|
1415
|
+
// A different refusal is a different problem, and a memory hold has a row of its own that asks its own question.
|
|
1416
|
+
it("starts again at a different refusal, and never folds a memory hold", () => {
|
|
1417
|
+
const rowOf = (event: Extract<AgentEvent, { kind: "error" }>): TranscriptRow => {
|
|
1418
|
+
const fold = new TranscriptFold([]);
|
|
1419
|
+
fold.apply(event);
|
|
1420
|
+
return fold.rows.at(-1)!;
|
|
1421
|
+
};
|
|
1422
|
+
const spent = rowOf({ kind: "error", code: "trial-exhausted", message: "The free trial is spent.", held: { ran: false } });
|
|
1423
|
+
const memory = rowOf({ kind: "error", code: "sandbox-memory-low", message: "Sandbox memory is low.", held: { ran: false } });
|
|
1424
|
+
const rows = [refusedAt(1), spent, spent, memory, memory];
|
|
1425
|
+
expect(transcriptIncidents(rows).map(({ from, to }) => [from, to])).toEqual([[1, 2]]);
|
|
1426
|
+
});
|
|
1427
|
+
|
|
1428
|
+
// A provider refusing an account it no longer serves answers as a failure of its own, with nothing run between two.
|
|
1429
|
+
it("folds the same coded failure twice running, and leaves an uncoded one be", () => {
|
|
1430
|
+
const failed = (code: AgentErrorCode | undefined): TranscriptRow => ({
|
|
1431
|
+
role: "notice",
|
|
1432
|
+
text: "refused",
|
|
1433
|
+
noticeCode: code === undefined ? { code: "failed", params: { message: "refused" } } : { code: "failed", params: { message: "refused", error: code } },
|
|
1434
|
+
});
|
|
1435
|
+
expect(transcriptIncidents([failed("account-not-entitled"), failed("account-not-entitled")])).toMatchObject([{ from: 0, to: 1 }]);
|
|
1436
|
+
expect(transcriptIncidents([failed(undefined), failed(undefined)])).toEqual([]);
|
|
1437
|
+
});
|
|
1438
|
+
|
|
1439
|
+
// A person's pick in the composer is the editor's own line, which the sandbox cannot code: the reader names it.
|
|
1440
|
+
it("ends a run on a row the reader says resolved it", () => {
|
|
1441
|
+
const switched: TranscriptRow = { role: "notice", text: "Switched to the radarsu@gmail.com account" };
|
|
1442
|
+
expect(transcriptIncidents([refusedAt(1), resent(), refusedAt(2), switched], (row) => row === switched)).toMatchObject([{ from: 0, to: 3, resolved: true }]);
|
|
1443
|
+
expect(transcriptIncidents([refusedAt(1), switched])).toEqual([]);
|
|
1444
|
+
});
|
|
1445
|
+
|
|
1446
|
+
// The move's own row names both accounts by name, and says it in a code the reader words in its own language.
|
|
1447
|
+
it("words the move with both accounts' names, and codes it", () => {
|
|
1448
|
+
expect(moved).toEqual({
|
|
1449
|
+
role: "notice",
|
|
1450
|
+
text: "Ran on radarsu@gmail.com: the Work account's plan or organization does not allow it.",
|
|
1451
|
+
noticeCode: { code: "accountMoved", params: { why: "refused", from: "Work", to: "radarsu@gmail.com", said: ORG_OFF } },
|
|
1452
|
+
});
|
|
1453
|
+
expect(sandboxNoticeOf(accountMovedRow({ why: "cold", from: "Work", to: "Home" }))).toEqual({ code: "accountMoved", params: { why: "cold", from: "Work", to: "Home" } });
|
|
1454
|
+
});
|
|
1455
|
+
});
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
type TranscriptTool,
|
|
13
13
|
} from "../events/transcript.js";
|
|
14
14
|
import { keptWarmLine, keptWarmNotice } from "../schemas/keep-warm.js";
|
|
15
|
-
import { startingRow } from "./notice-rows.js";
|
|
15
|
+
import { isStartingFrame, startingRow } from "./notice-rows.js";
|
|
16
16
|
import { isLandConflict } from "../events/land-conflict.js";
|
|
17
17
|
import { turnedAwayCode } from "../policy/turned-away.js";
|
|
18
18
|
import { errorRow, RENEWAL_WITHDRAWN, RENEWING } from "../events/failure-rows.js";
|
|
@@ -150,6 +150,11 @@ export class TranscriptFold {
|
|
|
150
150
|
if (parent !== undefined) {
|
|
151
151
|
return this.applyChild(event, parent);
|
|
152
152
|
}
|
|
153
|
+
// What the turn started from, each a row of its own rather than a stamp on the message: what was left out is not
|
|
154
|
+
// part of what was sent, and the fold beside the message only ever lists notes that actually rode.
|
|
155
|
+
if (isStartingFrame(event)) {
|
|
156
|
+
return this.pushRow(startingRow(event));
|
|
157
|
+
}
|
|
153
158
|
switch (event.kind) {
|
|
154
159
|
case "delta": {
|
|
155
160
|
if (event.text.length === 0) {
|
|
@@ -244,12 +249,6 @@ export class TranscriptFold {
|
|
|
244
249
|
const notice = keptWarmNotice(event);
|
|
245
250
|
return line === undefined || notice === undefined ? [] : this.pushRow({ role: "notice", text: line, noticeCode: noticeCode(notice) });
|
|
246
251
|
}
|
|
247
|
-
// Each a row of its own rather than a stamp on the message: what was left out is not part of what was sent, and
|
|
248
|
-
// the fold beside the message only ever lists notes that actually rode.
|
|
249
|
-
case "context_trim":
|
|
250
|
-
case "handoff":
|
|
251
|
-
case "fresh_start":
|
|
252
|
-
return this.pushRow(startingRow(event));
|
|
253
252
|
case "worktree":
|
|
254
253
|
return this.synced(event.sync);
|
|
255
254
|
case "landed":
|