@intentic/sandbox-contract 1.364.0 → 1.366.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/README.md +3 -0
- package/dist/contracts/agents.contract.d.ts +253 -0
- package/dist/contracts/agents.contract.d.ts.map +1 -1
- package/dist/contracts/agents.contract.js +18 -0
- package/dist/contracts/agents.contract.js.map +1 -1
- package/dist/contracts/needs.contract.d.ts +232 -0
- package/dist/contracts/needs.contract.d.ts.map +1 -1
- package/dist/contracts/needs.contract.js +11 -1
- package/dist/contracts/needs.contract.js.map +1 -1
- package/dist/contracts/runner.contract.d.ts +32 -0
- package/dist/contracts/runner.contract.d.ts.map +1 -1
- package/dist/contracts/settings.contract.d.ts +2 -0
- package/dist/contracts/settings.contract.d.ts.map +1 -1
- package/dist/contracts/system.contract.d.ts +33 -0
- package/dist/contracts/system.contract.d.ts.map +1 -1
- package/dist/contracts/workspace.contract.d.ts +232 -0
- package/dist/contracts/workspace.contract.d.ts.map +1 -1
- package/dist/contracts/workspace.contract.js +12 -1
- package/dist/contracts/workspace.contract.js.map +1 -1
- package/dist/events/agent-events.d.ts +14 -0
- package/dist/events/agent-events.d.ts.map +1 -1
- package/dist/events/agent-events.js +5 -1
- package/dist/events/agent-events.js.map +1 -1
- package/dist/events/sandbox-notice.d.ts +14 -0
- package/dist/events/sandbox-notice.d.ts.map +1 -1
- package/dist/events/sandbox-notice.js +13 -1
- package/dist/events/sandbox-notice.js.map +1 -1
- package/dist/events/system-events.d.ts +26 -0
- package/dist/events/system-events.d.ts.map +1 -1
- package/dist/events/tool-update.d.ts +6 -0
- package/dist/events/tool-update.d.ts.map +1 -0
- package/dist/events/tool-update.js +12 -0
- package/dist/events/tool-update.js.map +1 -0
- package/dist/events/transcript.d.ts +1 -0
- package/dist/events/transcript.d.ts.map +1 -1
- package/dist/events/transcript.js +4 -0
- package/dist/events/transcript.js.map +1 -1
- package/dist/index.d.ts +752 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/models/device-deadlines.d.ts +34 -0
- package/dist/models/device-deadlines.d.ts.map +1 -0
- package/dist/models/device-deadlines.js +28 -0
- package/dist/models/device-deadlines.js.map +1 -0
- package/dist/protocol/member-reach.d.ts +18 -0
- package/dist/protocol/member-reach.d.ts.map +1 -0
- package/dist/protocol/member-reach.js +31 -0
- package/dist/protocol/member-reach.js.map +1 -0
- package/dist/protocol/raw/raw-json-routes.d.ts +114 -0
- package/dist/protocol/raw/raw-json-routes.d.ts.map +1 -1
- package/dist/protocol/raw/raw-json-routes.js +4 -1
- package/dist/protocol/raw/raw-json-routes.js.map +1 -1
- package/dist/protocol/raw/raw-routes.d.ts +16 -0
- package/dist/protocol/raw/raw-routes.d.ts.map +1 -1
- package/dist/protocol/raw/raw-routes.js +6 -3
- package/dist/protocol/raw/raw-routes.js.map +1 -1
- package/dist/schemas/agents-list.d.ts +26 -0
- package/dist/schemas/agents-list.d.ts.map +1 -1
- package/dist/schemas/agents.d.ts +50 -0
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/agents.js +17 -0
- package/dist/schemas/agents.js.map +1 -1
- package/dist/schemas/environment.d.ts +5 -0
- package/dist/schemas/environment.d.ts.map +1 -1
- package/dist/schemas/environment.js +3 -0
- package/dist/schemas/environment.js.map +1 -1
- package/dist/schemas/members.d.ts +52 -0
- package/dist/schemas/members.d.ts.map +1 -1
- package/dist/schemas/members.js +15 -0
- package/dist/schemas/members.js.map +1 -1
- package/dist/schemas/needs.d.ts +7 -0
- package/dist/schemas/needs.d.ts.map +1 -1
- package/dist/schemas/needs.js +3 -0
- package/dist/schemas/needs.js.map +1 -1
- package/dist/schemas/providers/handoff.d.ts +24 -0
- package/dist/schemas/providers/handoff.d.ts.map +1 -1
- package/dist/schemas/providers/handoff.js +32 -0
- package/dist/schemas/providers/handoff.js.map +1 -1
- package/dist/schemas/providers/usage.d.ts +6 -0
- package/dist/schemas/providers/usage.d.ts.map +1 -1
- package/dist/schemas/providers/usage.js +2 -0
- package/dist/schemas/providers/usage.js.map +1 -1
- package/dist/schemas/settings-experiments.d.ts.map +1 -1
- package/dist/schemas/settings-experiments.js +1 -1
- package/dist/schemas/settings-experiments.js.map +1 -1
- package/dist/schemas/settings.d.ts +2 -0
- package/dist/schemas/settings.d.ts.map +1 -1
- package/dist/schemas/settings.js +6 -0
- package/dist/schemas/settings.js.map +1 -1
- package/dist/schemas/workspace/workspace-search.d.ts +93 -0
- package/dist/schemas/workspace/workspace-search.d.ts.map +1 -1
- package/dist/schemas/workspace/workspace-search.js +10 -0
- package/dist/schemas/workspace/workspace-search.js.map +1 -1
- package/dist/state/definition.d.ts +4 -0
- package/dist/state/definition.d.ts.map +1 -1
- package/dist/state/runtime-state.d.ts +3 -0
- package/dist/state/runtime-state.d.ts.map +1 -1
- package/dist/state/runtime-state.js +1 -0
- package/dist/state/runtime-state.js.map +1 -1
- package/dist/text/land-rows.d.ts.map +1 -1
- package/dist/text/land-rows.js +5 -2
- package/dist/text/land-rows.js.map +1 -1
- package/dist/text/notice-rows.d.ts +8 -0
- package/dist/text/notice-rows.d.ts.map +1 -0
- package/dist/text/notice-rows.js +14 -0
- package/dist/text/notice-rows.js.map +1 -0
- package/dist/text/transcript-fold.d.ts.map +1 -1
- package/dist/text/transcript-fold.js +25 -26
- package/dist/text/transcript-fold.js.map +1 -1
- package/package.json +5 -5
- package/src/contracts/agents.contract.ts +21 -0
- package/src/contracts/needs.contract.ts +14 -0
- package/src/contracts/workspace.contract.ts +15 -1
- package/src/events/agent-events.ts +11 -1
- package/src/events/sandbox-notice.ts +17 -1
- package/src/events/tool-update.ts +18 -0
- package/src/events/transcript.ts +5 -0
- package/src/models/device-deadlines.ts +62 -0
- package/src/protocol/member-reach.test.ts +221 -0
- package/src/protocol/member-reach.ts +78 -0
- package/src/protocol/raw/raw-json-routes.ts +12 -1
- package/src/protocol/raw/raw-routes.ts +10 -4
- package/src/schemas/agents.ts +30 -0
- package/src/schemas/environment.ts +9 -0
- package/src/schemas/members.ts +34 -4
- package/src/schemas/needs.ts +4 -0
- package/src/schemas/providers/handoff.test.ts +23 -1
- package/src/schemas/providers/handoff.ts +49 -0
- package/src/schemas/providers/usage.ts +4 -0
- package/src/schemas/settings-experiments.ts +5 -1
- package/src/schemas/settings.ts +12 -0
- package/src/schemas/shared.ts +1 -1
- package/src/schemas/workspace/workspace-search.ts +16 -0
- package/src/state/runtime-state.ts +5 -0
- package/src/state/workspace-state.ts +1 -1
- package/src/text/land-rows.ts +6 -2
- package/src/text/notice-rows.ts +21 -0
- package/src/text/transcript-fold.test.ts +102 -2
- package/src/text/transcript-fold.ts +29 -30
|
@@ -84,13 +84,19 @@ export const RAW_ROUTES = {
|
|
|
84
84
|
"GET /intake/{id}/config": { auth: "door", embedded: true },
|
|
85
85
|
"GET /intake/{id}/challenge": { auth: "door", embedded: true },
|
|
86
86
|
"POST /intake/{id}/report": { auth: "door", embedded: true },
|
|
87
|
-
// The roster is ownership's to change; giving up one's own grant is every tier's.
|
|
88
|
-
|
|
87
|
+
// The roster is ownership's to read and change; giving up one's own grant is every tier's. Reading it is floored at
|
|
88
|
+
// the owner here as well as in its handler (members.routes.ts), so the editor knows before asking.
|
|
89
|
+
"GET /members": { floor: "owner", control: "never" },
|
|
89
90
|
"POST /members": { control: "never" },
|
|
90
91
|
"DELETE /members": { control: "never" },
|
|
91
92
|
"DELETE /members/self": { floor: "viewer", guest: true, control: "never" },
|
|
92
93
|
// What one's own grant allows, read by the editor to offer only what will be taken.
|
|
93
94
|
"GET /members/self": { floor: "viewer", guest: true, control: "never" },
|
|
95
|
+
// Asking the owner for more access is every member's, a guest's included, from wherever they were refused; reading
|
|
96
|
+
// and dismissing the requests is the owner's, beside the roster they are answered on (schemas/members.ts).
|
|
97
|
+
"POST /members/requests": { floor: "viewer", guest: true, control: "never" },
|
|
98
|
+
"GET /members/requests": { floor: "owner", control: "never" },
|
|
99
|
+
"DELETE /members/requests": { floor: "owner", control: "never" },
|
|
94
100
|
// The owner's Reconnect: register with the platform now, having it adopt the sandbox first when it holds no record.
|
|
95
101
|
"POST /platform/relink": { control: "never" },
|
|
96
102
|
"GET /environment": {},
|
|
@@ -107,7 +113,7 @@ export const RAW_ROUTES = {
|
|
|
107
113
|
"POST /engines/channel": {},
|
|
108
114
|
"POST /engines/update": {},
|
|
109
115
|
"POST /engines/revert": {},
|
|
110
|
-
"GET /bundles": { control: "never" },
|
|
116
|
+
"GET /bundles": { floor: "maintainer", control: "never" },
|
|
111
117
|
"POST /bundles": { control: "never" },
|
|
112
118
|
"DELETE /bundles": { control: "never" },
|
|
113
119
|
"POST /bundles/ticket": { control: "never" },
|
|
@@ -267,7 +273,7 @@ export const RAW_ROUTES = {
|
|
|
267
273
|
"POST /link/conversations/{id}/answer": { auth: "door", control: "never" },
|
|
268
274
|
"POST /link/conversations/{id}/stop": { auth: "door", control: "never" },
|
|
269
275
|
"POST /system/control/tokens": { control: "never" },
|
|
270
|
-
"GET /system/control/tokens": { control: "never" },
|
|
276
|
+
"GET /system/control/tokens": { floor: "maintainer", control: "never" },
|
|
271
277
|
"DELETE /system/control/tokens/{id}": { control: "never" },
|
|
272
278
|
// One's own passkeys are identity, like staying signed in; the policy and recovery codes are ownership's.
|
|
273
279
|
"GET /system/passkeys": { guest: true, control: "never" },
|
package/src/schemas/agents.ts
CHANGED
|
@@ -239,6 +239,19 @@ export type LandedMessageDraft = z.infer<typeof LandedMessageDraftSchema>;
|
|
|
239
239
|
// offer the press that clears a refusal without knowing whose refusal it is.
|
|
240
240
|
export const LandConflictReasonSchema = z.enum(["workspace", "diverged", "binary"]);
|
|
241
241
|
export type LandConflictReason = z.infer<typeof LandConflictReasonSchema>;
|
|
242
|
+
// One land of a home conversation's, as committed: the land its transcript row names, and each repository's commit.
|
|
243
|
+
export const HomeCommitSchema = z.object({
|
|
244
|
+
land: z.string().describe("The land's id, as its `landed` transcript row names it."),
|
|
245
|
+
at: z.number().describe("When it was committed, in milliseconds."),
|
|
246
|
+
subject: z.string().describe("The commit's subject line."),
|
|
247
|
+
commits: z
|
|
248
|
+
.array(z.object({ repo: z.string().describe('Which repository: "root" for the workspace itself, else its folder.'), sha: z.string().describe("The commit, in full.") }))
|
|
249
|
+
.describe("The commit each repository the land reached took, in the order they were made."),
|
|
250
|
+
});
|
|
251
|
+
export type HomeCommit = z.infer<typeof HomeCommitSchema>;
|
|
252
|
+
// How many of a home's commits its card keeps.
|
|
253
|
+
export const HOME_COMMITS_KEPT = 20;
|
|
254
|
+
|
|
242
255
|
export const AgentSummarySchema = z.object({
|
|
243
256
|
id: z.string().describe("The conversation id, which is how every other call addresses it."),
|
|
244
257
|
sessionId: z.string().optional().describe("The provider session behind the last turn. It is retired whenever the model or account changes."),
|
|
@@ -391,6 +404,23 @@ export const AgentSummarySchema = z.object({
|
|
|
391
404
|
.describe(
|
|
392
405
|
"This is its owner's home conversation in this sandbox: the one long-running chat the master view opens, which orchestrates its own subagents, holds their work until it accepts it, and lands and commits by itself. Only its owner and the sandbox's owner see it. Absent for every other conversation.",
|
|
393
406
|
),
|
|
407
|
+
// A home's own record of what its lands became in history (conversations/land/version-landed.ts): each land's commit,
|
|
408
|
+
// under the land id its transcript row names (`landed` notice), so the chat can say what was committed and offer its
|
|
409
|
+
// revert. The newest few only, newest last.
|
|
410
|
+
commits: z
|
|
411
|
+
.array(HomeCommitSchema)
|
|
412
|
+
.optional()
|
|
413
|
+
.describe(
|
|
414
|
+
"A home conversation's latest lands as they were committed, newest last: which land, when, under what subject, and the commit each repository took. Kept for the last few only. Absent for every other conversation.",
|
|
415
|
+
),
|
|
416
|
+
// Set by Start fresh or Clear history (agents.startFresh / clearHistory) and cleared by the turn that opens the fresh
|
|
417
|
+
// session: what lets the chat say its next message starts over.
|
|
418
|
+
freshPending: z
|
|
419
|
+
.enum(["asked", "cleared"])
|
|
420
|
+
.optional()
|
|
421
|
+
.describe(
|
|
422
|
+
"A home conversation whose next message opens a fresh session, because its person asked (`asked`) or cleared its history (`cleared`). Absent once that message has gone, and for every other conversation.",
|
|
423
|
+
),
|
|
394
424
|
// Root repo's short base sha; per-repo bases stay daemon-internal.
|
|
395
425
|
base: z.string().optional().describe("The commit its private copy started from, shortened."),
|
|
396
426
|
costUsd: z.number().optional().describe("What it has cost so far, in dollars. A subagent's spend is its own and is not folded in here."),
|
|
@@ -83,6 +83,11 @@ export const EnvironmentRecurringSchema = z.object({
|
|
|
83
83
|
tool: z.string(),
|
|
84
84
|
kind: RuntimeInstallKindSchema,
|
|
85
85
|
sessions: z.number(),
|
|
86
|
+
// The evidence behind the count, so the owner judges the need without opening the ledger: the conversations that
|
|
87
|
+
// installed it (newest last, capped) and the last few commands that did, secrets already masked. Absent from a daemon
|
|
88
|
+
// released before they were carried.
|
|
89
|
+
sessionIds: z.array(z.string()).optional(),
|
|
90
|
+
commands: z.array(z.string()).optional(),
|
|
86
91
|
lastAt: z.number(),
|
|
87
92
|
live: z.boolean(),
|
|
88
93
|
drafted: z.boolean().optional(),
|
|
@@ -160,6 +165,10 @@ export const EnvironmentSchema = z.object({
|
|
|
160
165
|
recurring: z.array(EnvironmentRecurringSchema).optional(),
|
|
161
166
|
// Absent on a sandbox running a published image, which is every sandbox but a dogfooding one.
|
|
162
167
|
localImage: EnvironmentLocalImageSchema.optional(),
|
|
168
|
+
// Set only on a sandbox Docker Compose runs (SANDBOX_MANAGER): it updates with `docker compose pull && up` from the
|
|
169
|
+
// folder holding its file, so the update card offers that rather than an `ic` swap. Absent from an older daemon too,
|
|
170
|
+
// which is why the card still names the compose way beside the `ic` one when it cannot tell.
|
|
171
|
+
manager: z.literal("compose").optional(),
|
|
163
172
|
// A rebuild waiting for the agents to be idle, or started or refused once they were; absent when none is asked.
|
|
164
173
|
rebuildWhenIdle: EnvironmentRebuildWaitSchema.optional(),
|
|
165
174
|
// A checkout rebuild's restart held until no agent is mid-turn; absent when none is asked.
|
package/src/schemas/members.ts
CHANGED
|
@@ -225,14 +225,14 @@ export type MembersRoster = z.infer<typeof MembersRosterSchema>;
|
|
|
225
225
|
// `emailSignIn` lets the platform's identity assertion open this sandbox for them (policy/identity-assertion.ts): true
|
|
226
226
|
// allows it, false takes it back, absent keeps what the row already says, so a re-grade from an editor that predates
|
|
227
227
|
// the field never drops it. `credentials` the same way: `all` lifts a reach, a list sets one, absent keeps the row's,
|
|
228
|
-
// so a re-grade that never mentions it can never widen what a person's conversations may spend. A maintainer
|
|
229
|
-
// a list:
|
|
228
|
+
// so a re-grade that never mentions it can never widen what a person's conversations may spend. A maintainer may hold
|
|
229
|
+
// a list too: managing the sandbox and spending all of it are separate answers (docs/architecture/access.md).
|
|
230
230
|
// `agents` and `edit` decide the rest of the access; absent, the role's own meaning stands, so an editor that predates
|
|
231
231
|
// them still grants what it always did. `lands` is written as sent: absent is no, so a re-grade that never mentions it
|
|
232
232
|
// can never hand a home-only person's agent the authority to land. The role sent must be the tier the access makes (`tierOf`): two answers to one
|
|
233
233
|
// question are refused rather than one of them guessed away. `aiAccounts` reads as `credentials` does: `all` lifts it, a
|
|
234
|
-
// list sets it, absent keeps the row's
|
|
235
|
-
//
|
|
234
|
+
// list sets it, absent keeps the row's, a maintainer's included. `tools` and `assistants` read the same way, except that
|
|
235
|
+
// a maintainer is refused a tool ceiling, since the tier runs every tool.
|
|
236
236
|
// `profile` names an access profile instead of answering on the row: the daemon writes that profile's answers out on
|
|
237
237
|
// the row and ignores the access fields sent beside it, and the role sent must still be the tier the profile makes.
|
|
238
238
|
// Absent is answers of the row's own, so a re-grade from an editor that predates profiles unlinks the row, keeping
|
|
@@ -271,8 +271,38 @@ export const MemberSelfSchema = z.object({
|
|
|
271
271
|
tools: ToolCeilingSchema.optional().describe("The most their conversations' tools may be. Absent means no limit."),
|
|
272
272
|
assistants: z.array(entryId).optional().describe("For a guest who chats: the assistants they may talk to. Absent means every one in their areas."),
|
|
273
273
|
profile: entryId.optional().describe("The access profile their access comes from. Absent means answers of their own."),
|
|
274
|
+
askedAt: z
|
|
275
|
+
.number()
|
|
276
|
+
.int()
|
|
277
|
+
.optional()
|
|
278
|
+
.describe("When they asked the owner for more access, while that request is still open (POST /members/requests). Absent when they have not, or it was answered."),
|
|
274
279
|
});
|
|
275
280
|
export type MemberSelf = z.infer<typeof MemberSelfSchema>;
|
|
276
281
|
|
|
282
|
+
// ASKING THE OWNER FOR MORE ACCESS, from where the person was refused: the editor draws an "Ask for access" press on a
|
|
283
|
+
// place or an action their access refuses, and the owner sees each open request beside the roster (Access ▸ People),
|
|
284
|
+
// where granting the person what they asked for answers it. One open request per person: a later ask replaces theirs.
|
|
285
|
+
// `want` is what stood in the way, in the terms a grant answers: a tier (`viewer` is a guest asking to see more),
|
|
286
|
+
// running agents (`agents`), or a folder outside their areas (`areas`).
|
|
287
|
+
export const AccessWantSchema = z.enum(["viewer", "collaborator", "writer", "maintainer", "agents", "areas"]);
|
|
288
|
+
export type AccessWant = z.infer<typeof AccessWantSchema>;
|
|
289
|
+
|
|
290
|
+
// POST /members/requests: what the person asks for, and where they were when they asked.
|
|
291
|
+
export const AccessAskSchema = z.object({
|
|
292
|
+
want: AccessWantSchema.describe("What stood in the way: a tier, running agents, or a folder outside their areas."),
|
|
293
|
+
place: z.string().min(1).max(80).describe("Where they were, as that page or section is titled (\"Secrets\"), so the owner knows what it is for."),
|
|
294
|
+
});
|
|
295
|
+
export type AccessAsk = z.infer<typeof AccessAskSchema>;
|
|
296
|
+
|
|
297
|
+
export const AccessRequestSchema = AccessAskSchema.extend({
|
|
298
|
+
email: z.string().describe("Who asked."),
|
|
299
|
+
at: z.number().int().describe("When they asked, in ms since the epoch."),
|
|
300
|
+
});
|
|
301
|
+
export type AccessRequest = z.infer<typeof AccessRequestSchema>;
|
|
302
|
+
|
|
303
|
+
// GET /members/requests, and the answer to dismissing one: every open request, newest first.
|
|
304
|
+
export const AccessRequestsSchema = z.object({ requests: z.array(AccessRequestSchema) });
|
|
305
|
+
export type AccessRequests = z.infer<typeof AccessRequestsSchema>;
|
|
306
|
+
|
|
277
307
|
// DELETE /members: whose access to take back.
|
|
278
308
|
export const MemberEmailSchema = z.object({ email: z.string() });
|
package/src/schemas/needs.ts
CHANGED
|
@@ -256,6 +256,10 @@ export type NeedAnswer = z.infer<typeof NeedAnswerSchema>;
|
|
|
256
256
|
|
|
257
257
|
export const NeedIdParamSchema = z.object({ id: z.string().min(1).describe("Which need.") });
|
|
258
258
|
export const NeedAnswerInputSchema = NeedIdParamSchema.extend({ answer: NeedAnswerSchema });
|
|
259
|
+
// POST /needs/{id}/release: a release need's own answer, from the people its gate names, whatever their tier.
|
|
260
|
+
export const NeedReleaseInputSchema = NeedIdParamSchema.extend({
|
|
261
|
+
answer: z.enum(["release", "decline"]).describe("Release the credential to the conversation, or decline it."),
|
|
262
|
+
});
|
|
259
263
|
export const NeedSecretInputSchema = NeedIdParamSchema.extend({
|
|
260
264
|
value: z.string().min(1).max(64_000).describe("The secret's value. Stored, never echoed, never written into a transcript."),
|
|
261
265
|
// "Keep it on my computer": the value is sealed to that computer's keyring inbox (schemas/keyring.ts) and kept there,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type HandoffMode, handedOffLine, handedOffNotice, suggestHandoff } from "./handoff.js";
|
|
1
|
+
import { freshStartLine, freshStartNotice, type HandoffMode, handedOffLine, handedOffNotice, suggestHandoff } from "./handoff.js";
|
|
2
2
|
|
|
3
3
|
const THRESHOLDS = { carryUnder: 150_000, summaryOver: 700_000 };
|
|
4
4
|
const all = (): boolean => true;
|
|
@@ -40,3 +40,25 @@ describe("handedOffLine", () => {
|
|
|
40
40
|
expect(handedOffNotice({ mode: "summary", fellBack: true })).toStrictEqual({ code: "handedOff", params: { mode: "summary", fellBack: true } });
|
|
41
41
|
});
|
|
42
42
|
});
|
|
43
|
+
|
|
44
|
+
describe("a home's fresh start", () => {
|
|
45
|
+
it("says why the chat started over and what the fresh session opened with", () => {
|
|
46
|
+
expect(freshStartLine({ why: "cold", from: 90_000, summarized: false })).toBe(
|
|
47
|
+
"This chat had been idle long enough that re-reading it at about 90k tokens would cost more than starting over, so it went on in a fresh session, opened with its latest messages and the work in hand.",
|
|
48
|
+
);
|
|
49
|
+
expect(freshStartLine({ why: "asked", summarized: true })).toBe(
|
|
50
|
+
"Started fresh, as you asked, opened with a summary of the conversation and its latest messages.",
|
|
51
|
+
);
|
|
52
|
+
expect(freshStartLine({ why: "cleared", summarized: false })).toBe("History cleared: started fresh, opened with its latest messages and the work in hand.");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("carries only the facts it has", () => {
|
|
56
|
+
expect(freshStartNotice({ why: "asked", summarized: false })).toEqual({ code: "freshStart", params: { why: "asked", summarized: false } });
|
|
57
|
+
expect(freshStartNotice({ why: "budget", from: 151_400, model: "haiku", summarized: true }).params).toEqual({
|
|
58
|
+
why: "budget",
|
|
59
|
+
from: "151k",
|
|
60
|
+
model: "haiku",
|
|
61
|
+
summarized: true,
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -126,3 +126,52 @@ export const handedOffLine = (event: HandedOff): string => {
|
|
|
126
126
|
return `Continued in a fresh session opened with a summary of the conversation${event.model === undefined ? "" : ` written by ${event.model}`}.`;
|
|
127
127
|
}
|
|
128
128
|
};
|
|
129
|
+
|
|
130
|
+
// HOW A HOME CONVERSATION STAYS CHEAP (the daemon's conversations/home/home-rollover.ts). A home is one chat kept for
|
|
131
|
+
// good, so its session would grow until the model's window forced a compaction, every call of every turn re-reading all
|
|
132
|
+
// of it on the way. Instead, once it has grown past the sandbox's budget (`homeFreshOver`), or half of it with the
|
|
133
|
+
// prompt cache already cold, its next turn opens a fresh session: a summary where a model is set for hand-off summaries,
|
|
134
|
+
// the newest part of the conversation word for word, its subagents and what they hold, and its home policy again. Its
|
|
135
|
+
// person may also start one fresh by hand, or clear its history. The chat itself keeps every row; only what the model
|
|
136
|
+
// re-reads starts over.
|
|
137
|
+
export const FRESH_START_WHYS = ["budget", "cold", "asked", "cleared"] as const;
|
|
138
|
+
export const FreshStartWhySchema = z.enum(FRESH_START_WHYS);
|
|
139
|
+
export type FreshStartWhy = z.infer<typeof FreshStartWhySchema>;
|
|
140
|
+
|
|
141
|
+
export const FreshStartSchema = z.object({
|
|
142
|
+
why: FreshStartWhySchema.describe(
|
|
143
|
+
"Why the conversation went on in a fresh session: it outgrew the budget (`budget`), it had grown past half of it while its prompt cache was already cold (`cold`), its person asked (`asked`), or its person cleared its history (`cleared`).",
|
|
144
|
+
),
|
|
145
|
+
from: z.number().optional().describe("The context the old session had grown to, in tokens. Absent where nothing measured it."),
|
|
146
|
+
model: z.string().optional().describe("The model that wrote the summary the fresh session opened with."),
|
|
147
|
+
summarized: z.boolean().describe("Whether a summary was written; false where the fresh session opened with the recent conversation alone."),
|
|
148
|
+
});
|
|
149
|
+
export type FreshStart = z.infer<typeof FreshStartSchema>;
|
|
150
|
+
|
|
151
|
+
export const freshStartNotice = (event: FreshStart): Extract<SandboxNotice, { code: "freshStart" }> => {
|
|
152
|
+
const params: Extract<SandboxNotice, { code: "freshStart" }>["params"] = { why: event.why, summarized: event.summarized };
|
|
153
|
+
if (event.from !== undefined) {
|
|
154
|
+
params.from = tokensLabel(event.from);
|
|
155
|
+
}
|
|
156
|
+
if (event.model !== undefined) {
|
|
157
|
+
params.model = event.model;
|
|
158
|
+
}
|
|
159
|
+
return { code: "freshStart", params };
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/** The transcript's line for a fresh session, in the English the record keeps. */
|
|
163
|
+
export const freshStartLine = (event: FreshStart): string => {
|
|
164
|
+
const from = event.from === undefined ? "" : ` at about ${tokensLabel(event.from)} tokens`;
|
|
165
|
+
const why =
|
|
166
|
+
event.why === "budget"
|
|
167
|
+
? `This chat's memory was full${from}, so it went on in a fresh session`
|
|
168
|
+
: event.why === "cold"
|
|
169
|
+
? `This chat had been idle long enough that re-reading it${from} would cost more than starting over, so it went on in a fresh session`
|
|
170
|
+
: event.why === "asked"
|
|
171
|
+
? "Started fresh, as you asked"
|
|
172
|
+
: "History cleared: started fresh";
|
|
173
|
+
const carried = event.summarized
|
|
174
|
+
? `, opened with a summary of the conversation${event.model === undefined ? "" : ` written by ${event.model}`} and its latest messages.`
|
|
175
|
+
: ", opened with its latest messages and the work in hand.";
|
|
176
|
+
return `${why}${carried}`;
|
|
177
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Durable spend ledger: per-account token and cost totals.
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { FreshStartWhySchema } from "./handoff.js";
|
|
3
4
|
// One row per attributed turn, appended at turn end and never pruned, unlike the activity log which shrinks as it
|
|
4
5
|
// prunes. Rollups project this on read, so a new grouping needs no new storage.
|
|
5
6
|
export const UsageTurnSchema = z.object({
|
|
@@ -107,6 +108,9 @@ export const UsageTurnSchema = z.object({
|
|
|
107
108
|
// Assigned on cold-eligible follow-ups only, including controls; cleared results only when a copy was resumed.
|
|
108
109
|
coldTrimArm: z.boolean().optional(),
|
|
109
110
|
coldTrimmed: z.number().int().min(0).optional(),
|
|
111
|
+
// A home conversation's turn that opened a fresh session rather than resuming its old one, and why (handoff.ts
|
|
112
|
+
// FreshStartSchema). Absent on every other turn, a home's included. What `bench:home` reads the rollover's cost off.
|
|
113
|
+
homeFresh: FreshStartWhySchema.optional(),
|
|
110
114
|
// What became of pre-turn retrieval on this turn, and how long it took. Assignment and DELIVERY are different
|
|
111
115
|
// facts: the first version of this mechanism was assigned to every eligible turn and reached four in five of them,
|
|
112
116
|
// which is the difference between a null result and a mechanism that never ran. Absent means the flag was off, so
|
|
@@ -14,11 +14,15 @@ export const claudeExperimentSettings = {
|
|
|
14
14
|
"Load the schemas of connected tools (browsers, devices, accounts, phones) only when the agent looks one up, instead of sending all of them with every request. The tools the agent leans on every turn stay loaded. Applies to Claude models on the Claude Code loop.",
|
|
15
15
|
),
|
|
16
16
|
// Both arms set the CLI's switch explicitly, so a shielded turn and an unshielded one compare the same two things.
|
|
17
|
+
// Measured and closed on 2026-10-26: Opus 5.5 turns on this loop, 273 deferred against 272 loaded over the same days
|
|
18
|
+
// (10-18 to 10-26), opened at 52k prompt tokens against 110k, read 120k cached tokens per model call against 194k and
|
|
19
|
+
// cost $0.055 a call against $0.072 ($5.03 a turn against $7.81 on average). Nothing is held out by default now; an
|
|
20
|
+
// owner who wants the comparison back sets a share here.
|
|
17
21
|
toolSearchHoldout: z
|
|
18
22
|
.number()
|
|
19
23
|
.min(0)
|
|
20
24
|
.max(1)
|
|
21
|
-
.default(0
|
|
25
|
+
.default(0)
|
|
22
26
|
.describe(
|
|
23
27
|
"What share of conversations to run with every tool loaded up front, so the two can be compared. Whole conversations rather than individual turns, because switching mid-conversation would rewrite the prompt the cache holds.",
|
|
24
28
|
),
|
package/src/schemas/settings.ts
CHANGED
|
@@ -457,6 +457,18 @@ export const SandboxSettingsSchema = z.object({
|
|
|
457
457
|
.describe(
|
|
458
458
|
"For the suggested hand-off: at or above this many tokens of context, suggest a summary rather than a trimmed session, where a model is set for hand-off summaries.",
|
|
459
459
|
),
|
|
460
|
+
// A home conversation is one chat kept for good (handoff.ts FreshStartSchema): past this, its next turn opens a fresh
|
|
461
|
+
// session instead of re-reading all of the old one. 150k sits under where a typical conversation here peaked (the spend
|
|
462
|
+
// ledger, 2026-10-13..27: median peak 172k), and a turn ending at 100-150k cost about $1 on average there against about
|
|
463
|
+
// $9 for one ending at 300-500k.
|
|
464
|
+
homeFreshOver: z
|
|
465
|
+
.number()
|
|
466
|
+
.int()
|
|
467
|
+
.min(0)
|
|
468
|
+
.default(150_000)
|
|
469
|
+
.describe(
|
|
470
|
+
"How large a home conversation's context may grow, in tokens, before its next message starts a fresh session: a summary and its latest messages instead of the whole conversation re-read on every call. Half of it is enough once the prompt cache has gone cold, since re-reading then costs a full write anyway. The chat keeps every message; only what the model reads starts over. Zero never starts one by itself.",
|
|
471
|
+
),
|
|
460
472
|
// Off by default: every refresh spends the account's own allowance on a conversation nobody is using yet. Before
|
|
461
473
|
// 2026-09-26 these were four top-level settings (settings-history.ts folds them).
|
|
462
474
|
keepWarm: KeepWarmSettingsSchema.prefault({}).describe(
|
package/src/schemas/shared.ts
CHANGED
|
@@ -18,7 +18,7 @@ export type MemberRole = z.infer<typeof MemberRoleSchema>;
|
|
|
18
18
|
export const GrantedRoleSchema = zEnum(["guest", "viewer", "collaborator", "writer", "maintainer"]);
|
|
19
19
|
export type GrantedRole = z.infer<typeof GrantedRoleSchema>;
|
|
20
20
|
// Single source for role order; every surface that gates on a role reads this ranking. A guest is below every
|
|
21
|
-
// floor: its routes are an allowlist of its own (
|
|
21
|
+
// floor: its routes are an allowlist of its own (protocol/member-reach.ts guestReach), never a floor it can clear.
|
|
22
22
|
const MEMBER_ROLE_RANK: Record<MemberRole, number> = { guest: 0, viewer: 1, collaborator: 2, writer: 3, maintainer: 4, owner: 5 };
|
|
23
23
|
export const roleAtLeast = (role: MemberRole, floor: MemberRole): boolean => MEMBER_ROLE_RANK[role] >= MEMBER_ROLE_RANK[floor];
|
|
24
24
|
// Rotating a door credential (event webhook, release gate, bug intake): the old value stops working immediately; the
|
|
@@ -33,6 +33,8 @@ export const WorkspaceSearchQuerySchema = z.object({
|
|
|
33
33
|
limit: z.coerce.number().int().positive().optional().describe("How many results to return."),
|
|
34
34
|
after: z.string().optional().describe("Resume from the cursor a previous answer handed back."),
|
|
35
35
|
});
|
|
36
|
+
// A search as its handler reads it, the switches parsed to booleans.
|
|
37
|
+
export type WorkspaceSearchQuery = z.infer<typeof WorkspaceSearchQuerySchema>;
|
|
36
38
|
// The query's verb enum.
|
|
37
39
|
export type WorkspaceSearchMode = NonNullable<z.infer<typeof WorkspaceSearchQuerySchema>["mode"]>;
|
|
38
40
|
export const WorkspaceSearchTagSchema = z.object({
|
|
@@ -130,3 +132,17 @@ export const WorkspaceSearchResultSchema = z.object({
|
|
|
130
132
|
features: z.array(z.string()).optional().describe("Which stages of the search were switched off for this run. Absent means all of them ran."),
|
|
131
133
|
});
|
|
132
134
|
export type WorkspaceSearchResult = z.infer<typeof WorkspaceSearchResultSchema>;
|
|
135
|
+
// What /workspace/search/stream sends: the files a text search has found so far, as it finds them, then its answer.
|
|
136
|
+
// `groups` frames are provisional (the first ones found, at most a page of them, in no order); `done` is the first page
|
|
137
|
+
// as /workspace/search would have answered it, which replaces them, and whose cursor pages on through the same answer.
|
|
138
|
+
export const WorkspaceSearchFrameSchema = z.discriminatedUnion("kind", [
|
|
139
|
+
z.object({
|
|
140
|
+
kind: z.literal("groups"),
|
|
141
|
+
groups: z.array(WorkspaceSearchGroupSchema).describe("Files found since the last frame, each with all of its matching lines."),
|
|
142
|
+
}),
|
|
143
|
+
z.object({
|
|
144
|
+
kind: z.literal("done"),
|
|
145
|
+
result: WorkspaceSearchResultSchema.describe("The first page of the finished search; it replaces every file sent before it."),
|
|
146
|
+
}),
|
|
147
|
+
]);
|
|
148
|
+
export type WorkspaceSearchFrame = z.infer<typeof WorkspaceSearchFrameSchema>;
|
|
@@ -74,6 +74,11 @@ const RUNTIME_DOMAINS = [
|
|
|
74
74
|
// live under the auth root, which no file push watches, and the Allowed list must move with the card that wrote one.
|
|
75
75
|
{ domain: "grants", invalidates: [["grants"]] },
|
|
76
76
|
|
|
77
|
+
// Somebody asked the owner for more access, or a request was answered (auth/members/access-requests.ts): the owner's
|
|
78
|
+
// list beside the roster moves, and so does the asker's own "asked" (GET /members/self). Like grants, they live under
|
|
79
|
+
// a root no file push watches.
|
|
80
|
+
{ domain: "access-requests", invalidates: [["access-requests"], ["members-self"]] },
|
|
81
|
+
|
|
77
82
|
// Somebody's composer draft was written, cleared or sent. The frame names no conversation and carries no words, since
|
|
78
83
|
// every member hears it: each window reads back its own caller's drafts (agents.drafts). The key is the editor's draft
|
|
79
84
|
// store's, which reads them back itself rather than through a cached query (models/conversations/drafts/).
|
|
@@ -708,7 +708,7 @@ export const LOCKED_STATE_ENTRIES: ReadonlySet<string> = new Set([
|
|
|
708
708
|
export const PLAN_DOCUMENTS_DIR = `${STATE_DIR}/records/sessions/claude/plans`;
|
|
709
709
|
|
|
710
710
|
// Where message attachments land: the browser posts to `<this>/<uuid>/<name>` before the message is sent, and the
|
|
711
|
-
// turn reads them back (schemas/agent.ts). The role floor (
|
|
711
|
+
// turn reads them back (schemas/agent.ts). The role floor (protocol/member-reach.ts) keys off this path: attaching is
|
|
712
712
|
// part of sending (a collaborator's grant), writing elsewhere in the workspace is the operating tier's, and both
|
|
713
713
|
// travel through the same upload route.
|
|
714
714
|
export const ATTACHMENTS_DIR = `${STATE_DIR}/records/artifacts/attachments`;
|
package/src/text/land-rows.ts
CHANGED
|
@@ -104,8 +104,12 @@ export const landedRow = (event: Extract<AgentEvent, { kind: "landed" }>): Trans
|
|
|
104
104
|
const deps = event.deps === undefined || event.deps.missing === 0 ? undefined : event.deps;
|
|
105
105
|
return {
|
|
106
106
|
role: "notice",
|
|
107
|
-
|
|
107
|
+
// A home's land (the only one named) is committed too, by nobody pressing anything: said, not left to the Changes panel.
|
|
108
|
+
text: `${event.land === undefined ? "Changes landed in your workspace: review them in the Changes panel." : "Landed in your workspace and committed."}${dependencyLine(event.deps)}`,
|
|
108
109
|
noticeAction: (event.deps?.started.length ?? 0) > 0 ? "depsInstall" : "landHold",
|
|
109
|
-
noticeCode: noticeCode({
|
|
110
|
+
noticeCode: noticeCode({
|
|
111
|
+
code: "landed",
|
|
112
|
+
params: deps === undefined && event.land === undefined ? undefined : { deps: deps?.missing, queued: deps?.deferred || undefined, land: event.land },
|
|
113
|
+
}),
|
|
110
114
|
};
|
|
111
115
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AgentEvent } from "../events/agent-events.js";
|
|
2
|
+
import type { TranscriptRow } from "../events/transcript.js";
|
|
3
|
+
import { noticeCode } from "../events/sandbox-notice.js";
|
|
4
|
+
import { contextTrimLine, contextTrimNotice } from "../schemas/context-trim.js";
|
|
5
|
+
import { freshStartLine, freshStartNotice, handedOffLine, handedOffNotice } from "../schemas/providers/handoff.js";
|
|
6
|
+
|
|
7
|
+
// 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, and where a home's session started over.
|
|
9
|
+
type StartingFrame = Extract<AgentEvent, { kind: "context_trim" | "handoff" | "fresh_start" }>;
|
|
10
|
+
|
|
11
|
+
/** A starting frame's row, in the English the record keeps, with the code a reader words it from. */
|
|
12
|
+
export const startingRow = (event: StartingFrame): TranscriptRow => {
|
|
13
|
+
switch (event.kind) {
|
|
14
|
+
case "context_trim":
|
|
15
|
+
return { role: "notice", text: contextTrimLine(event), noticeCode: noticeCode(contextTrimNotice(event)) };
|
|
16
|
+
case "handoff":
|
|
17
|
+
return { role: "notice", text: handedOffLine(event), noticeCode: noticeCode(handedOffNotice(event)) };
|
|
18
|
+
case "fresh_start":
|
|
19
|
+
return { role: "notice", text: freshStartLine(event), noticeCode: noticeCode(freshStartNotice(event)) };
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { STATE_DIR } from "@intentic/constants";
|
|
2
2
|
import { type AgentErrorCode, AgentErrorCodeSchema, type AgentEvent } from "../events/agent-events.js";
|
|
3
|
-
import { type TranscriptPatch, type TranscriptRow, TranscriptRowSchema } from "../events/transcript.js";
|
|
3
|
+
import { type TranscriptPatch, type TranscriptRow, TranscriptRowSchema, type TranscriptTool } from "../events/transcript.js";
|
|
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
7
|
import { RESUME_NOTES } from "../events/resume.js";
|
|
8
8
|
import { childReportPrompt, peerMessagePrompt } from "../events/agent-words.js";
|
|
9
|
-
import { applyTranscriptPatch, foldTurn, TranscriptFold, userRow } from "./transcript-fold.js";
|
|
9
|
+
import { applyTranscriptPatch, foldTurn, mapTool, TranscriptFold, userRow } from "./transcript-fold.js";
|
|
10
10
|
|
|
11
11
|
// Epoch ms stamped on the opening user row's sentAt.
|
|
12
12
|
const SENT_AT = 1_767_225_600_000;
|
|
@@ -84,6 +84,20 @@ describe("foldTurn", () => {
|
|
|
84
84
|
]);
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
+
// Devin sends a call's arguments only on its updates; a card with nothing yet takes them, one that has its own keeps it.
|
|
88
|
+
it("takes an update's input into a card that has neither target nor input, and only then", () => {
|
|
89
|
+
const events: AgentEvent[] = [
|
|
90
|
+
{ kind: "tool_call", id: "t1", name: "Click", category: "other", status: "in_progress" },
|
|
91
|
+
{ kind: "tool_call", id: "t2", name: "Bash", category: "execute", status: "in_progress", target: "ls" },
|
|
92
|
+
{ kind: "tool_call_update", id: "t1", status: "completed", input: '{"ref":"e12"}' },
|
|
93
|
+
{ kind: "tool_call_update", id: "t2", status: "completed", input: '{"command":"ls -la"}' },
|
|
94
|
+
];
|
|
95
|
+
const [click, bash] = foldOf("act", events).flatMap((message) => message.tools ?? []);
|
|
96
|
+
expect(click?.input).toBe('{"ref":"e12"}');
|
|
97
|
+
expect(bash).toMatchObject({ target: "ls" });
|
|
98
|
+
expect(Object.keys(bash ?? {})).not.toContain("input");
|
|
99
|
+
});
|
|
100
|
+
|
|
87
101
|
it("leaves an unanswered call in progress", () => {
|
|
88
102
|
const events: AgentEvent[] = [{ kind: "tool_call", id: "t1", name: "Bash", category: "execute", status: "in_progress" }];
|
|
89
103
|
expect(foldOf("run", events).at(-1)?.tools?.[0]?.status).toBe("in_progress");
|
|
@@ -484,6 +498,23 @@ describe("foldTurn", () => {
|
|
|
484
498
|
});
|
|
485
499
|
});
|
|
486
500
|
|
|
501
|
+
// A home's land is named on its row, so the commit its card files under that name is told on the same row.
|
|
502
|
+
it("names a home's land on its row", () => {
|
|
503
|
+
expect(foldOf("go", [{ kind: "landed", landed: true, land: "land-1" }]).at(-1)).toMatchObject({
|
|
504
|
+
text: "Landed in your workspace and committed.",
|
|
505
|
+
noticeCode: { code: "landed", params: { land: "land-1" } },
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
// Where a home's model memory starts over: a row of its own, which a reader can tell from any other notice.
|
|
510
|
+
it("marks a home's fresh session with a row of its own", () => {
|
|
511
|
+
expect(foldOf("go", [{ kind: "fresh_start", why: "budget", from: 182_000, summarized: true, model: "haiku" }]).at(-1)).toEqual({
|
|
512
|
+
role: "notice",
|
|
513
|
+
text: "This chat's memory was full at about 182k tokens, so it went on in a fresh session, opened with a summary of the conversation written by haiku and its latest messages.",
|
|
514
|
+
noticeCode: { code: "freshStart", params: { why: "budget", from: "182k", model: "haiku", summarized: true } },
|
|
515
|
+
});
|
|
516
|
+
});
|
|
517
|
+
|
|
487
518
|
// A spawned child's work goes into its parent's checkout, as the parent's in-process subagents' edits do: the row
|
|
488
519
|
// says so, never that it reached the owner's workspace, and says who is to bring in a clash.
|
|
489
520
|
it("says a child's work went into its parent's checkout, or was held off it by a clash", () => {
|
|
@@ -688,6 +719,75 @@ describe("foldTurn", () => {
|
|
|
688
719
|
|
|
689
720
|
// Patches applied to a window's rows must reproduce the fold's own rows exactly, or live and reopened chats drift.
|
|
690
721
|
describe("patches", () => {
|
|
722
|
+
const call = (id: string, children?: TranscriptTool[]): TranscriptTool => {
|
|
723
|
+
const tool: TranscriptTool = { id, name: "Read", category: "read", status: "completed" };
|
|
724
|
+
if (children !== undefined) {
|
|
725
|
+
tool.children = children;
|
|
726
|
+
}
|
|
727
|
+
return tool;
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
it("a nested tool update preserves unrelated branches and the original tree", () => {
|
|
731
|
+
const sibling = call("sibling");
|
|
732
|
+
const leaf = call("leaf");
|
|
733
|
+
const parent = call("parent", [sibling, leaf]);
|
|
734
|
+
const other = call("other", [call("untouched")]);
|
|
735
|
+
const tools = [other, parent];
|
|
736
|
+
const next = mapTool(tools, "leaf", (tool) => ({ ...tool, thinking: "new reasoning" }));
|
|
737
|
+
|
|
738
|
+
expect(next).toEqual([other, { ...parent, children: [sibling, { ...leaf, thinking: "new reasoning" }] }]);
|
|
739
|
+
expect(next).not.toBe(tools);
|
|
740
|
+
expect(next[0]).toBe(other);
|
|
741
|
+
expect(next[1]?.children?.[0]).toBe(sibling);
|
|
742
|
+
expect(leaf.thinking).toBeUndefined();
|
|
743
|
+
expect(parent.children).toEqual([sibling, leaf]);
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
it("an absent tool keeps the tree, while a matched identity callback still reports a match", () => {
|
|
747
|
+
const tools = [call("parent", [call("child")])];
|
|
748
|
+
let called = 0;
|
|
749
|
+
const identity = (tool: TranscriptTool): TranscriptTool => {
|
|
750
|
+
called += 1;
|
|
751
|
+
return tool;
|
|
752
|
+
};
|
|
753
|
+
expect(mapTool(tools, "missing", identity)).toBe(tools);
|
|
754
|
+
expect(called).toBe(0);
|
|
755
|
+
const matched = mapTool(tools, "child", identity);
|
|
756
|
+
expect(matched).toEqual(tools);
|
|
757
|
+
expect(matched).not.toBe(tools);
|
|
758
|
+
expect(called).toBe(1);
|
|
759
|
+
});
|
|
760
|
+
|
|
761
|
+
it("updates every matching branch without descending into a matching card", () => {
|
|
762
|
+
const hidden = call("target");
|
|
763
|
+
const parent = call("target", [hidden]);
|
|
764
|
+
const nestedLeaf = call("target");
|
|
765
|
+
const nested = call("branch", [nestedLeaf]);
|
|
766
|
+
const tools = [parent, nested];
|
|
767
|
+
let called = 0;
|
|
768
|
+
const next = mapTool(tools, "target", (tool) => {
|
|
769
|
+
called += 1;
|
|
770
|
+
return { ...tool, thinking: "updated" };
|
|
771
|
+
});
|
|
772
|
+
expect(next).toEqual([
|
|
773
|
+
{ ...parent, thinking: "updated" },
|
|
774
|
+
{ ...nested, children: [{ ...nestedLeaf, thinking: "updated" }] },
|
|
775
|
+
]);
|
|
776
|
+
expect(called).toBe(2);
|
|
777
|
+
expect(next[0]?.children?.[0]).toBe(hidden);
|
|
778
|
+
});
|
|
779
|
+
|
|
780
|
+
it("an indexed row patch keeps unrelated rows and ignores positions outside the transcript", () => {
|
|
781
|
+
const opening: TranscriptRow = { role: "user", text: "go" };
|
|
782
|
+
const rows: TranscriptRow[] = [opening, { role: "assistant", text: "hello" }];
|
|
783
|
+
const next = applyTranscriptPatch(rows, { op: "text", index: 1, text: " world" });
|
|
784
|
+
expect(next).toEqual([opening, { role: "assistant", text: "hello world" }]);
|
|
785
|
+
expect(next[0]).toBe(rows[0]);
|
|
786
|
+
expect(rows[1]?.text).toBe("hello");
|
|
787
|
+
expect(applyTranscriptPatch(rows, { op: "text", index: 2, text: "ignored" })).toEqual(rows);
|
|
788
|
+
expect(applyTranscriptPatch(rows, { op: "text", index: -1, text: "ignored" })).toEqual(rows);
|
|
789
|
+
});
|
|
790
|
+
|
|
691
791
|
const replay = (
|
|
692
792
|
opening: readonly TranscriptRow[],
|
|
693
793
|
events: readonly AgentEvent[],
|