Skip to content

Commit abe4c91

Browse files
Gustav-SimonssonTheGreatAxios
authored andcommitted
refactor(session): deepen comment compression in the runtime assembly cluster
1 parent b81d509 commit abe4c91

5 files changed

Lines changed: 39 additions & 45 deletions

File tree

‎src/session/assemble-runtime.ts‎

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,7 @@ export interface SessionGate {
279279
/**
280280
* Seed approvals (session → project → global → provider-model) and build the
281281
* permission gate over roots, persist, and log wiring. Runners differ only
282-
* in how approval reaches an operator (modal vs stdin) — both arrive as
283-
* callbacks.
282+
* in the operator channel (modal vs stdin); approval arrives as a callback.
284283
*/
285284
export async function assembleSessionGate(
286285
args: SessionGateArgs,
@@ -378,18 +377,18 @@ export interface AdvertisedToolset {
378377

379378
/**
380379
* Fixed built-in prefix plus session-activated tools, family-gated for the
381-
* wire. The provider identity is read per call so a live model switch
382-
* re-gates without rebuilding the agent.
380+
* wire. Provider identity is read per call, so a live model switch re-gates
381+
* without a rebuild.
383382
*
384383
* Activation and advertisement are split: activating opens the call gate at
385384
* once; flushPromotions commits names onto the wire (promote-on-execute
386-
* flushes the one called name, tool_search only the top ranked hits). Fold
387-
* breaks the cache prefix — pruneIdlePromotions drops the advertised tail
388-
* back to it.
385+
* flushes the called name, tool_search only top-ranked hits). Fold breaks
386+
* the cache prefix — pruneIdlePromotions drops the advertised tail back to
387+
* it.
389388
*
390389
* `pinnedTools` (local settings) merge into the prefix — advertised from the
391-
* first turn and exempt from activation state, so resume needs no
392-
* tool_search round-trip for the project's hottest integrations.
390+
* first turn, exempt from activation state, so resume skips the tool_search
391+
* round-trip for them.
393392
*/
394393
export function createAdvertisedToolset(args: {
395394
sessionMode: SessionMode;
@@ -566,9 +565,8 @@ export interface ChatAgentWiring {
566565
anthropicCachePrompt?: () => boolean;
567566
/**
568567
* Present when a resumed run record has an Anthropic-protocol cache write
569-
* and the provider about to be called is the same protocol. Read at each
570-
* build so an interrupt rebuild of the same session still folds before the
571-
* next infer. Omitted for a new session.
568+
* and the next provider is the same protocol. Read at each build so an
569+
* interrupt rebuild of the same session still folds before the next infer.
572570
*/
573571
getCacheWriteSeed?: () => { at: number; model: string } | undefined;
574572
/** Assigns the runner's live agent/storage holders; keeps call sites unchanged. */
@@ -850,9 +848,9 @@ export interface SessionLifecycle {
850848

851849
/**
852850
* Hook manager, turn observer, run sink, and in-flight cycle recorder. Pure
853-
* construction — every live value (session id, source, context dir) is read
854-
* through a getter at event time, so it can assemble before the agent exists
855-
* (the TUI builds it early, exec late; same call, different position).
851+
* construction — live values (session id, source, context dir) are read
852+
* through getters at event time, so it can assemble before the agent exists
853+
* (TUI early, exec late).
856854
*/
857855
export async function assembleSessionLifecycle(
858856
wiring: SessionLifecycleWiring,

‎src/session/compaction-handoff.ts‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -825,11 +825,9 @@ export function renderHandoffFile(
825825
}
826826

827827
/**
828-
* Render the thin live spine: goal cut at a token boundary, standing output
829-
* tokens uncut, constraints/decisions, the evidence echo, activated tools,
830-
* and the file pointer. Starts with COMPACTED_PREFIX so the next fold parses
831-
* it as a handoff turn. Counts, file lists, and next actions stay in the fat
832-
* file.
828+
* Render the thin live spine (shape in the module doc). Starts with
829+
* COMPACTED_PREFIX so the next fold parses it as a handoff turn; counts,
830+
* file lists, and next actions stay in the fat file.
833831
*/
834832
export function renderHandoffSpine(
835833
spine: SpineFacts,
@@ -891,9 +889,9 @@ export interface HandoffFold {
891889
}
892890

893891
/**
894-
* Build one fold's handoff: extract the artifact from the folded turns
895-
* (unioned with the previous fat file when provided), render the fat file,
896-
* and return the thin spine carrying the file's pointer.
892+
* Build one fold's handoff: extract the artifact (unioned with the previous
893+
* fat file when provided), render the fat file, and return the thin spine
894+
* carrying the file's pointer.
897895
*/
898896
export function buildHandoffFold(
899897
foldedTurns: readonly ConversationTurn[],

‎src/session/optimized-context-store.ts‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,12 @@ function sanitizeCallId(callId: string): string {
8686

8787
/**
8888
* Parse conversation turns out of one JSONL segment. A crash can tear the
89-
* final line of the active segment mid-write; `tolerateTornTail` drops it
90-
* instead of aborting resume. Null padding from a stale keepBytes write is
91-
* stripped. `skipMalformed` drops (or partially recovers) a bad line
92-
* anywhere and keeps surrounding history — used by `loadRecentTurns` and
93-
* the reactor's `load()` recovery path, since a bad line should not kill
94-
* the session. A truncated stub glued to the next append still yields a
95-
* trailing complete turn via `recoverTurnFromGluedLine`.
89+
* final line of the active segment mid-write; `tolerateTornTail` drops it.
90+
* Null padding from a stale keepBytes write is stripped. `skipMalformed`
91+
* drops (or partially recovers) a bad line anywhere and keeps surrounding
92+
* history — used by `loadRecentTurns` and the reactor's `load()` recovery
93+
* path. A truncated stub glued to the next append still yields a trailing
94+
* complete turn via `recoverTurnFromGluedLine`.
9695
*/
9796
function recoverTurnFromGluedLine(line: string): ConversationTurn | null {
9897
// Walk every `{` start: a truncated prefix glued onto a complete record

‎src/session/runtime-assembly.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ export interface LiveSubAgentSources {
118118
/**
119119
* Single owner of every session fact a sub-agent spawn reads. Each switch
120120
* path (model picker, /agent, post-connect refresh, favorite toggle)
121-
* reassigns the runner's config, so all three derive from a config getter
122-
* per spawn; hand-synced snapshots went stale when a switch path missed one.
121+
* reassigns the runner's config, so all three read a config getter per
122+
* spawn; hand-synced snapshots went stale when a switch path missed one.
123123
*/
124124
export function createLiveSubAgentSources(
125125
getConfig: () => SubAgentSourcesConfig,
@@ -213,7 +213,7 @@ function persistBestEffort(
213213
* Route a gate-persisted grant to the store its scope selects. Session
214214
* grants never reach here — the gate keeps those in memory only.
215215
* `getActiveProviderModel` is read at persist time so a live model switch
216-
* stores under the pair now in use.
216+
* stores under the pair in use.
217217
*/
218218
export function createApprovalPersist(
219219
cwd: string,
@@ -582,9 +582,9 @@ export function createSessionPruningCompactor(
582582

583583
/**
584584
* Content-less inbound the compaction governor self-delivers after a compact
585-
* cycle so the reactor re-enters (it emits no event after compact). Single
586-
* owner for the TUI, exec, and sub-agent loops; the copies were
587-
* byte-identical, so a new field is a one-site change.
585+
* so the reactor re-enters (it emits nothing after). One owner for the TUI,
586+
* exec, and sub-agent loops — the copies were byte-identical, so a new
587+
* field is a one-site change.
588588
*/
589589
export function buildCompactionContinuationMessage(): InboundMessage {
590590
return {
@@ -604,10 +604,10 @@ export function buildCompactionContinuationMessage(): InboundMessage {
604604
/**
605605
* Per-host consume-once gate for the compaction continuation emit. The
606606
* reactor emits it before compact runs and nothing after, so the emission
607-
* is the outstanding-continuation claim. Each emission (keyed by its
607+
* is the outstanding-continuation claim. Each emission (keyed by a
608608
* session-scoped seq) is answered at most once: a replayed duplicate is
609-
* ignored since every delivery costs a billable inference, and a forged
610-
* fresh seq is answered with wait, so it cannot burn a model turn either.
609+
* ignored (every delivery costs a billable inference) and a forged fresh
610+
* seq is answered with wait, so it cannot burn a model turn.
611611
*/
612612
export function createContinuationGate(): {
613613
shouldDeliver: (seq: number) => boolean;

‎src/session/summarizer.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//
33
// On compaction the pruning compactor replaces older turns with a summary. A
44
// deterministic stats blob loses what resuming work needs, so this module
5-
// writes a structured, workflow-aware narrative via one inference call
6-
// against the session's own model.
5+
// writes a structured, workflow-aware narrative in one inference call on the
6+
// session's own model.
77

88
import { type } from "arktype";
99
import { runInference, type Dependencies } from "@intx/inference";
@@ -119,8 +119,7 @@ export async function buildArchiveSummaryExcerpt(
119119
}
120120

121121
// What the agent was doing when compaction fired, so the summary preserves
122-
// the workflow contract ("we are at step 3/7 of /build") instead of dropping
123-
// it into the compacted region.
122+
// the workflow contract ("we are at step 3/7 of /build").
124123
export interface SummaryContext {
125124
workflow?: {
126125
name?: string;
@@ -453,8 +452,8 @@ export interface ModelSummarizerOptions {
453452
/**
454453
* Build a `summarize(turns, ctx)` function suitable for `CompactorConfig`.
455454
* Throws on empty output or a failed call so the compact cycle can substitute
456-
* a statistics-only stub; the session pruning wrapper owns that stub's
457-
* operator notice and fires it only after the fold commits.
455+
* a statistics-only stub; the pruning wrapper owns that stub's notice and
456+
* fires it only after the fold commits.
458457
*/
459458
export function createModelSummarizer(
460459
options: ModelSummarizerOptions,

0 commit comments

Comments
 (0)