@spunto/build 0.29.0 → 0.30.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spunto/build",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "Spunto's shared Build engine — the devcontainer image protocol and VS Code extension registry clients, with no database, no HTTP framework and no UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -724,6 +724,132 @@
|
|
|
724
724
|
],
|
|
725
725
|
"additionalProperties": false
|
|
726
726
|
},
|
|
727
|
+
{
|
|
728
|
+
"type": "object",
|
|
729
|
+
"properties": {
|
|
730
|
+
"type": {
|
|
731
|
+
"const": "context.compacted"
|
|
732
|
+
},
|
|
733
|
+
"source": {
|
|
734
|
+
"description": "The harness's own message this event was read from, verbatim — kept so the projection can be replayed."
|
|
735
|
+
},
|
|
736
|
+
"trigger": {
|
|
737
|
+
"anyOf": [
|
|
738
|
+
{
|
|
739
|
+
"type": "string"
|
|
740
|
+
},
|
|
741
|
+
{
|
|
742
|
+
"type": "null"
|
|
743
|
+
}
|
|
744
|
+
]
|
|
745
|
+
},
|
|
746
|
+
"preTokens": {
|
|
747
|
+
"anyOf": [
|
|
748
|
+
{
|
|
749
|
+
"type": "number"
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
"type": "null"
|
|
753
|
+
}
|
|
754
|
+
]
|
|
755
|
+
},
|
|
756
|
+
"postTokens": {
|
|
757
|
+
"anyOf": [
|
|
758
|
+
{
|
|
759
|
+
"type": "number"
|
|
760
|
+
},
|
|
761
|
+
{
|
|
762
|
+
"type": "null"
|
|
763
|
+
}
|
|
764
|
+
]
|
|
765
|
+
},
|
|
766
|
+
"durationMs": {
|
|
767
|
+
"anyOf": [
|
|
768
|
+
{
|
|
769
|
+
"type": "number"
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
"type": "null"
|
|
773
|
+
}
|
|
774
|
+
]
|
|
775
|
+
},
|
|
776
|
+
"summary": {
|
|
777
|
+
"type": "string"
|
|
778
|
+
},
|
|
779
|
+
"truncated": {
|
|
780
|
+
"type": "boolean"
|
|
781
|
+
},
|
|
782
|
+
"parentCallId": {
|
|
783
|
+
"anyOf": [
|
|
784
|
+
{
|
|
785
|
+
"type": "string"
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
"type": "null"
|
|
789
|
+
}
|
|
790
|
+
]
|
|
791
|
+
}
|
|
792
|
+
},
|
|
793
|
+
"required": [
|
|
794
|
+
"type"
|
|
795
|
+
],
|
|
796
|
+
"additionalProperties": false
|
|
797
|
+
},
|
|
798
|
+
{
|
|
799
|
+
"type": "object",
|
|
800
|
+
"properties": {
|
|
801
|
+
"type": {
|
|
802
|
+
"const": "skill.loaded"
|
|
803
|
+
},
|
|
804
|
+
"source": {
|
|
805
|
+
"description": "The harness's own message this event was read from, verbatim — kept so the projection can be replayed."
|
|
806
|
+
},
|
|
807
|
+
"callId": {
|
|
808
|
+
"anyOf": [
|
|
809
|
+
{
|
|
810
|
+
"type": "string"
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
"type": "null"
|
|
814
|
+
}
|
|
815
|
+
]
|
|
816
|
+
},
|
|
817
|
+
"name": {
|
|
818
|
+
"type": "string"
|
|
819
|
+
},
|
|
820
|
+
"path": {
|
|
821
|
+
"anyOf": [
|
|
822
|
+
{
|
|
823
|
+
"type": "string"
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
"type": "null"
|
|
827
|
+
}
|
|
828
|
+
]
|
|
829
|
+
},
|
|
830
|
+
"text": {
|
|
831
|
+
"type": "string"
|
|
832
|
+
},
|
|
833
|
+
"truncated": {
|
|
834
|
+
"type": "boolean"
|
|
835
|
+
},
|
|
836
|
+
"parentCallId": {
|
|
837
|
+
"anyOf": [
|
|
838
|
+
{
|
|
839
|
+
"type": "string"
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
"type": "null"
|
|
843
|
+
}
|
|
844
|
+
]
|
|
845
|
+
}
|
|
846
|
+
},
|
|
847
|
+
"required": [
|
|
848
|
+
"type",
|
|
849
|
+
"name"
|
|
850
|
+
],
|
|
851
|
+
"additionalProperties": false
|
|
852
|
+
},
|
|
727
853
|
{
|
|
728
854
|
"type": "object",
|
|
729
855
|
"properties": {
|
|
@@ -44,6 +44,8 @@ export const TASK_EVENT_TYPES = [
|
|
|
44
44
|
"session.ended",
|
|
45
45
|
"session.background",
|
|
46
46
|
"subagent",
|
|
47
|
+
"context.compacted",
|
|
48
|
+
"skill.loaded",
|
|
47
49
|
"raw",
|
|
48
50
|
] as const
|
|
49
51
|
export type TaskEventType = (typeof TASK_EVENT_TYPES)[number]
|
|
@@ -238,6 +240,28 @@ const FIELDS: Record<TaskEventType | TransientType, Record<string, Field>> = {
|
|
|
238
240
|
// Its report, once it has ended.
|
|
239
241
|
summary: str(),
|
|
240
242
|
},
|
|
243
|
+
// The harness compacted its context: what it dropped, how long it took, and the summary it
|
|
244
|
+
// carries on with in their place — one event, never a message of the human's (the harness hands
|
|
245
|
+
// the summary back as a user turn). `parentCallId` when it is a subagent's context, not the session's.
|
|
246
|
+
"context.compacted": {
|
|
247
|
+
trigger: nullable(str()),
|
|
248
|
+
preTokens: COUNT,
|
|
249
|
+
postTokens: COUNT,
|
|
250
|
+
durationMs: COUNT,
|
|
251
|
+
summary: str(),
|
|
252
|
+
truncated: bool(),
|
|
253
|
+
parentCallId: PARENT,
|
|
254
|
+
},
|
|
255
|
+
// The harness loaded a skill's instructions into the context — the body of its SKILL.md, which
|
|
256
|
+
// the harness hands the model as a user turn. `callId` is the call that asked for it, when one did.
|
|
257
|
+
"skill.loaded": {
|
|
258
|
+
callId: nullable(str()),
|
|
259
|
+
name: req(str()),
|
|
260
|
+
path: nullable(str()),
|
|
261
|
+
text: str(),
|
|
262
|
+
truncated: bool(),
|
|
263
|
+
parentCallId: PARENT,
|
|
264
|
+
},
|
|
241
265
|
raw: { json: any(), text: str() },
|
|
242
266
|
// Not stored. `start` opens a fresh draft (one draft is one text block), else `text` is appended.
|
|
243
267
|
"message.delta": { text: req(str()), start: bool() },
|
|
@@ -297,6 +321,8 @@ const CLIPPED: Partial<Record<TaskEventType, string>> = {
|
|
|
297
321
|
thinking: "text",
|
|
298
322
|
"tool.call": "input",
|
|
299
323
|
"tool.result": "output",
|
|
324
|
+
"context.compacted": "summary",
|
|
325
|
+
"skill.loaded": "text",
|
|
300
326
|
}
|
|
301
327
|
|
|
302
328
|
/** Why this line is not a valid output line of the contract, or null. */
|
|
@@ -318,13 +318,19 @@ export function withoutFileBytes(value: unknown, depth = 0): unknown {
|
|
|
318
318
|
*/
|
|
319
319
|
export function claudeTranslator(now: () => Date = () => new Date()): (message: Record<string, unknown>) => Record<string, unknown>[] {
|
|
320
320
|
let carried: string | null = null
|
|
321
|
+
const compaction = compactionReader()
|
|
322
|
+
const skills = skillReader()
|
|
321
323
|
const subagents = subagentTracker()
|
|
322
324
|
return (message) => {
|
|
323
325
|
if (message.type === "stream_event") return claudeDelta(message)
|
|
324
326
|
// The runner answers the `title` verb itself; a control response is never a title here.
|
|
325
327
|
if (message.type === "control_response") return []
|
|
328
|
+
const compacted = compaction(message)
|
|
329
|
+
if (compacted.handled) return compacted.lines
|
|
326
330
|
const subagent = subagents(message)
|
|
327
|
-
if (subagent) return subagent.map((line) => ({ ...line, source: message }))
|
|
331
|
+
if (subagent) return [...compacted.lines, ...subagent.map((line) => ({ ...line, source: message }))]
|
|
332
|
+
const skill = skills(message)
|
|
333
|
+
if (skill) return [...compacted.lines, skill]
|
|
328
334
|
const events = adaptClaudeJson(withoutFileBytes(message) as Record<string, unknown>)
|
|
329
335
|
for (const e of events) {
|
|
330
336
|
const limit = e.payload.limit as TurnLimit | undefined
|
|
@@ -336,7 +342,166 @@ export function claudeTranslator(now: () => Date = () => new Date()): (message:
|
|
|
336
342
|
}
|
|
337
343
|
carried = null
|
|
338
344
|
}
|
|
339
|
-
return events.map((e) => ({ type: e.type, ...e.payload, source: message }))
|
|
345
|
+
return [...compacted.lines, ...events.map((e) => ({ type: e.type, ...e.payload, source: message }))]
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// ── Skills ────────────────────────────────────────────────────────────────────
|
|
350
|
+
|
|
351
|
+
/** How Claude Code opens the turn that carries a skill's instructions. Measured on 2.1.310, 2026-11-24. */
|
|
352
|
+
const SKILL_PREFIX = /^Base directory for this skill: ([^\n]*)\n*/
|
|
353
|
+
|
|
354
|
+
/** How many asked-for skills are remembered while their body has not come: a loop guard, not a limit anyone reaches. */
|
|
355
|
+
const MAX_PENDING_SKILLS = 16
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* A skill being loaded, read as one `skill.loaded` rather than as something the member wrote.
|
|
359
|
+
*
|
|
360
|
+
* When the model calls the `Skill` tool, Claude Code answers the call with one line (« Launching
|
|
361
|
+
* skill: e2e-proof ») and then hands the model the skill's whole SKILL.md as a **user** turn,
|
|
362
|
+
* `isSynthetic`, opening with « Base directory for this skill: <path> ». Read naively that is
|
|
363
|
+
* kilobytes of instructions in the member's name. So the calls are remembered as they go by, and
|
|
364
|
+
* the synthetic turn that follows is tied back to the call that asked for it — by the skill's
|
|
365
|
+
* name, else the oldest call still waiting. A body no call explains (a slash command typed in a
|
|
366
|
+
* terminal session) still comes out as `skill.loaded`, named after its directory.
|
|
367
|
+
*/
|
|
368
|
+
function skillReader(): (message: Record<string, unknown>) => Record<string, unknown> | null {
|
|
369
|
+
const pending: { callId: string; name: string }[] = []
|
|
370
|
+
return (message) => {
|
|
371
|
+
if (message.type === "assistant") {
|
|
372
|
+
const content = (message.message as Record<string, unknown> | undefined)?.content
|
|
373
|
+
for (const block of Array.isArray(content) ? content : []) {
|
|
374
|
+
if (!block || typeof block !== "object" || block.type !== "tool_use" || block.name !== "Skill") continue
|
|
375
|
+
const skill = (block.input as Record<string, unknown> | undefined)?.skill
|
|
376
|
+
if (typeof block.id === "string" && typeof skill === "string") pending.push({ callId: block.id, name: skill })
|
|
377
|
+
if (pending.length > MAX_PENDING_SKILLS) pending.shift()
|
|
378
|
+
}
|
|
379
|
+
return null
|
|
380
|
+
}
|
|
381
|
+
if (message.type !== "user" || message.isSynthetic !== true) return null
|
|
382
|
+
const full = userText(message)
|
|
383
|
+
const header = SKILL_PREFIX.exec(full)
|
|
384
|
+
if (!header) return null
|
|
385
|
+
const path = header[1]!.trim() || null
|
|
386
|
+
const dir = path?.split("/").filter(Boolean).pop() ?? ""
|
|
387
|
+
// `plugin:skill` is called by its full name and lives in a directory named after the skill.
|
|
388
|
+
const at = pending.findIndex((p) => p.name === dir || p.name.split(":").pop() === dir)
|
|
389
|
+
const call = at >= 0 ? pending.splice(at, 1)[0]! : pending.shift()
|
|
390
|
+
const { text, truncated } = clip(full.slice(header[0].length))
|
|
391
|
+
const parentCallId = typeof message.parent_tool_use_id === "string" && message.parent_tool_use_id ? message.parent_tool_use_id : null
|
|
392
|
+
return {
|
|
393
|
+
type: "skill.loaded",
|
|
394
|
+
callId: call?.callId ?? null,
|
|
395
|
+
name: call?.name ?? (dir || "skill"),
|
|
396
|
+
path,
|
|
397
|
+
text,
|
|
398
|
+
truncated,
|
|
399
|
+
...(parentCallId ? { parentCallId } : {}),
|
|
400
|
+
source: message,
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// ── Compaction ────────────────────────────────────────────────────────────────
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* How Claude Code's summary turn begins — only for a summary nothing else marks (a subagent's has
|
|
409
|
+
* no boundary before it). Measured on Claude Code 2.1.310, 2026-11-24.
|
|
410
|
+
*/
|
|
411
|
+
const SUMMARY_PREFIX = "This session is being continued from a previous conversation"
|
|
412
|
+
|
|
413
|
+
type Compaction = { lines: Record<string, unknown>[]; handled: boolean }
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* A compaction, read as **one** `context.compacted`. What Claude Code prints, measured on
|
|
417
|
+
* 2026-11-24 (a session that compacted twelve times):
|
|
418
|
+
*
|
|
419
|
+
* 1. `system/status` `compacting`, restated as the summary is written (`compact_output_chars`);
|
|
420
|
+
* 2. `system/status` `null`, `compact_result: "success"`;
|
|
421
|
+
* 3. `system/compact_boundary` — the numbers (`compact_metadata`: trigger, tokens before and
|
|
422
|
+
* after, duration), and `preserved_segment.anchor_uuid`, the uuid of…
|
|
423
|
+
* 4. …a **user** turn, `isSynthetic`, whose text is the summary the session carries on with.
|
|
424
|
+
*
|
|
425
|
+
* Read naively, (1)–(3) are `raw` and (4) is 8 KB the member seems to have written. So (1) and (2)
|
|
426
|
+
* are absorbed, (3) is held, and (4) closes it — recognised by the anchor first, then by what
|
|
427
|
+
* Claude Code marks (`isCompactSummary`, `isVisibleInTranscriptOnly`), then as the synthetic turn
|
|
428
|
+
* right after a boundary, and by its first words only when nothing else says so. A boundary that
|
|
429
|
+
* no summary follows still comes out, without one, before the next line.
|
|
430
|
+
*
|
|
431
|
+
* A failed compaction (`compact_result: "failed"`) is left to the generic reader: it is information
|
|
432
|
+
* about the harness, and rare enough not to need a type.
|
|
433
|
+
*/
|
|
434
|
+
function compactionReader(): (message: Record<string, unknown>) => Compaction {
|
|
435
|
+
let boundary: Record<string, unknown> | null = null
|
|
436
|
+
const flush = (): Record<string, unknown>[] => {
|
|
437
|
+
if (!boundary) return []
|
|
438
|
+
const line = compactedLine(boundary, null)
|
|
439
|
+
boundary = null
|
|
440
|
+
return [line]
|
|
441
|
+
}
|
|
442
|
+
return (message) => {
|
|
443
|
+
if (message.type === "system" && message.subtype === "status") {
|
|
444
|
+
const absorbed = message.status === "compacting" || (message.status === null && message.compact_result === "success")
|
|
445
|
+
return { lines: absorbed ? [] : flush(), handled: absorbed }
|
|
446
|
+
}
|
|
447
|
+
if (message.type === "system" && message.subtype === "compact_boundary") {
|
|
448
|
+
const lines = flush()
|
|
449
|
+
boundary = message
|
|
450
|
+
return { lines, handled: true }
|
|
451
|
+
}
|
|
452
|
+
if (message.type === "user" && isSummaryTurn(message, boundary)) {
|
|
453
|
+
const line = compactedLine(boundary, message)
|
|
454
|
+
boundary = null
|
|
455
|
+
return { lines: [line], handled: true }
|
|
456
|
+
}
|
|
457
|
+
return { lines: flush(), handled: false }
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function isSummaryTurn(message: Record<string, unknown>, boundary: Record<string, unknown> | null): boolean {
|
|
462
|
+
if (message.isCompactSummary === true) return true
|
|
463
|
+
if (boundary) {
|
|
464
|
+
const anchor = anchorOf(boundary)
|
|
465
|
+
if (anchor && message.uuid === anchor) return true
|
|
466
|
+
if (message.isVisibleInTranscriptOnly === true) return true
|
|
467
|
+
if (!anchor && message.isSynthetic === true && !message.parent_tool_use_id) return true
|
|
468
|
+
}
|
|
469
|
+
return message.isSynthetic === true && userText(message).startsWith(SUMMARY_PREFIX)
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function anchorOf(boundary: Record<string, unknown>): string | null {
|
|
473
|
+
const meta = (boundary.compact_metadata ?? {}) as Record<string, unknown>
|
|
474
|
+
for (const key of ["preserved_messages", "preserved_segment"]) {
|
|
475
|
+
const anchor = (meta[key] as Record<string, unknown> | undefined)?.anchor_uuid
|
|
476
|
+
if (typeof anchor === "string") return anchor
|
|
477
|
+
}
|
|
478
|
+
return null
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function userText(message: Record<string, unknown>): string {
|
|
482
|
+
const content = (message.message as Record<string, unknown> | undefined)?.content
|
|
483
|
+
if (typeof content === "string") return content
|
|
484
|
+
if (!Array.isArray(content)) return ""
|
|
485
|
+
return content
|
|
486
|
+
.filter((b): b is Record<string, unknown> => !!b && typeof b === "object" && b.type === "text" && typeof b.text === "string")
|
|
487
|
+
.map((b) => b.text as string)
|
|
488
|
+
.join("\n\n")
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/** The event, with both harness lines as its source when there are two — the projection stays replayable. */
|
|
492
|
+
function compactedLine(boundary: Record<string, unknown> | null, summary: Record<string, unknown> | null): Record<string, unknown> {
|
|
493
|
+
const meta = (boundary?.compact_metadata ?? {}) as Record<string, unknown>
|
|
494
|
+
const { text, truncated } = clip(summary ? userText(summary) : "")
|
|
495
|
+
const parentCallId = typeof summary?.parent_tool_use_id === "string" && summary.parent_tool_use_id ? summary.parent_tool_use_id : null
|
|
496
|
+
return {
|
|
497
|
+
type: "context.compacted",
|
|
498
|
+
trigger: typeof meta.trigger === "string" ? meta.trigger : null,
|
|
499
|
+
preTokens: num(meta.pre_tokens),
|
|
500
|
+
postTokens: num(meta.post_tokens),
|
|
501
|
+
durationMs: num(meta.duration_ms),
|
|
502
|
+
...(summary ? { summary: text, truncated } : {}),
|
|
503
|
+
...(parentCallId ? { parentCallId } : {}),
|
|
504
|
+
source: boundary && summary ? [boundary, summary] : (boundary ?? summary),
|
|
340
505
|
}
|
|
341
506
|
}
|
|
342
507
|
|