@yaks/session 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +1392 -2
- package/_dist/admission.d.ts +15 -0
- package/_dist/admission.d.ts.map +1 -0
- package/_dist/announce.d.ts +17 -0
- package/_dist/announce.d.ts.map +1 -0
- package/_dist/answer.d.ts +200 -0
- package/_dist/answer.d.ts.map +1 -0
- package/_dist/append.d.ts +10 -0
- package/_dist/append.d.ts.map +1 -0
- package/_dist/archive.d.ts +6 -0
- package/_dist/archive.d.ts.map +1 -0
- package/_dist/asks.d.ts +11 -0
- package/_dist/asks.d.ts.map +1 -0
- package/_dist/audit.d.ts +15 -0
- package/_dist/audit.d.ts.map +1 -0
- package/_dist/bounce.d.ts +19 -0
- package/_dist/bounce.d.ts.map +1 -0
- package/_dist/bus.d.ts +8 -0
- package/_dist/bus.d.ts.map +1 -0
- package/_dist/cache.d.ts +45 -0
- package/_dist/cache.d.ts.map +1 -0
- package/_dist/child-notice.d.ts +6 -0
- package/_dist/child-notice.d.ts.map +1 -0
- package/_dist/children.d.ts +59 -0
- package/_dist/children.d.ts.map +1 -0
- package/_dist/cli.d.ts +8 -0
- package/_dist/cli.d.ts.map +1 -0
- package/_dist/comp.d.ts +9 -0
- package/_dist/comp.d.ts.map +1 -0
- package/_dist/compact.d.ts +19 -0
- package/_dist/compact.d.ts.map +1 -0
- package/_dist/conversation.d.ts +158 -0
- package/_dist/conversation.d.ts.map +1 -0
- package/_dist/cost.d.ts +13 -0
- package/_dist/cost.d.ts.map +1 -0
- package/_dist/deferred.d.ts +79 -0
- package/_dist/deferred.d.ts.map +1 -0
- package/_dist/ended.d.ts +27 -0
- package/_dist/ended.d.ts.map +1 -0
- package/_dist/files.d.ts +73 -0
- package/_dist/files.d.ts.map +1 -0
- package/_dist/fork.d.ts +23 -0
- package/_dist/fork.d.ts.map +1 -0
- package/_dist/graft.d.ts +33 -0
- package/_dist/graft.d.ts.map +1 -0
- package/_dist/graph.d.ts +14 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/handoff.d.ts +29 -0
- package/_dist/handoff.d.ts.map +1 -0
- package/_dist/imported.d.ts +63 -0
- package/_dist/imported.d.ts.map +1 -0
- package/_dist/intake.d.ts +43 -0
- package/_dist/intake.d.ts.map +1 -0
- package/_dist/joined.d.ts +35 -0
- package/_dist/joined.d.ts.map +1 -0
- package/_dist/lease.d.ts +21 -0
- package/_dist/lease.d.ts.map +1 -0
- package/_dist/lines.d.ts +13 -0
- package/_dist/lines.d.ts.map +1 -0
- package/_dist/mod.d.ts +107 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/naming.d.ts +10 -0
- package/_dist/naming.d.ts.map +1 -0
- package/_dist/native.d.ts +13 -0
- package/_dist/native.d.ts.map +1 -0
- package/_dist/parts.d.ts +145 -0
- package/_dist/parts.d.ts.map +1 -0
- package/_dist/plugin.d.ts +33 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/project.d.ts +67 -0
- package/_dist/project.d.ts.map +1 -0
- package/_dist/prose.d.ts +7 -0
- package/_dist/prose.d.ts.map +1 -0
- package/_dist/providers.d.ts +36 -0
- package/_dist/providers.d.ts.map +1 -0
- package/_dist/reach.d.ts +39 -0
- package/_dist/reach.d.ts.map +1 -0
- package/_dist/react.d.ts +236 -0
- package/_dist/react.d.ts.map +1 -0
- package/_dist/readers.d.ts +221 -0
- package/_dist/readers.d.ts.map +1 -0
- package/_dist/reap.d.ts +21 -0
- package/_dist/reap.d.ts.map +1 -0
- package/_dist/recall.d.ts +32 -0
- package/_dist/recall.d.ts.map +1 -0
- package/_dist/routes.d.ts +15 -0
- package/_dist/routes.d.ts.map +1 -0
- package/_dist/run.d.ts +81 -0
- package/_dist/run.d.ts.map +1 -0
- package/_dist/service.d.ts +131 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/source.d.ts +9 -0
- package/_dist/source.d.ts.map +1 -0
- package/_dist/start.d.ts +29 -0
- package/_dist/start.d.ts.map +1 -0
- package/_dist/state.d.ts +75 -0
- package/_dist/state.d.ts.map +1 -0
- package/_dist/status.d.ts +38 -0
- package/_dist/status.d.ts.map +1 -0
- package/_dist/tail.d.ts +121 -0
- package/_dist/tail.d.ts.map +1 -0
- package/_dist/timing.d.ts +9 -0
- package/_dist/timing.d.ts.map +1 -0
- package/_dist/told.d.ts +17 -0
- package/_dist/told.d.ts.map +1 -0
- package/_dist/tools.d.ts +41 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/transcript.d.ts +5 -0
- package/_dist/transcript.d.ts.map +1 -0
- package/_dist/turn.d.ts +49 -0
- package/_dist/turn.d.ts.map +1 -0
- package/_dist/unknown.d.ts +6 -0
- package/_dist/unknown.d.ts.map +1 -0
- package/_dist/views.d.ts +9 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +9 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/_dist/wait.d.ts +15 -0
- package/_dist/wait.d.ts.map +1 -0
- package/_dist/wake.d.ts +116 -0
- package/_dist/wake.d.ts.map +1 -0
- package/_dist/watch.d.ts +52 -0
- package/_dist/watch.d.ts.map +1 -0
- package/_dist/who.d.ts +84 -0
- package/_dist/who.d.ts.map +1 -0
- package/_dist/window.d.ts +43 -0
- package/_dist/window.d.ts.map +1 -0
- package/admission.js +137 -0
- package/admission.js.map +1 -0
- package/admission.ts +164 -0
- package/announce.js +123 -0
- package/announce.js.map +1 -0
- package/announce.ts +126 -0
- package/answer.js +372 -0
- package/answer.js.map +1 -0
- package/answer.ts +426 -0
- package/append.js +125 -0
- package/append.js.map +1 -0
- package/append.ts +205 -0
- package/archive.js +62 -0
- package/archive.js.map +1 -0
- package/archive.ts +62 -0
- package/asks.js +80 -0
- package/asks.js.map +1 -0
- package/asks.ts +106 -0
- package/attempt.js +46 -0
- package/attempt.js.map +1 -0
- package/attempt.ts +60 -0
- package/audit.js +57 -0
- package/audit.js.map +1 -0
- package/audit.ts +65 -0
- package/bounce.js +29 -0
- package/bounce.js.map +1 -0
- package/bounce.ts +34 -0
- package/bus.js +568 -0
- package/bus.js.map +1 -0
- package/bus.ts +683 -0
- package/cache.js +169 -0
- package/cache.js.map +1 -0
- package/cache.ts +230 -0
- package/child-notice.js +128 -0
- package/child-notice.js.map +1 -0
- package/child-notice.ts +136 -0
- package/children.js +937 -0
- package/children.js.map +1 -0
- package/children.ts +925 -0
- package/claude-control.js +8 -0
- package/claude-control.js.map +1 -0
- package/claude-control.ts +12 -0
- package/cli.js +23 -0
- package/cli.js.map +1 -0
- package/cli.ts +28 -0
- package/comp.js +76 -0
- package/comp.js.map +1 -0
- package/comp.ts +78 -0
- package/compact.js +157 -0
- package/compact.js.map +1 -0
- package/compact.ts +209 -0
- package/compact_ask.js +280 -0
- package/compact_ask.js.map +1 -0
- package/compact_ask.ts +199 -0
- package/continue.js +131 -0
- package/continue.js.map +1 -0
- package/continue.ts +143 -0
- package/conversation.js +337 -0
- package/conversation.js.map +1 -0
- package/conversation.ts +593 -0
- package/cost.js +111 -0
- package/cost.js.map +1 -0
- package/cost.ts +93 -0
- package/deferred.js +207 -0
- package/deferred.js.map +1 -0
- package/deferred.ts +219 -0
- package/deno.json +1 -0
- package/dependencies.js +114 -0
- package/dependencies.js.map +1 -0
- package/dependencies.ts +110 -0
- package/draining.js +20 -0
- package/draining.js.map +1 -0
- package/draining.ts +26 -0
- package/ended.js +210 -0
- package/ended.js.map +1 -0
- package/ended.ts +225 -0
- package/files.js +285 -0
- package/files.js.map +1 -0
- package/files.ts +318 -0
- package/fork.js +96 -0
- package/fork.js.map +1 -0
- package/fork.ts +124 -0
- package/graft.js +97 -0
- package/graft.js.map +1 -0
- package/graft.ts +88 -0
- package/graph.js +49 -0
- package/graph.js.map +1 -0
- package/graph.ts +61 -0
- package/handoff.js +111 -0
- package/handoff.js.map +1 -0
- package/handoff.ts +147 -0
- package/help.js +432 -0
- package/help.js.map +1 -0
- package/help.ts +431 -0
- package/hooks.js +253 -0
- package/hooks.js.map +1 -0
- package/hooks.ts +333 -0
- package/imported.js +259 -0
- package/imported.js.map +1 -0
- package/imported.ts +201 -0
- package/inspect.js +353 -0
- package/inspect.js.map +1 -0
- package/inspect.ts +378 -0
- package/intake.js +115 -0
- package/intake.js.map +1 -0
- package/intake.ts +124 -0
- package/joined.js +67 -0
- package/joined.js.map +1 -0
- package/joined.ts +69 -0
- package/lease.js +146 -0
- package/lease.js.map +1 -0
- package/lease.ts +151 -0
- package/lifecycle.js +49 -0
- package/lifecycle.js.map +1 -0
- package/lifecycle.ts +46 -0
- package/lines.js +171 -0
- package/lines.js.map +1 -0
- package/lines.ts +177 -0
- package/listen.js +604 -0
- package/listen.js.map +1 -0
- package/listen.ts +976 -0
- package/log.js +78 -0
- package/log.js.map +1 -0
- package/log.ts +88 -0
- package/mod.js +107 -0
- package/mod.js.map +1 -0
- package/mod.ts +113 -0
- package/name.js +51 -0
- package/name.js.map +1 -0
- package/name.ts +84 -0
- package/naming.js +96 -0
- package/naming.js.map +1 -0
- package/naming.ts +102 -0
- package/native.js +17 -0
- package/native.js.map +1 -0
- package/native.ts +17 -0
- package/package.json +133 -4
- package/parts.js +334 -0
- package/parts.js.map +1 -0
- package/parts.ts +383 -0
- package/plugin.js +77 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +98 -0
- package/project.js +354 -0
- package/project.js.map +1 -0
- package/project.ts +407 -0
- package/prompt.js +57 -0
- package/prompt.js.map +1 -0
- package/prompt.ts +92 -0
- package/prose.js +43 -0
- package/prose.js.map +1 -0
- package/prose.ts +63 -0
- package/providers.js +279 -0
- package/providers.js.map +1 -0
- package/providers.ts +306 -0
- package/pruning.js +80 -0
- package/pruning.js.map +1 -0
- package/pruning.ts +147 -0
- package/reach.js +923 -0
- package/reach.js.map +1 -0
- package/reach.ts +1107 -0
- package/react.js +2259 -0
- package/react.js.map +1 -0
- package/react.ts +2864 -0
- package/readers.js +956 -0
- package/readers.js.map +1 -0
- package/readers.ts +1017 -0
- package/reap.js +60 -0
- package/reap.js.map +1 -0
- package/reap.ts +65 -0
- package/recall.js +67 -0
- package/recall.js.map +1 -0
- package/recall.ts +114 -0
- package/reopen.js +45 -0
- package/reopen.js.map +1 -0
- package/reopen.ts +44 -0
- package/result-entry.js +32 -0
- package/result-entry.js.map +1 -0
- package/result-entry.ts +34 -0
- package/resume.js +266 -0
- package/resume.js.map +1 -0
- package/resume.ts +283 -0
- package/routes.js +129 -0
- package/routes.js.map +1 -0
- package/routes.ts +147 -0
- package/routine.js +179 -0
- package/routine.js.map +1 -0
- package/routine.ts +191 -0
- package/run.js +932 -0
- package/run.js.map +1 -0
- package/run.ts +999 -0
- package/service.js +806 -0
- package/service.js.map +1 -0
- package/service.ts +911 -0
- package/source.js +26 -0
- package/source.js.map +1 -0
- package/source.ts +40 -0
- package/start.js +197 -0
- package/start.js.map +1 -0
- package/start.ts +214 -0
- package/state.js +247 -0
- package/state.js.map +1 -0
- package/state.ts +404 -0
- package/status.js +1222 -0
- package/status.js.map +1 -0
- package/status.ts +1555 -0
- package/status_bench.ts +50 -0
- package/statusline.js +187 -0
- package/statusline.js.map +1 -0
- package/statusline.ts +232 -0
- package/tail.js +748 -0
- package/tail.js.map +1 -0
- package/tail.ts +815 -0
- package/talk.js +58 -0
- package/talk.js.map +1 -0
- package/talk.ts +51 -0
- package/task-context.js +41 -0
- package/task-context.js.map +1 -0
- package/task-context.ts +53 -0
- package/texted.js +65 -0
- package/texted.js.map +1 -0
- package/texted.ts +65 -0
- package/timing.js +37 -0
- package/timing.js.map +1 -0
- package/timing.ts +52 -0
- package/told.js +56 -0
- package/told.js.map +1 -0
- package/told.ts +54 -0
- package/tools.js +595 -0
- package/tools.js.map +1 -0
- package/tools.ts +633 -0
- package/transcript.js +34 -0
- package/transcript.js.map +1 -0
- package/transcript.ts +41 -0
- package/turn.js +47 -0
- package/turn.js.map +1 -0
- package/turn.ts +68 -0
- package/unknown.js +8 -0
- package/unknown.js.map +1 -0
- package/unknown.ts +9 -0
- package/views.js +15 -0
- package/views.js.map +1 -0
- package/views.ts +21 -0
- package/vocab.js +24 -0
- package/vocab.js.map +1 -0
- package/vocab.json +1573 -0
- package/vocab.ts +30 -0
- package/wait.js +30 -0
- package/wait.js.map +1 -0
- package/wait.ts +45 -0
- package/wake.js +552 -0
- package/wake.js.map +1 -0
- package/wake.ts +597 -0
- package/watch.js +520 -0
- package/watch.js.map +1 -0
- package/watch.ts +596 -0
- package/who.js +309 -0
- package/who.js.map +1 -0
- package/who.ts +347 -0
- package/window.js +179 -0
- package/window.js.map +1 -0
- package/window.ts +268 -0
- package/woken.js +129 -0
- package/woken.js.map +1 -0
- package/woken.ts +127 -0
package/README.md
CHANGED
|
@@ -1,3 +1,1393 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yaks/session
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@yaks/session` stores conversations as graph transcripts, derives their status,
|
|
4
|
+
manages claims, and runs model and tool turns. It does not start an
|
|
5
|
+
operating-system process.
|
|
6
|
+
|
|
7
|
+
<a id="install"></a>
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
deno add jsr:@yaks/session
|
|
11
|
+
# or: npx jsr add @yaks/session
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Prompt-cache observations
|
|
15
|
+
|
|
16
|
+
`yak session cache` reads request usage without keeping a second rollup. It
|
|
17
|
+
reports token-weighted cached share and separate groups for session, provider,
|
|
18
|
+
model and path. `--requests` adds each observation's id, time, counts and share.
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
yak session cache --until 2026-10-01T20:10:00Z
|
|
22
|
+
yak session cache --from 2026-10-01T20:10:00Z
|
|
23
|
+
yak session cache --from 2026-10-01T20:10:00Z \
|
|
24
|
+
--until 2026-10-02T00:00:00Z --session S-123 --requests
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Dates are ISO instants with a timezone, selected by request `created.at`. `from`
|
|
28
|
+
is inclusive and `until` exclusive: the two sides of the 20:10 UTC cut never
|
|
29
|
+
overlap. Without bounds, all observations are read. Undated observations appear
|
|
30
|
+
only in an unbounded report.
|
|
31
|
+
|
|
32
|
+
`cached_share` is `reported_cached_tokens / reported_input_tokens`, summed over
|
|
33
|
+
requests reporting both counts, not an average of request percentages. It is
|
|
34
|
+
null when that input denominator is zero. `input_tokens` and `cached_tokens` sum
|
|
35
|
+
all reported counts; the paired `reported_*` totals explain the share.
|
|
36
|
+
`unknown_cache_input_tokens`, `unknown_input_requests` and
|
|
37
|
+
`unknown_cache_requests` expose missing coverage; `zero_cache_requests` counts
|
|
38
|
+
explicitly reported zeros. Requests not yet reporting usage remain unknown.
|
|
39
|
+
Imported CLI entries can carry `ask{to, through}` too; `session{transcript}` on
|
|
40
|
+
their session still identifies them as imported. Imported entries can be
|
|
41
|
+
cumulative turn totals rather than individual requests. They are excluded from
|
|
42
|
+
`total` and the session, provider and model groups, so these never mix
|
|
43
|
+
cumulative imports with per-request usage. `imported_observations` counts the
|
|
44
|
+
excluded entries; `groups.path.imported` keeps their totals separately, and
|
|
45
|
+
`--requests` retains the individual observations. An endpoint that omits cached
|
|
46
|
+
usage (or reports null) is unknown, not a cache miss; it does not enter the
|
|
47
|
+
share denominator.
|
|
48
|
+
|
|
49
|
+
Paths come from existing provenance: a session without `session{source}` is
|
|
50
|
+
`native`; `session.source` → `call{source}` → `build{}` is `builder`; a source
|
|
51
|
+
call whose registered `tool{name}` or `call{name}` is `session_compact` is
|
|
52
|
+
`compaction`; another source is `other`. Usage-only entries are `imported`.
|
|
53
|
+
Provider and model names are resolved from their rows; missing identity is
|
|
54
|
+
`unknown`, not guessed from output text.
|
|
55
|
+
|
|
56
|
+
`cacheOf(rows, metadata, options)` is the pure reducer.
|
|
57
|
+
`cacheRead(graph,
|
|
58
|
+
options)` accepts only `read` and `get`, so an app-store
|
|
59
|
+
consumer can use the same report without a box-specific adapter. Both are
|
|
60
|
+
exported by `@yaks/session`; there is no second consumer needing aggregation in
|
|
61
|
+
`@yaks/model` yet.
|
|
62
|
+
|
|
63
|
+
## Storage model
|
|
64
|
+
|
|
65
|
+
<a id="the-transcript"></a>
|
|
66
|
+
|
|
67
|
+
A session entity has a `session` component. Each transcript entry is a separate
|
|
68
|
+
entity with `entry{session, seq}`. A **bundle** is one entity's components as a
|
|
69
|
+
JSON object. The components beside `entry` determine its type:
|
|
70
|
+
|
|
71
|
+
| Components | Meaning |
|
|
72
|
+
| ------------------------------------- | ------------------------------------------ |
|
|
73
|
+
| `content{body}` without `output` | input from a person or system |
|
|
74
|
+
| `ask{to, served, through}` | a request to a model, and what answered it |
|
|
75
|
+
| `content{body}` with `output{source}` | model output |
|
|
76
|
+
| `call{to, name, id, args, source}` | a tool call requested by a model |
|
|
77
|
+
| `result{call}` with `content` | a tool result |
|
|
78
|
+
| `heard` beside a result or report | what it brought, a stranger wrote |
|
|
79
|
+
| `using{provider, model, effort, …}` | model selection on an input or ask |
|
|
80
|
+
| `usage` and `cost` beside an ask | what the request used and cost |
|
|
81
|
+
| `questions{asked}` | typed questions for the next ask |
|
|
82
|
+
| `answer{question, …}` with `output` | a model's answer to one question |
|
|
83
|
+
| `stop` | no further transcript work |
|
|
84
|
+
| `refusal{code}` | an expected failure |
|
|
85
|
+
| `exception` | an unexpected failure |
|
|
86
|
+
|
|
87
|
+
`entry.seq` is assigned transactionally when omitted. `appendEntry()` is the
|
|
88
|
+
usual way to append text.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { graph } from '@yaks/graph'
|
|
92
|
+
import { modelDoc } from '@yaks/model'
|
|
93
|
+
import { ram } from '@yaks/ram'
|
|
94
|
+
import { appendEntry, sessionDoc, sessions } from '@yaks/session'
|
|
95
|
+
import { toolsDoc } from '@yaks/tools/vocab'
|
|
96
|
+
import { loadVocab } from '@yaks/vocab'
|
|
97
|
+
|
|
98
|
+
let vocab = loadVocab([sessionDoc, toolsDoc, modelDoc])
|
|
99
|
+
let g = graph({ storage: ram(vocab), vocab, plugins: [sessions()] })
|
|
100
|
+
await g.apply([{ entity: { eid: 'session' }, session: {} }])
|
|
101
|
+
|
|
102
|
+
await appendEntry(g, 'session', 'Please review this change')
|
|
103
|
+
await appendEntry(g, 'session', 'Build completed', {
|
|
104
|
+
eid: 'notice:build-123',
|
|
105
|
+
notice: true,
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Sending** is what goes to a model:
|
|
110
|
+
`sending{input, instructions, window, tools}`. It is selected independently of
|
|
111
|
+
`using{provider, model, effort}` on an input and recorded on each ask.
|
|
112
|
+
`sending.input` carries explicit model-native fields, such as lyrics or
|
|
113
|
+
duration, validated by the provider.
|
|
114
|
+
|
|
115
|
+
`sending.tools` names the tools a turn is offered: exactly those, found among
|
|
116
|
+
the runner's own and then among the ones it runs only for a turn that names them
|
|
117
|
+
(`Deps.named`, `offered()`); without it a turn gets the runner's own. Where no
|
|
118
|
+
input selected any, a host may name them for each ask (`Deps.resolveTools`: the
|
|
119
|
+
tools the transcript's persona contains), read when the instructions are and
|
|
120
|
+
recorded on the ask.
|
|
121
|
+
|
|
122
|
+
A tool marked `deferred` is offered without its schema: `tool_load` lists each
|
|
123
|
+
one by name and title, and the deferred tools a `tool_load` call names, or a
|
|
124
|
+
call to one, are sent from then on (./deferred.ts). A turn sends the deferred
|
|
125
|
+
tools the newest ask sent (its `sending.offer`) and those the entries since
|
|
126
|
+
load, so a turn anchored past the load, or windowed or summarized past it, still
|
|
127
|
+
sends them: the tools lead a provider's cached prefix, and a set that dropped
|
|
128
|
+
one would change all of it. A runner holding many tools sends the few most turns
|
|
129
|
+
use, and the rest cost a line each. A deferred tool runs whenever it is called;
|
|
130
|
+
only what is sent changes.
|
|
131
|
+
|
|
132
|
+
`sending.instructions` are the system instructions a turn is asked with (an ask
|
|
133
|
+
keeps its predecessor's while the prefix that one cached is unexpired,
|
|
134
|
+
`cachedInstructions`), and `sending.window` bounds what it sends: the newest
|
|
135
|
+
that many lines, reaching back to the input that began the turn they cut into,
|
|
136
|
+
so a long transcript costs a turn no more than a short one. A line is what a
|
|
137
|
+
model is sent (an input, a reply, a call, a result); the asks and errors kept
|
|
138
|
+
beside them are not lines, and neither are the typed questions other turns asked
|
|
139
|
+
or their answers. Without an explicit window, a long native transcript is
|
|
140
|
+
summarized into a checkpoint once the next request would fill `Deps.compactAt`
|
|
141
|
+
(half where absent, the same for every model) of its model's context window:
|
|
142
|
+
`model.context` on the model's row, else `provider.context` on its provider's,
|
|
143
|
+
else 128,000 tokens (./compact.ts). What it weighs is what the model holds: the
|
|
144
|
+
provider's count of the newest request since the checkpoint, which includes any
|
|
145
|
+
history an anchor kept there, plus the lines since. The summary replaces the
|
|
146
|
+
oldest lines and keeps the newest that fit half the limit, no more than the
|
|
147
|
+
summarizer's own window can read, and no checkpoint follows another within `GAP`
|
|
148
|
+
asks, so a window set too small summarizes every few steps, never every step.
|
|
149
|
+
The next turn reads that summary and the entries after its boundary. A provider
|
|
150
|
+
anchor before the checkpoint is not reused. A provider that no longer holds the
|
|
151
|
+
reply an anchor names (it expired) refuses with `UNANCHORED` (@yaks/model): the
|
|
152
|
+
ask ends interrupted with that code, and the next turn sends the whole
|
|
153
|
+
conversation once, so the ask answering it anchors the turns after. Every
|
|
154
|
+
request names its session as `Request.conversation`, so between checkpoints a
|
|
155
|
+
provider that keys its prompt cache by conversation reads the unchanged prefix
|
|
156
|
+
from it.
|
|
157
|
+
|
|
158
|
+
A session that wears `drops{}`, or whose persona does, shrinks without a
|
|
159
|
+
summary. It leaves out what it has replied past: each of its own calls with its
|
|
160
|
+
result, and each worker's report, that came before the request its newest reply
|
|
161
|
+
answered. That reply is what keeps what the session took from them. A worker's
|
|
162
|
+
report is the end of a child as its parent was told it (`delivery`), or what a
|
|
163
|
+
session it started wrote to it through the bus (`attention{worker}`). A person's
|
|
164
|
+
words and the session's own replies are never left out, a call still running
|
|
165
|
+
stays with every answer to it, and a fork leaves its parent's lines to its
|
|
166
|
+
parent. Leaving out is the `archived{}` mark, so no model is asked, the row
|
|
167
|
+
stays, and its result is still read by id (`result_query`). It happens at two
|
|
168
|
+
moments:
|
|
169
|
+
|
|
170
|
+
1. A request starts after the provider's cache of the one before has expired
|
|
171
|
+
(`cold`, from the ask's recorded `cache_expires_at`). The request pays for
|
|
172
|
+
its whole context either way, so the drop costs nothing. An ask whose
|
|
173
|
+
provider recorded no expiry is not cold.
|
|
174
|
+
2. A summary is due while the cache is warm. The drop is done first and costs
|
|
175
|
+
one cache write; the summary follows only if what is left still fills the
|
|
176
|
+
share.
|
|
177
|
+
|
|
178
|
+
A drop changes the archive marks, so the next request replays the conversation
|
|
179
|
+
with no provider anchor, and a checkpoint written before it no longer stands:
|
|
180
|
+
the words and replies it summarized are sent again.
|
|
181
|
+
|
|
182
|
+
A fork has `fork{from}` on its session entity. Its logical transcript contains
|
|
183
|
+
the parent transcript through the referenced entry, followed by its own entries.
|
|
184
|
+
Provider continuation data is stored as a provider-specific component on an ask
|
|
185
|
+
entry; for example, `@yaks/openai` stores `openai{response_id}`.
|
|
186
|
+
|
|
187
|
+
A model that takes over a conversation another harness ran (its newest model
|
|
188
|
+
selection or request was imported, `lines{file, start}`) is told so first:
|
|
189
|
+
`handoffOf(g, session)` is the note (`handoff`) saying what it ran on, that its
|
|
190
|
+
tool calls were that harness's own, and the files its calls named (`touched`). A
|
|
191
|
+
model whose window cannot hold the conversation reads it summarized, as any long
|
|
192
|
+
transcript is.
|
|
193
|
+
|
|
194
|
+
A fork reads its parent's lines where they are, so both live in one store. To
|
|
195
|
+
begin a session in another store with a transcript's lines,
|
|
196
|
+
`grafted(lines,
|
|
197
|
+
session)` gives the rows that write them as that session's first
|
|
198
|
+
entries: what was said, asked and answered, each reference between them naming
|
|
199
|
+
the copy, and nothing the provider or the original session kept for itself
|
|
200
|
+
(provider data, costs, prompts, archive marks). yaks.app begins a visitor's
|
|
201
|
+
conversation with a home-page demo's this way.
|
|
202
|
+
|
|
203
|
+
`spawned{parent, notice, quiet}` selects passive completion delivery. With
|
|
204
|
+
`notice: true`, `deliverChild(g, child, now)` writes one `notice{child}` entry
|
|
205
|
+
in the parent instead of waking it. A settled chat waits `quiet` milliseconds
|
|
206
|
+
after its latest input and for its helpers to finish; failure and stop close it
|
|
207
|
+
immediately. The return value is the quiet deadline the host should wake at, or
|
|
208
|
+
`undefined`. The receipt's `delivery{child, outcome, through}` records its last
|
|
209
|
+
covered entry. Delivery marks the child `completed{}`; a host clears that mark
|
|
210
|
+
when accepting another input and schedules only children without it. Continuing
|
|
211
|
+
the child refreshes that same notice after it closes again. A child that heard a
|
|
212
|
+
stranger (an entry of its own carries `heard`) reports `heard`, by receipt,
|
|
213
|
+
notice or `wait`, so its parent's host narrows the turn that reads it as it
|
|
214
|
+
would its own.
|
|
215
|
+
|
|
216
|
+
Helpers spawned by a passive child inherit `spawned.notice`, report to their
|
|
217
|
+
immediate parent, and their reports are included in that parent's closing
|
|
218
|
+
notice. Failures also send one passive notice to the main thread above that
|
|
219
|
+
chain. `noticeParent(g, child)` finds that thread;
|
|
220
|
+
`raiseNotice(g, child, body,
|
|
221
|
+
eid)` builds a passive notice bundle for
|
|
222
|
+
exceptional work needing it. `spawnChild(g, parent, {prompt, model?})` submits
|
|
223
|
+
helper work through the same admission path as the model's spawn tool, without
|
|
224
|
+
inventing a model call in the parent's transcript.
|
|
225
|
+
|
|
226
|
+
Session status is derived from entries rather than stored. `statusOf()` returns
|
|
227
|
+
`empty`, `pending`, `running`, `settled`, `stopped`, or `failed`.
|
|
228
|
+
`sessionDerived` exposes the corresponding `session.status` SQL-derived
|
|
229
|
+
property, and `statusComputed` the same rule for @yaks/ram's `computed`, so
|
|
230
|
+
`.session.status=running` answers alike in memory. A stop remains effective
|
|
231
|
+
until new input resumes the transcript; late model replies and tool results can
|
|
232
|
+
be recorded without admitting more work. An unanswered call from the newest
|
|
233
|
+
model request keeps a transcript `running` regardless of later entries.
|
|
234
|
+
Otherwise, input/result means `pending`, ask/call means `running`, output means
|
|
235
|
+
`settled`, stop means `stopped`, a provider's error beside an interrupted ask
|
|
236
|
+
means `pending` (the pool asks again), and exception, an error beside a
|
|
237
|
+
completed ask, three consecutive errors, or one error coded `limit` (`LIMIT`, a
|
|
238
|
+
request refused at a ceiling, which asking again would meet too) means `failed`.
|
|
239
|
+
No entries means `empty`. There is no separate `input` component.
|
|
240
|
+
|
|
241
|
+
Besides `session.ended`, one mark on the session's row bears on it: a session a
|
|
242
|
+
process of its own runs (@yaks/process `process` with no `exit` yet, as a
|
|
243
|
+
spawned CLI run wears) reads `running` where its entries say `pending`, since
|
|
244
|
+
that process owes the answer, not the runner. `marksOf(row)` reads both for
|
|
245
|
+
`statusOf(entries, marks)`.
|
|
246
|
+
|
|
247
|
+
A request's `cost{dollars, reported}` (@yaks/model) is written beside its
|
|
248
|
+
`usage`: the provider's own dollars where it reports them, and otherwise, in the
|
|
249
|
+
same transaction, the usage weighed at the `price` on the row of the model that
|
|
250
|
+
answered it (`weighing`, a precondition of `sessions()`). `session.cost` is
|
|
251
|
+
computed, never stored: the sum of its entries' `cost`, absent where none
|
|
252
|
+
records any. Whole session reads omit this transcript-wide sum; name
|
|
253
|
+
`session.cost` in a filter or `.fields=session.cost` to compute it.
|
|
254
|
+
`sessionCost` is its SQL, registered in `sessionDerived`.
|
|
255
|
+
|
|
256
|
+
Applications that run a session add components from other packages:
|
|
257
|
+
`process{pid, command, cwd}` and `exit{code}` describe its program;
|
|
258
|
+
`worktree{repository, path}` describes its checkout; `spawned{parent, call}`
|
|
259
|
+
describes delegation; and @yaks/file's `lines{file, start}` records the line of
|
|
260
|
+
the file an imported entry was read from. Start, latest-input, and finish times
|
|
261
|
+
are entry `created.at` values. The last `content` and `usage` record what the
|
|
262
|
+
run produced. Persona and role remain referenced entities.
|
|
263
|
+
|
|
264
|
+
`archived{at}` is the general `@yaks/kernel` visibility marker. Archiving a
|
|
265
|
+
session does not stop its runner, release claims, remove entries, or change
|
|
266
|
+
transcript status.
|
|
267
|
+
|
|
268
|
+
## Claims
|
|
269
|
+
|
|
270
|
+
<a id="a-lock-is-a-lease-not-a-patch"></a>
|
|
271
|
+
|
|
272
|
+
`claim{session}` is stored on the entity a session claims. A **batch** is a list
|
|
273
|
+
of bundles applied in one transaction. If a batch attempts to replace another
|
|
274
|
+
session's claim, the whole transaction fails with `Bounced`; the collision is
|
|
275
|
+
then recorded as `conflict{target, loser, holder, at}`: with `page` claimed by
|
|
276
|
+
`ada`, a batch holding `{ entity: { eid: page }, claim: { session: bo } }` fails
|
|
277
|
+
with `Bounced: <page> is already claimed by <ada>`.
|
|
278
|
+
|
|
279
|
+
Reclaiming with the same session is harmless. Set `claim: null` to release a
|
|
280
|
+
claim; release is unguarded so a caller can hand a claim over. The collision
|
|
281
|
+
check runs in the transaction's `precondition` phase, before cascades change
|
|
282
|
+
rows. After rollback, the `audit` phase records the conflict in a separate
|
|
283
|
+
transaction. Claims do not expire. Deleting a session releases its claims
|
|
284
|
+
through the graph cascade. `reapLeases(storage)` releases claims whose holder is
|
|
285
|
+
no longer a session; the `/service` duty runs it when it starts.
|
|
286
|
+
`endGone(graph, options)` (`@yaks/session/ended`), run hourly by the same duty,
|
|
287
|
+
writes `session.ended` on a session that is over, which is what makes a page of
|
|
288
|
+
live sessions a presence test (`.session !session.ended`). An outside harness's
|
|
289
|
+
session is over when its process is gone: Claude's by its running-process files,
|
|
290
|
+
where a subagent runs in its root session's process and also ends once its log
|
|
291
|
+
has been quiet for two hours, and Codex's by a fully imported log quiet for two
|
|
292
|
+
hours. A session with no transcript file is over once it has been quiet for two
|
|
293
|
+
hours, a day if its turn is unfinished; a claim keeps it while its turn is
|
|
294
|
+
unfinished or it is parked there (see below), and so does a wake still to fire
|
|
295
|
+
that reaches it (`awaited`, [Standing duties](#standing-duties)). The mark
|
|
296
|
+
leaves `updated` as it was. Input on the transcript, or a knock or letter
|
|
297
|
+
addressed to the session, clears it in the same batch, whatever door it came
|
|
298
|
+
through (`./reopen.ts`). What its entries leave unfinished then reads `stopped`;
|
|
299
|
+
settled, failed and empty keep reading that way. `session_release` frees what a
|
|
300
|
+
marked session held. `session_release` records work when a transcript ends or
|
|
301
|
+
receives a claim after ending, so a later worker releases those claims through
|
|
302
|
+
the ordinary queue. A managed run that ended cleanly keeps the claims it is
|
|
303
|
+
parked on (see below), and lets each go once its task finishes or nothing is
|
|
304
|
+
left to wait for.
|
|
305
|
+
|
|
306
|
+
## Parking on a task
|
|
307
|
+
|
|
308
|
+
A transcript is **parked** on a task when its run is over (a native transcript
|
|
309
|
+
has settled; a managed run's process exited 0 and nobody stopped it) while the
|
|
310
|
+
task it holds still waits on a dependency: a `requires` or `contains` edge to a
|
|
311
|
+
task that has not finished (`@yaks/task` `dependencies`). When a dependency
|
|
312
|
+
finishes, `session_wake` wakes every transcript parked on a task that waits on
|
|
313
|
+
it, the same way for both kinds: it appends an input carrying the `using` in
|
|
314
|
+
force, naming what finished. `session_run` answers that input for a provider a
|
|
315
|
+
host lent a model for, and `@yaks/spawn` answers it by running the command line
|
|
316
|
+
again on the provider's own thread. Deleting the link to a dependency that has
|
|
317
|
+
not finished wakes the transcript parked on the task it led from the same way
|
|
318
|
+
(`unlinked(graph, task, dep)`), read from the edge as the commit found it
|
|
319
|
+
(`@yaks/effects` `Event.before`).
|
|
320
|
+
|
|
321
|
+
Before parking, the transcript follows its unfinished dependency chains. It
|
|
322
|
+
claims unattended runnable leaves and receives an instruction to work them on
|
|
323
|
+
its existing provider. A resting worker that already holds a leaf receives the
|
|
324
|
+
instruction instead; a failed or missing worker's claim goes through
|
|
325
|
+
`session_release` first. Changes to claims and dependency links reconcile the
|
|
326
|
+
waiting ancestors, so losing a worker after parking resumes the work too.
|
|
327
|
+
Decisions, explicit outside blockers and tasks assigned to a person remain
|
|
328
|
+
external waits. A cycle, missing task or missing provider is reported to the
|
|
329
|
+
spawning session through a knock as soon as it is found; repairable dependency
|
|
330
|
+
problems also give the waiting transcript a turn to fix them.
|
|
331
|
+
|
|
332
|
+
News is a dependency that finished after the claim was taken, by somebody other
|
|
333
|
+
than the holder, or the link to an unfinished one going away. Each wake is named
|
|
334
|
+
for the transcript, the task and what it tells of, so the same news is told
|
|
335
|
+
once. A native turn settling or a managed run ending calls
|
|
336
|
+
`rouse(graph, session)`, so a dependency that finished while it ran is told at
|
|
337
|
+
once. `waits(graph, session, task)` says whether a held task still waits on
|
|
338
|
+
something the holder is to be woken for, `unanswered(graph, session)` lists what
|
|
339
|
+
a transcript was told that its last turn or run was not given, and
|
|
340
|
+
`told(graph, session)` everything it was told, for a run that never began.
|
|
341
|
+
`parkedLine(graph, session)` says where a parked transcript stands, for a
|
|
342
|
+
person. A wake records the task it woke its transcript for (`woken{task}`), so
|
|
343
|
+
`carrying(graph, task)` finds the transcript already on a task, its claim held
|
|
344
|
+
or let go, and `handing(graph, session, task, body)` gives it an instruction
|
|
345
|
+
instead of a second run starting (`@yaks/spawn`), on the provider, model and
|
|
346
|
+
account its last request named; a transcript never given one gets none.
|
|
347
|
+
@yaks/heal hands a session that is over the bug its work raised the same way.
|
|
348
|
+
|
|
349
|
+
When `x` finishes, a transcript parked on `y` which requires `x` receives that
|
|
350
|
+
news and a request for another turn, carrying its previous provider choice. The
|
|
351
|
+
complete executable scenario, including those exact assertions, is beside `wake`
|
|
352
|
+
in [`wake_test.ts`](./wake_test.ts).
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
import { wake } from '@yaks/session'
|
|
356
|
+
|
|
357
|
+
// await wake(graph, 'x') // what session_wake runs when x finishes
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## Running a transcript
|
|
361
|
+
|
|
362
|
+
<a id="when-something-runs-the-session"></a>
|
|
363
|
+
|
|
364
|
+
`react()` performs one required step: request a model response, run the next
|
|
365
|
+
tool call, or retry an error. `settle()` runs a transcript until it has nothing
|
|
366
|
+
more to do, under a lease named for it, so two processes never run one
|
|
367
|
+
transcript at once.
|
|
368
|
+
|
|
369
|
+
With a durable pool, each `session_run` effect performs one leased step. Inputs,
|
|
370
|
+
completed requests, context checkpoints and final tool results owe subsequent
|
|
371
|
+
steps in the transaction that records them. A run owed while this process is
|
|
372
|
+
already stepping the transcript joins that step, and the step's run owes one
|
|
373
|
+
more afterwards, unless the step wrote every change that joined it and left no
|
|
374
|
+
turn owed: a step's own reply wakes its transcript, and the step that wrote it
|
|
375
|
+
has answered that wake already. A run a stopping worker cuts short owes one more
|
|
376
|
+
too while its transcript owes a turn, or has ended and its end is not yet told
|
|
377
|
+
(a child's parent, its dispatch). A host that answers the words a turn took (a
|
|
378
|
+
reply sent back by text or mail) is told each time a pass finds a transcript
|
|
379
|
+
ended (`Runner.ended`), whether its step ended it or a stop was written while it
|
|
380
|
+
rested, and reads what to send with `answerOf(g, session)`: the reply in plain
|
|
381
|
+
words, a fault for its tracker where there was one, and the inputs the turn
|
|
382
|
+
answers, a helper's report standing for the words whose turn started it. A reply
|
|
383
|
+
said while newer words wait is told at once (`Runner.replied`), and read with
|
|
384
|
+
`answerOf(g, session, naming, true)`: the reply's own turn, the newer words
|
|
385
|
+
being the next one's, whether they were written before the reply or just after
|
|
386
|
+
it. `session_input` performs the same step for a new input that inherits
|
|
387
|
+
`using`, leaving an input that selects `using` to `session_run` so it owes only
|
|
388
|
+
one turn. Each `session_tool` effect claims and executes one call independently,
|
|
389
|
+
so several calls can run together. A background call (`tool_async`) is answered
|
|
390
|
+
by `PENDING` ("Pending; its result will follow."), which a request derives from
|
|
391
|
+
the call. A model turn starts while calls run only when there is something new
|
|
392
|
+
to read: an input, a result, or the Pending entry (`tool_progress`) a call is
|
|
393
|
+
given when it outlasts its patience (`PATIENCE`, 10 seconds; `Deps.patience`),
|
|
394
|
+
since a call that has run that long leaves other work worth doing. An input asks
|
|
395
|
+
at once; a result or a Pending waits until each call of its reply has answered
|
|
396
|
+
or outlasted its patience, since the model asked for them together. A call that
|
|
397
|
+
answers sooner costs two entries, the call and its result, and no turn of its
|
|
398
|
+
own. A tool that `waits` (on a process, a child, a task) is never given one: the
|
|
399
|
+
model chose to wait. Older transcripts hold a `tool_progress` entry beside every
|
|
400
|
+
background call, which still answers it.
|
|
401
|
+
|
|
402
|
+
A request carries each call's answer right after the reply's last call, in the
|
|
403
|
+
order of the calls, since many models pair a result with its call by position
|
|
404
|
+
rather than by id: its Pending where an earlier request sent one, else its
|
|
405
|
+
final. A final whose Pending was sent stays where it landed and names its call
|
|
406
|
+
by tool, id and arguments ("The pending shell call c1 {…} finished:"), as a
|
|
407
|
+
second output for the call on OpenAI and as a user line on providers that take
|
|
408
|
+
one output per call.
|
|
409
|
+
|
|
410
|
+
Any process working the `@yaks/effects` pool takes an owed step.
|
|
411
|
+
`running(g, runner)` is the handler a host registers, lent the models, tools and
|
|
412
|
+
limits it has; a transcript asking for a provider the host was lent nothing for,
|
|
413
|
+
such as a command line `@yaks/spawn` launches, is left to whoever answers it.
|
|
414
|
+
|
|
415
|
+
This complete example runs in memory with a local model function:
|
|
416
|
+
|
|
417
|
+
```ts
|
|
418
|
+
import { graph } from '@yaks/graph'
|
|
419
|
+
import { type Model, modelDoc } from '@yaks/model'
|
|
420
|
+
import { ram } from '@yaks/ram'
|
|
421
|
+
import { sessionDoc, sessions, settle, transcript } from '@yaks/session'
|
|
422
|
+
import { toolsDoc } from '@yaks/tools/vocab'
|
|
423
|
+
import { loadVocab } from '@yaks/vocab'
|
|
424
|
+
|
|
425
|
+
const vocab = loadVocab([sessionDoc, toolsDoc, modelDoc])
|
|
426
|
+
const g = graph({ storage: ram(vocab), vocab, plugins: [sessions()] })
|
|
427
|
+
const model: Model = async (request) => ({
|
|
428
|
+
id: crypto.randomUUID(),
|
|
429
|
+
model: request.model,
|
|
430
|
+
items: [{ kind: 'assistant', text: 'pong' }],
|
|
431
|
+
})
|
|
432
|
+
await g.apply([
|
|
433
|
+
{ entity: { eid: 'here' }, content: {} },
|
|
434
|
+
{ entity: { eid: '$provider' }, provider: { name: 'local' } },
|
|
435
|
+
{ entity: { eid: '$model' }, model: { name: 'example' } },
|
|
436
|
+
{ entity: { eid: 'session' }, session: {} },
|
|
437
|
+
{
|
|
438
|
+
entity: { eid: 'input' },
|
|
439
|
+
entry: { session: 'session' },
|
|
440
|
+
content: { body: 'Reply with pong' },
|
|
441
|
+
using: { provider: '$provider', model: '$model' },
|
|
442
|
+
},
|
|
443
|
+
])
|
|
444
|
+
await settle(g, 'session', { holder: 'here', model, tools: [] })
|
|
445
|
+
console.log(await transcript(g, 'session'))
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
Replace the local function with `responses({ credential })` from `@yaks/openai`
|
|
449
|
+
to use that provider; also load its `openaiDoc` vocabulary.
|
|
450
|
+
|
|
451
|
+
A host can lend an [executor](../model/README.md) through `Deps.executor`, or
|
|
452
|
+
return one as `Served.executor` from `resolveModel` for a selected provider. The
|
|
453
|
+
runner commits the original ask before `Executor.submit(call, request)`;
|
|
454
|
+
`request.call` and `call` name that ask. The executor freezes the request,
|
|
455
|
+
records `inference{executor, request, receipt}` on the ask, and dispatches the
|
|
456
|
+
same instance idempotently. The runner releases its lease while the receipt is
|
|
457
|
+
pending.
|
|
458
|
+
|
|
459
|
+
Model metadata is optional preparation, not a prerequisite for an ask.
|
|
460
|
+
`providerResolver` lists a provider's catalog only for a pending (unconfirmed)
|
|
461
|
+
model. A confirmed model with no price does not trigger another full listing:
|
|
462
|
+
some providers never publish prices. A provider with `info(name)` can still
|
|
463
|
+
supply per-model metadata. The runner's resolver shares in-flight discovery
|
|
464
|
+
across concurrent sessions and caches successful results (including missing
|
|
465
|
+
metadata) for five minutes. After a transient discovery failure it continues the
|
|
466
|
+
ask and cools down for at least a minute, or the error's longer retry delay. A
|
|
467
|
+
host can supply a fifth `report(error)` argument to observe exhausted metadata
|
|
468
|
+
discovery failures; permanent provider refusals still propagate. Provider
|
|
469
|
+
implementations own HTTP retry/backoff before that fallback. Its sixth argument
|
|
470
|
+
is the clock (@yaks/fp `Clock`, the runtime's by default) the cache expires by.
|
|
471
|
+
|
|
472
|
+
`providerResolver` accepts an executor factory as its fourth argument, keyed by
|
|
473
|
+
the selected provider's name. It prepares the provider's metadata and modalities
|
|
474
|
+
before submission and confirms the model on receipt. An executor's `available()`
|
|
475
|
+
returning false leaves new asks on the inline provider. Its `name` records
|
|
476
|
+
durable admission on the ask; older inline asks remain interrupted when a host
|
|
477
|
+
enables it.
|
|
478
|
+
|
|
479
|
+
On a later run, `Executor.resume(call)` reads the frozen request's outcome:
|
|
480
|
+
`undefined` leaves the ask pending, a reply completes the same ask, and a
|
|
481
|
+
terminal `ModelError` records its failure. A transport or receipt-read failure
|
|
482
|
+
is thrown for the effects pool to retry. Restart does not buy another response.
|
|
483
|
+
An ask committed before its request was frozen is dispatched under its original
|
|
484
|
+
id and transcript boundary. Changing `inference.receipt` owes `session_run` a
|
|
485
|
+
run; a receipt arriving while a lease is held is checked again when that lease
|
|
486
|
+
is released.
|
|
487
|
+
|
|
488
|
+
This example lends an executor through a provider selection. Its in-memory
|
|
489
|
+
methods illustrate the interface; a host supplies durable request storage,
|
|
490
|
+
idempotent submission, and receipt delivery behind them.
|
|
491
|
+
|
|
492
|
+
```ts
|
|
493
|
+
import { type Executor, type Model } from '@yaks/model'
|
|
494
|
+
import { type Served } from '@yaks/session'
|
|
495
|
+
import { equal } from '@yaks/testing'
|
|
496
|
+
|
|
497
|
+
let model: Model = async (request) => ({
|
|
498
|
+
id: 'reply',
|
|
499
|
+
model: request.model,
|
|
500
|
+
items: [],
|
|
501
|
+
})
|
|
502
|
+
let submitted: string[] = []
|
|
503
|
+
let executor: Executor = {
|
|
504
|
+
submit: async (call, request) => {
|
|
505
|
+
equal(request.call, call)
|
|
506
|
+
submitted.push(call)
|
|
507
|
+
},
|
|
508
|
+
resume: async () => undefined,
|
|
509
|
+
}
|
|
510
|
+
let served: Served = { name: 'example', model, executor }
|
|
511
|
+
await served.executor!.submit('ask-1', {
|
|
512
|
+
call: 'ask-1',
|
|
513
|
+
model: served.name,
|
|
514
|
+
items: [],
|
|
515
|
+
tools: [],
|
|
516
|
+
})
|
|
517
|
+
equal(submitted, ['ask-1'])
|
|
518
|
+
equal(await served.executor!.resume('ask-1'), undefined)
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
The hosted ask records its exact offered tool names in `sending.tools`, deferred
|
|
522
|
+
ones included. Returned tool calls keep those tools' stable graph identities,
|
|
523
|
+
and execution uses the source ask's offer even when a later input selects
|
|
524
|
+
different tools.
|
|
525
|
+
|
|
526
|
+
A provider refusal is recorded as `refusal{code}` with its
|
|
527
|
+
`response{body, headers}` beside it. A retryable request wears
|
|
528
|
+
`interrupted{code}` and `provisional{note}` while the effects pool still owes
|
|
529
|
+
another try. The pool gives it eight tries with backoff, resetting the tries
|
|
530
|
+
when a reply makes progress. A request not retried wears `failed{reason}`; new
|
|
531
|
+
input permits recovery without replaying completed tool operations.
|
|
532
|
+
|
|
533
|
+
An entry wearing `questions{asked}` (typed questions in Jev's terms, by name;
|
|
534
|
+
@yaks/model `Questions`) asks them with the next turn: the runner sends them as
|
|
535
|
+
`Request.questions`, and writes each of the reply's answers as its own entry,
|
|
536
|
+
`answer{question, noul, choice, score, confidence, probabilities}` with
|
|
537
|
+
`output{source}` naming the ask and a line saying it (`plan: forge, 0.82`), so a
|
|
538
|
+
person reading the transcript sees what was decided and a query can match
|
|
539
|
+
`.answer.question=plan&.answer.choice=forge`. A retry after an error asks them
|
|
540
|
+
again; a later turn does not, and reads neither them nor their answers: they are
|
|
541
|
+
rows for whoever asked, so a wake asking every few minutes never crowds the
|
|
542
|
+
conversation out of a window.
|
|
543
|
+
|
|
544
|
+
A streamed request is withdrawn by an entry carrying `cancel{target}` that names
|
|
545
|
+
its in-flight attempt: the run holding the transcript aborts it and records the
|
|
546
|
+
turn as interrupted. Models receive the abort through `Request.signal`; custom
|
|
547
|
+
models must observe it. Independent tool processes are not stopped.
|
|
548
|
+
|
|
549
|
+
Spawned children share one bound, `maxChildren`: a child waits
|
|
550
|
+
`dispatch.state: queued` until fewer than that many are `active`, and a child
|
|
551
|
+
waiting on its own children gives up its place while it waits.
|
|
552
|
+
|
|
553
|
+
The `wait` tool, like every wait here (`changes` in `@yaks/session/wait`), reads
|
|
554
|
+
again only once the store's revision has moved, on a beat that starts at 25 ms
|
|
555
|
+
and doubles to a second: a short wait answers about as soon as what it waits on
|
|
556
|
+
finishes, and a long one costs at most a read a second. Each read takes a task's
|
|
557
|
+
status marks (`statusComps` in @yaks/task) or a child's place and transcript
|
|
558
|
+
status, never a whole row.
|
|
559
|
+
|
|
560
|
+
<a id="recorded-tool-execution"></a>
|
|
561
|
+
|
|
562
|
+
Tool execution vocabulary belongs to `@yaks/tools`. The session loop builds a
|
|
563
|
+
runner for each step, executes transcript calls serially, and writes returned
|
|
564
|
+
text as `content{body}` plus `output{source}` beside a `result` entry with its
|
|
565
|
+
`call` and `ms` fields. A precommit rule adds `entry.session` to results before
|
|
566
|
+
sequence allocation. The general tool-runner plugin is not registered because
|
|
567
|
+
its effect-phase execution would race the session loop. A refused call is one
|
|
568
|
+
entry, its result carrying `refusal{code}` (the runner's `onResult`), and the
|
|
569
|
+
model reads it as that call's result. A tool answering `{text, with}` rather
|
|
570
|
+
than a string puts the components `with` names on its result entry beside its
|
|
571
|
+
words, so a host reading entries finds them there (an image it shows the model
|
|
572
|
+
beside the result). An unknown tool is handled by a refusing tool, producing
|
|
573
|
+
such a result. A durable `execution.state=running` without a result is not
|
|
574
|
+
replayed. On restart, a tool may recover its outcome from durable state;
|
|
575
|
+
otherwise the runner records an interrupted result so the model can inspect the
|
|
576
|
+
state before taking another action. The session then continues.
|
|
577
|
+
|
|
578
|
+
## Reading transcripts
|
|
579
|
+
|
|
580
|
+
<a id="bounded-transcript-reads"></a>
|
|
581
|
+
|
|
582
|
+
`transcript()` loads the full fork-aware history. A status, a runner step and a
|
|
583
|
+
tool snapshot read less: `reach()` returns the newest entries down to the oldest
|
|
584
|
+
one their decisions look at (the latest ask and the line it was sent through,
|
|
585
|
+
the turns a retry counts, the last stop, the newest checkpoint and what follows
|
|
586
|
+
it, the lines of a finite `sending.window`) and the older entries those name. It
|
|
587
|
+
answers `statusOf`, `openCalls`, `usingBefore`, `sendingBefore` and a model
|
|
588
|
+
turn's context as `transcript()` would, so a step costs the same on a short
|
|
589
|
+
transcript and a long one. A step running one call (`{ call: true }`) reads what
|
|
590
|
+
its tool reads of the turn, the prompts and the `using` and `sending` in force,
|
|
591
|
+
and no window: the turn sent that, not the call. A model turn (`{ turn: true }`)
|
|
592
|
+
reads on to its window only where the transcript is pending: one running its
|
|
593
|
+
calls, settled, stopped or failed is sent nothing, and its turn reads what a
|
|
594
|
+
call's does. What it looks for beyond those newest entries (the open calls, the
|
|
595
|
+
newest `using`, `sending` and stop) a graph remembers, and the next reading asks
|
|
596
|
+
only the lines appended since and the ones it found. So it does the lines of a
|
|
597
|
+
window below the newest page: the next reading asks them by name, which the
|
|
598
|
+
store answers from memory, and reads them without an ask's `attempt` or a call's
|
|
599
|
+
`execution`, which nothing decides by there. Where the model that answered the
|
|
600
|
+
newest ask can continue from it (`Model.anchor`), the turn is sent only the
|
|
601
|
+
lines after that ask, and reads no further back (`{ anchored }`); it reads the
|
|
602
|
+
prose of only the lines it sends. A turn that finds it cannot continue from that
|
|
603
|
+
ask after all (another model, an archive since, a summary due, a refused anchor)
|
|
604
|
+
is read again whole. A pending transcript with no checkpoint, anchor or window
|
|
605
|
+
is its own context, and its turn reads it all. A runner reads a step's
|
|
606
|
+
transcript once a pass (`reading()`): its checks before the step (a stop, a
|
|
607
|
+
cancelled task, an answered call) judge the reading that `react()` then acts on,
|
|
608
|
+
unless a line has landed since. `usingOf()` and `openOf()` ask for the model
|
|
609
|
+
selection in force and the calls no result answers alone, and so do
|
|
610
|
+
`entryStatus()` for the status, `newestOf()` for the newest line, `saidOf()` for
|
|
611
|
+
what a transcript said last, `firstInput()` for what it was first told,
|
|
612
|
+
`firstRequest()` and `latestRequest()` for the line a run was started with and
|
|
613
|
+
the one it goes on with, and `receiptOf()` for the stop that says a run ended.
|
|
614
|
+
`transcriptWindow()` reads a bounded page for user interfaces:
|
|
615
|
+
|
|
616
|
+
```ts
|
|
617
|
+
import { graph } from '@yaks/graph'
|
|
618
|
+
import { modelDoc } from '@yaks/model'
|
|
619
|
+
import { ram } from '@yaks/ram'
|
|
620
|
+
import { sessionDoc, sessions, transcriptWindow } from '@yaks/session'
|
|
621
|
+
import { toolsDoc } from '@yaks/tools/vocab'
|
|
622
|
+
import { loadVocab } from '@yaks/vocab'
|
|
623
|
+
|
|
624
|
+
let vocab = loadVocab([sessionDoc, toolsDoc, modelDoc])
|
|
625
|
+
let g = graph({ storage: ram(vocab), vocab, plugins: [sessions()] })
|
|
626
|
+
await g.apply([
|
|
627
|
+
{ entity: { eid: 'session' }, session: {} },
|
|
628
|
+
{ entity: { eid: 'hello' }, entry: { session: 'session' } },
|
|
629
|
+
])
|
|
630
|
+
|
|
631
|
+
const newest = await transcriptWindow(g, 'session', { limit: 64 })
|
|
632
|
+
const around = await transcriptWindow(g, 'session', { anchor: 'hello' })
|
|
633
|
+
const oldest = await transcriptWindow(g, 'session', { edge: 'start' })
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
The result is `{ entries, before, after, total, offset }`. Limits count entries,
|
|
637
|
+
are clamped to 1–256, and default to 64. `before` names an entry, a page's
|
|
638
|
+
first, for the page ending just before it, so a reader pages back to the start.
|
|
639
|
+
An unknown anchor or one outside the fork prefix selects the newest page. A fork
|
|
640
|
+
never includes parent entries written after its `fork.from` boundary.
|
|
641
|
+
`transcriptPlan()` returns ordinary bounded graph queries; it is not a
|
|
642
|
+
transactionally frozen snapshot, so subscriptions must refresh it when
|
|
643
|
+
membership changes. `transcriptSegments()` describes ancestor ranges, and
|
|
644
|
+
`transcriptUsage()` reads the latest usage without transcript text. `before` and
|
|
645
|
+
`after` indicate unloaded neighbors. Pages remain in logical transcript order. A
|
|
646
|
+
plan reads entry positions first, then limits body reads to the selected ranges;
|
|
647
|
+
it can be used with `@yaks/api` subscriptions.
|
|
648
|
+
|
|
649
|
+
## Harness hooks
|
|
650
|
+
|
|
651
|
+
The `./cli` facet answers `UserPromptSubmit` context from its local transcript
|
|
652
|
+
without opening the graph, so it cannot wait behind a graph writer. An empty or
|
|
653
|
+
malformed hook without a session is also a local no-op. Other lifecycle events
|
|
654
|
+
and `--json` delegate to the graph's tool runner.
|
|
655
|
+
|
|
656
|
+
`yak hooks install` writes lifecycle hooks into a Claude-compatible settings
|
|
657
|
+
file (default `~/.claude/settings.json`), replacing an earlier install and
|
|
658
|
+
leaving every other entry alone. A harness runs each hook with the event as JSON
|
|
659
|
+
on stdin. The hooks post to the `yak serve` of the graph's config (`server`,
|
|
660
|
+
default the config's `port` and `hostname`, else `http://127.0.0.1:8787`), and
|
|
661
|
+
the install also connects Claude Code to the graph through
|
|
662
|
+
`yak mcp --host <server>`. This local client expands opted-in `@path` arguments
|
|
663
|
+
before sending their values to `/mcp`; the HTTP server reads no caller-named
|
|
664
|
+
path. Start `yak serve` for the graph to answer the hooks and tool calls.
|
|
665
|
+
|
|
666
|
+
| Event | Command | Effect |
|
|
667
|
+
| --------------------------- | ------------------------------ | -------------------------------------------------------------------------------- |
|
|
668
|
+
| SessionStart, SubagentStart | `yak session context --hook -` | creates the session under the harness's id; prints its claims |
|
|
669
|
+
| UserPromptSubmit | `yak session context --hook -` | one timing line: prompt sent (or observed at hook time) and previous reply ended |
|
|
670
|
+
| SessionEnd | `yak session wrap --hook -` | releases the session's claims, except the task a managed run is parked on |
|
|
671
|
+
|
|
672
|
+
SessionStart, SubagentStart and SessionEnd first post their JSON input to
|
|
673
|
+
`POST /session/hook` using a small shell/curl command. The server runs the same
|
|
674
|
+
tool and renders the same answer as the CLI; start events return it in
|
|
675
|
+
`hookSpecificOutput.additionalContext`. A failed request (including a server
|
|
676
|
+
that is down) retries the command shown above with the original input. Partial
|
|
677
|
+
HTTP responses are discarded before retrying, and a failed fallback exits
|
|
678
|
+
successfully. Requests have a two-second limit and local connection attempts a
|
|
679
|
+
100 ms limit.
|
|
680
|
+
|
|
681
|
+
Claude Code's
|
|
682
|
+
[hook type support](https://code.claude.com/docs/en/hooks#prompt-based-hooks)
|
|
683
|
+
excludes SessionStart from HTTP hooks, though HTTP response JSON supports
|
|
684
|
+
additionalContext. Keeping a command wrapper also gives all three lifecycle
|
|
685
|
+
events their local fallback.
|
|
686
|
+
|
|
687
|
+
UserPromptSubmit reads `transcript_path` locally and prints plain stdout, which
|
|
688
|
+
Claude Code adds as context on exit 0. Its documented input has no sent
|
|
689
|
+
timestamp: a matching queued submission (or `prompt_id` already in the
|
|
690
|
+
transcript) supplies one; otherwise the line says **Prompt observed** at hook
|
|
691
|
+
time, not an invented send time. The previous reply uses a main-thread assistant
|
|
692
|
+
`end_turn` timestamp, never a tool call or a subagent. Reads are bounded to the
|
|
693
|
+
last 1 MiB; unavailable times say `unknown`. A missing/unreadable transcript or
|
|
694
|
+
unavailable graph means no context. The hook suppresses errors, exits
|
|
695
|
+
successfully and has a two-second ceiling; it never blocks a prompt. See Claude
|
|
696
|
+
Code's
|
|
697
|
+
[hook input and output reference](https://code.claude.com/docs/en/hooks#userpromptsubmit).
|
|
698
|
+
|
|
699
|
+
It also writes a PostToolUse HTTP hook posting each tool call to the server's
|
|
700
|
+
hook door, `POST /session/hook` (`@yaks/session/routes`; `server` names the
|
|
701
|
+
`yak serve`). A harness runs its subagents and forks under the session's own id,
|
|
702
|
+
and only the hook event says which context a call came from (Claude Code's
|
|
703
|
+
`agent_id`). So the door answers a call from the session's own line of work with
|
|
704
|
+
what the bus owes the session, as the context the harness adds after the call,
|
|
705
|
+
and a subagent's with nothing. The first event, a subagent's too, marks the
|
|
706
|
+
session `hooked{}`, and from then on the bus says nothing beside a tool reply to
|
|
707
|
+
it, since a tool call cannot say which context made it.
|
|
708
|
+
|
|
709
|
+
A Stop HTTP hook posts the end of each turn to the same door. A line owed then,
|
|
710
|
+
such as a person's comment written while the agent wrote its last answer, blocks
|
|
711
|
+
the stop (`decision: "block"`) with the lines as its reason, which the harness
|
|
712
|
+
gives the agent as its next turn; with nothing owed the turn ends. A `claude -p`
|
|
713
|
+
run would otherwise end without hearing it, and a comment on a task it holds is
|
|
714
|
+
said to nobody else.
|
|
715
|
+
|
|
716
|
+
A PreToolUse HTTP hook on MCP tools (`mcp__.*`) posts to the same door before
|
|
717
|
+
each call, which remembers the session or subagent making it under the call's
|
|
718
|
+
id, so the MCP door writes as that run (see "Identity and HTTP attribution").
|
|
719
|
+
|
|
720
|
+
The hook door speaks only after a tool call or at a turn's end, so an agent at
|
|
721
|
+
rest hears nothing there. To be woken, its own context runs the listener as a
|
|
722
|
+
background command that ends once it has said something; the harness then wakes
|
|
723
|
+
the agent with that output, and the agent runs it again:
|
|
724
|
+
|
|
725
|
+
```sh
|
|
726
|
+
yak session listen --session "$CLAUDE_CODE_SESSION_ID" --once
|
|
727
|
+
```
|
|
728
|
+
|
|
729
|
+
A wake costs the agent a read of its whole context, so one wake carries all that
|
|
730
|
+
is waiting. After each line the listener stays up through a quiet window
|
|
731
|
+
(`--quiet`, 5 seconds) and ends when nothing new came in it, at most six windows
|
|
732
|
+
after its first line. Each line is the item whole, so reading it takes no second
|
|
733
|
+
command, and a knock left at two addresses the session hears (itself and its
|
|
734
|
+
project) is one line.
|
|
735
|
+
|
|
736
|
+
A listened line counts as heard once printed, so the command's output goes
|
|
737
|
+
straight to the harness, never to a file another loop watches.
|
|
738
|
+
|
|
739
|
+
## The Claude Code plugin
|
|
740
|
+
|
|
741
|
+
`plugins/yak` packages the same hooks and the graph's MCP connection as a Claude
|
|
742
|
+
Code plugin, `yak@yak`, from the marketplace at the repository's root:
|
|
743
|
+
|
|
744
|
+
```sh
|
|
745
|
+
claude plugin marketplace add yak-sh/yak
|
|
746
|
+
claude plugin install yak@yak
|
|
747
|
+
yak hooks install
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
Its hooks are the ones above (`pluginHooks`), every one a command, since a
|
|
751
|
+
plugin's option reaches a command's environment (`CLAUDE_PLUGIN_OPTION_SERVER`)
|
|
752
|
+
and not an HTTP hook's URL. The option is the plugin's `server`, by default
|
|
753
|
+
`http://127.0.0.1:8787`. `yak hooks install` on an account that runs the plugin
|
|
754
|
+
sets it to this graph's server, takes out the hooks and MCP server an earlier
|
|
755
|
+
install wrote by hand, and writes the status line, which no plugin can.
|
|
756
|
+
|
|
757
|
+
**The status line.** Claude Code hands the line its session's model, context and
|
|
758
|
+
plan limits; the line posts them to `POST /session/status`
|
|
759
|
+
(`@yaks/session/statusline`), which keeps the limits as the account's
|
|
760
|
+
`rate_limit` rows, written only where a reading moved, and answers each plan's
|
|
761
|
+
room, this session's plan first:
|
|
762
|
+
|
|
763
|
+
```
|
|
764
|
+
Opus 5.5 ctx 42% │ claude-work 5h 8% (90m) · wk 60% │ codex wk 70%
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
A plan is an account, named by its directory; each window says what is left, and
|
|
768
|
+
when it resets where less than a tenth is. An install leaves a status line of
|
|
769
|
+
the person's own as it is.
|
|
770
|
+
|
|
771
|
+
**`/yak:continue`.** The prompt hook answers it before Claude Code asks its
|
|
772
|
+
model anything, so it works when that model's plan is spent: the door blocks the
|
|
773
|
+
prompt and Claude Code shows the answer (`@yaks/session/continue`).
|
|
774
|
+
|
|
775
|
+
| Typed | Does |
|
|
776
|
+
| ---------------------------------------- | ---------------------------------------------------------------------------------------------- |
|
|
777
|
+
| `/yak:continue [provider/]model [words]` | hands this conversation to that model in place (`session_send`), from the words or "Continue." |
|
|
778
|
+
| `/yak:continue S-12` | writes S-12 into this account for `/resume` (`session_open`) |
|
|
779
|
+
| `/yak:continue` | how to use it, and each plan's room |
|
|
780
|
+
|
|
781
|
+
**Opening a session in Claude Code.** `yak session open S-12 --in claude` writes
|
|
782
|
+
the session's conversation as Claude Code's own transcript, under the session's
|
|
783
|
+
id, so `claude --resume <id>` (or `/resume <id>`) continues it. Claude Code
|
|
784
|
+
resumes a transcript it did not write, other harnesses' tool calls included, as
|
|
785
|
+
long as each line has its shape. Into a file Claude Code already keeps of the
|
|
786
|
+
session goes only what was said since its last line; any other session gets a
|
|
787
|
+
new file in `cwd`'s projects holding all of it. The lines end with the note any
|
|
788
|
+
model gets when it takes over another harness's conversation. Each written line
|
|
789
|
+
names its entry (`yak.entry`), and the Claude Code reader skips such a line,
|
|
790
|
+
while what Claude Code appends after them is read into the same session. A
|
|
791
|
+
session another model took over here is still read from its Claude Code file:
|
|
792
|
+
only a run @yaks/spawn launched (`process`) is read from its own stream instead.
|
|
793
|
+
|
|
794
|
+
## Transcripts from outside
|
|
795
|
+
|
|
796
|
+
A session a harness runs outside this package's daemon is read into the graph
|
|
797
|
+
from the harness's own log, by one importer (`@yaks/session/tail`). A reader
|
|
798
|
+
(`claude`, `codex`, `codexRollout`, `grok`, `antigravity`) says what each line
|
|
799
|
+
of a format means, and `pull()` writes it: what a person typed (an input, signed
|
|
800
|
+
by them, and the session marked `operator`), what the harness put in front of
|
|
801
|
+
the model (`notice`), what the model said and thought, and each tool call with
|
|
802
|
+
its result. A call arrives held by the session (`execution{state, by}`), so no
|
|
803
|
+
tool runner here runs it again, and keeps the name it was called by
|
|
804
|
+
(`call.name`): a provider that continues the conversation is not served that
|
|
805
|
+
harness's tools. Tool arguments and output pass through `scrub()`, which redacts
|
|
806
|
+
the shapes a credential takes.
|
|
807
|
+
|
|
808
|
+
Each file read is a @yaks/file `file{path, root}` on the volume that holds it,
|
|
809
|
+
and every entry read from it wears the line it came from, `lines{file, start}`.
|
|
810
|
+
The file carries `transcript{session, consumed, version, finished}`, which says
|
|
811
|
+
how many of its lines have been read, which is where a resume starts: a line
|
|
812
|
+
that made no entry, or whose entries were deleted since, is not read again.
|
|
813
|
+
Entry IDs are derived from the session, the line and the place in it, so a line
|
|
814
|
+
read twice writes nothing new. A harness can write one session's id into two
|
|
815
|
+
files; the session's first file (`session.transcript`) keeps those IDs, and an
|
|
816
|
+
entry of any other file names that file's path too, so the two never collide.
|
|
817
|
+
Each entry is dated when the harness wrote it.
|
|
818
|
+
|
|
819
|
+
`@yaks/spawn` follows a managed run's stdout with it. The
|
|
820
|
+
`@yaks/session/service` duty follows Claude Code's transcript files,
|
|
821
|
+
`<project>/<session>.jsonl` under its projects directory, and Codex rollouts,
|
|
822
|
+
`YYYY/MM/DD/rollout-<date>-<thread>.jsonl` under its sessions directory: one
|
|
823
|
+
written to in the last `full` milliseconds is read as it grows, at full depth,
|
|
824
|
+
and an older one is read in lazily, one per pass, its prose and provider/model
|
|
825
|
+
selections. A look reserves its first bounded slice for the pending source least
|
|
826
|
+
recently read, including old backfill, so growing tails cannot starve other
|
|
827
|
+
files. Cold parents precede their subagents. The remaining budget reads open
|
|
828
|
+
tails least behind first, then unopened recent files newest first, each for a
|
|
829
|
+
slice (`SLICE`, 100 ms) until its budget (`BUDGET`, a second) is spent. It skips
|
|
830
|
+
a managed run, whose transcript asks a provider for it (`using{provider}`). A
|
|
831
|
+
subagent's transcript, `<session>/subagents/agent-<id>.jsonl`, is read the same
|
|
832
|
+
way (`subagent`, the reader whose lines are all side conversations) into a
|
|
833
|
+
session of its own: `session{id}` the agent id, its eid
|
|
834
|
+
`sessionEid(id, parent)`, and `spawned{parent, call}` naming the session that
|
|
835
|
+
started it and, from the `agent-<id>.meta.json` beside it, the call that did. A
|
|
836
|
+
Claude Code compaction summary becomes a checkpoint in the transcript; a native
|
|
837
|
+
continuation starts there.
|
|
838
|
+
|
|
839
|
+
Codex rollouts use `codexRollout`; managed `codex exec --json` output uses
|
|
840
|
+
`codex`. Rollouts keep each response item once, omitting its event notification
|
|
841
|
+
mirror. Injected instructions and inter-agent messages are notices, model prose
|
|
842
|
+
is output, and tool results name their calls by `call_id`. A child's thread UUID
|
|
843
|
+
stays its identity even when its rollout carries inherited metadata; it names
|
|
844
|
+
its parent with `spawned{parent}`. Imported model selections name the Codex CLI
|
|
845
|
+
provider through `using{provider, model, effort}`. The rollout file is the
|
|
846
|
+
source record. Compressed `.jsonl.zst` archives stream through the same
|
|
847
|
+
importer; `zstd` must be installed on the host. Each pull reads one decoded
|
|
848
|
+
chunk and shares the duty's time budget. `transcript{version, finished}` records
|
|
849
|
+
the source file's size and modification time and the version whose decoder
|
|
850
|
+
reached successful EOF. A restart resumes incomplete archives by skipping
|
|
851
|
+
consumed lines; completed unchanged archives do no decoding. Changed source
|
|
852
|
+
versions restart their cursor. Compressing a plain rollout makes another file,
|
|
853
|
+
`X.jsonl.zst` beside `X.jsonl`: the first tail on it takes over the plain file's
|
|
854
|
+
transcript, and the session's `session.transcript` where it named the plain
|
|
855
|
+
file, so reading resumes at the same line and entry identities hold. A failed
|
|
856
|
+
archive retries after a minute while the other files progress.
|
|
857
|
+
|
|
858
|
+
The Codex Mac app writes the same rollouts under the same `CODEX_HOME` as the
|
|
859
|
+
CLI, so its threads are read as the CLI's are.
|
|
860
|
+
|
|
861
|
+
Grok Build keeps each session's model history as
|
|
862
|
+
`<GROK_HOME>/sessions/<percent-encoded cwd>/<session>/chat_history.jsonl`, one
|
|
863
|
+
`{type, content}` row per line, read by `grok`. An assistant row names its model
|
|
864
|
+
(`model_id`) and its calls (`tool_calls`, each `{id, name, arguments}` with the
|
|
865
|
+
arguments a JSON string), and a `tool_result` names its call by `tool_call_id`.
|
|
866
|
+
Reasoning that is only `encrypted_content` is left out, and the rows carry no
|
|
867
|
+
time. The session's `updates.jsonl` streams the same turns as Agent Client
|
|
868
|
+
Protocol chunks; the history holds each message whole, so it is the one read.
|
|
869
|
+
|
|
870
|
+
The Antigravity CLI (`agy`) keeps each conversation's steps as
|
|
871
|
+
`~/.gemini/antigravity-cli/brain/<conversation>/.system_generated/logs/transcript_full.jsonl`
|
|
872
|
+
(`transcript.jsonl`, whose long fields are cut, where an older version kept only
|
|
873
|
+
that), one `{step_index, source, type, status, created_at, content}` per line,
|
|
874
|
+
read by `antigravity`. A `PLANNER_RESPONSE` carries the model's words, its
|
|
875
|
+
`thinking` and its calls (`tool_calls`, `{name, args}` with no id), and each
|
|
876
|
+
call's outcome is the `GENERIC` step after it, in call order. A call is named by
|
|
877
|
+
the step that answers it (`step-<n>`), and that step names its call too, so a
|
|
878
|
+
result always has the call it answers. The desktop app's `~/.gemini/antigravity`
|
|
879
|
+
is another layout, and is not read.
|
|
880
|
+
|
|
881
|
+
Both formats are copied from what others saw these CLIs write, not from a
|
|
882
|
+
published schema, and the fixtures in grok_antigravity_test.ts follow them: a
|
|
883
|
+
version that writes another shape reads as nothing, and the fix is the reader.
|
|
884
|
+
|
|
885
|
+
The duty scans sessions one at a time, starting another scan an hour after the
|
|
886
|
+
last finishes. `stale()` yields pages of at most 50 imported entry identities
|
|
887
|
+
from sessions whose newest entry is older than `full`, checking that age before
|
|
888
|
+
each page. `strip()` deletes one page between looks: calls, results, thoughts,
|
|
889
|
+
notices and a turn's ending go; what a person typed and what the model said
|
|
890
|
+
stay. Provider/model selections and compaction summaries stay too, so an older
|
|
891
|
+
transcript can still resume, and so does an entry that records what a turn cost,
|
|
892
|
+
since the session's cost is their sum.
|
|
893
|
+
|
|
894
|
+
| Option | Default | Meaning |
|
|
895
|
+
| ------- | ------- | ------------------------------------------------------- |
|
|
896
|
+
| `every` | `1000` | milliseconds between looks |
|
|
897
|
+
| `homes` | none | more account directories to read, beside the ones found |
|
|
898
|
+
| `find` | `true` | whether accounts are found on their own |
|
|
899
|
+
| `full` | 14 days | how long a session keeps its full depth |
|
|
900
|
+
|
|
901
|
+
An **account** is a directory a CLI keeps one sign-in and its transcripts in
|
|
902
|
+
(@yaks/model `ACCOUNTS`): Claude Code's `CLAUDE_CONFIG_DIR` (its `projects`),
|
|
903
|
+
Codex's `CODEX_HOME` and Grok's `GROK_HOME` (their `sessions`), and the
|
|
904
|
+
Antigravity CLI's `~/.gemini/antigravity-cli` (its `brain`). Someone with
|
|
905
|
+
several accounts keeps each in a directory of its own, so the duty reads every
|
|
906
|
+
account it finds (`homes` in ./files.ts): the ones `yak serve`'s environment
|
|
907
|
+
names, else `~/.claude`, `~/.codex`, `~/.grok` and `~/.gemini/antigravity-cli`;
|
|
908
|
+
every `~/.claude*`, `~/.codex*` and `~/.grok*` directory holding transcripts;
|
|
909
|
+
and each one the `homes` option lists, known by its name, else as Claude Code's
|
|
910
|
+
by its `projects`, Antigravity's by its `brain` and Codex's by its `sessions`.
|
|
911
|
+
They are found again as often as transcripts are listed. Each is an
|
|
912
|
+
`account{home, provider}` row (@yaks/model), and each transcript keeps its
|
|
913
|
+
account: a Codex rollout's plan readings are that account's `rate_limit` rows,
|
|
914
|
+
as are those a `claude -p` run reports in its stream (`rate_limit_event`), and
|
|
915
|
+
@yaks/spend bills a request to the account whose directory holds its transcript.
|
|
916
|
+
`moveThread(from, to, thread)` moves a thread's transcript into another
|
|
917
|
+
account's, at the same place, so the CLI signed in there carries it on.
|
|
918
|
+
|
|
919
|
+
## Identity and HTTP attribution
|
|
920
|
+
|
|
921
|
+
<a id="one-id-means-one-run"></a>
|
|
922
|
+
|
|
923
|
+
A session written under an alias with the harness's own id for it
|
|
924
|
+
(`session{id}`) is the entity `sessionEid(id)` names: the id itself where it is
|
|
925
|
+
a uuid, as Claude Code's session ids and Codex's thread ids are, and otherwise
|
|
926
|
+
an eid derived from it. Whoever holds a Claude session id can read that session
|
|
927
|
+
by it, and the hook and the importer that both create it land on one entity. A
|
|
928
|
+
managed run's session is written first under an eid of its own, which
|
|
929
|
+
`@yaks/spawn` hands Claude Code as its `--session-id`.
|
|
930
|
+
|
|
931
|
+
`sessionFor()` resolves an entity ID, a human-readable session ID, or a harness
|
|
932
|
+
session ID to the same entity. `speaking()` returns the actor a session writes
|
|
933
|
+
as: `by` the actor it works as (`actorOf()`), and `via` the session itself. The
|
|
934
|
+
actor is the session's persona, else the actor it names (`session.actor`), else
|
|
935
|
+
the project it is filed in, else whatever the session that spawned it works as,
|
|
936
|
+
so a subagent works as the persona it runs under. A session with no persona
|
|
937
|
+
anywhere up its line should be rare. A session is never an actor: one that works
|
|
938
|
+
as nobody leaves `by` unsaid.
|
|
939
|
+
|
|
940
|
+
`standIn()` (`@yaks/session/who`) keeps the session standing here for a
|
|
941
|
+
conversation held in another store and reached through a door such as a tunnel:
|
|
942
|
+
`session{door, persona, source}`, its eid derived from the door and the
|
|
943
|
+
conversation's id, so every request from one conversation speaks through one
|
|
944
|
+
session and none of them names one of this graph's own runs. It answers the
|
|
945
|
+
actor such a request writes as. That actor is the door's word, so a write
|
|
946
|
+
through a session holding `door` names nobody else as the one a mark is by: the
|
|
947
|
+
plugin's `authorize` hook (`attributing`) drops a `$decider` from it, and a
|
|
948
|
+
decision answered through a tunnel is `decided.by` the caller's persona, whoever
|
|
949
|
+
the answer named.
|
|
950
|
+
|
|
951
|
+
The `@yaks/session/graph` entry point exports `authenticate()`, for every door
|
|
952
|
+
over the graph: an HTTP request and a `yak` command alike. It reads the session
|
|
953
|
+
from the `x-via` header, else from a harness's tool call the hook door was told
|
|
954
|
+
about. Claude Code runs one MCP connection for a session and all its subagents,
|
|
955
|
+
so before each MCP tool call its `PreToolUse` hook posts the call's id with the
|
|
956
|
+
session and subagent making it, and the call itself carries that id in its
|
|
957
|
+
`_meta` (`claudecode/toolUseId`). A subagent the graph has not met is written
|
|
958
|
+
then, spawned by its session, and so is one the harness's `SubagentStart` hook
|
|
959
|
+
reports. The hook stores `announced{call, session}` in the graph, so the MCP
|
|
960
|
+
request keeps its caller across serving processes and restarts. The result's
|
|
961
|
+
hook removes the pairing; abandoned pairings stay until removed. Applications
|
|
962
|
+
enforce access separately.
|
|
963
|
+
|
|
964
|
+
<a id="appending-entries"></a>
|
|
965
|
+
|
|
966
|
+
Explicit sequence positions are supported for imports. Fractional and occupied
|
|
967
|
+
positions are rejected, while retrying an existing entry ID preserves its
|
|
968
|
+
position. Passive notices do not wake a settled session; the `notice` tool
|
|
969
|
+
appends them without requiring a sequence number. Direct `g.apply` calls can
|
|
970
|
+
also omit `entry.seq` when additional components are needed.
|
|
971
|
+
|
|
972
|
+
## Exports
|
|
973
|
+
|
|
974
|
+
The main module exports:
|
|
975
|
+
|
|
976
|
+
- vocabulary and constants: `sessionDoc`, `SESSION`, `CLAIM`, `CONFLICT`,
|
|
977
|
+
`ENTRY`, and the other transcript component names;
|
|
978
|
+
- graph integration: `sessions()`, `leasing()`, `naming`, `auditing()`,
|
|
979
|
+
`reapLeases()`, and `staleLeases()`;
|
|
980
|
+
- execution: `react()`, `settle()`, `running()`, `admitNext()`, `transcript()`,
|
|
981
|
+
`sessionTools()`, and the provider lookups `offers()`, `providerResolver()`
|
|
982
|
+
and `answers()`;
|
|
983
|
+
- parking: `wake()`, `unlinked()`, `rouse()`, `waits()`, `unanswered()`,
|
|
984
|
+
`told()`, `requested()`, `resting()` and `cleanEnd()`;
|
|
985
|
+
- inspection: `statusOf()`, `kindOf()`, `textOf()`, `ordered()`,
|
|
986
|
+
`sessionDerived`, `statusComputed`, and the bounded transcript functions;
|
|
987
|
+
- identity and rendering: `sessionFor()`, `sessionEid()`, `speaking()`,
|
|
988
|
+
`where()`, and `sessionViews`, the portable transcript renderers;
|
|
989
|
+
- harness readers: `claude`, `subagent`, `codex`, `codexRollout`, `readers`, and
|
|
990
|
+
`scrub()`;
|
|
991
|
+
- error types including `Bounced`, `Unnamed`, and `UnknownSession`.
|
|
992
|
+
|
|
993
|
+
Additional entry points are `@yaks/session/vocab`, `/graph` (with
|
|
994
|
+
`authenticate`), `/tools`, `/cli` (local context hooks), `/views`, `/service`
|
|
995
|
+
(the duty that reads transcripts), `/tail` (the importer) and `/transcript`
|
|
996
|
+
(`transcript()` alone, for a reader that runs no session). `/views` is `views`,
|
|
997
|
+
the portable renderers; `joined`, which entries make the lines of a conversation
|
|
998
|
+
(a result joins the call it answers); `conversationKinds`, loaded when asked
|
|
999
|
+
for; `conversationViews`, a session's `Conversation` view, which asks for its
|
|
1000
|
+
entries, draws each line by those kinds and hands them to @yaks/ux's
|
|
1001
|
+
`Conversation`, which follows its reader; and `inspectViews`, how the inspector
|
|
1002
|
+
(@yaks/inspect) draws an entry and a session: an entry as a turn of its
|
|
1003
|
+
conversation (`Inspect.Turn`), the turns either side of it
|
|
1004
|
+
(`Inspect.Conversation`, what a belief citing the entry shows), the entry's page
|
|
1005
|
+
inside its conversation, and a session's page with its status, brief and latest
|
|
1006
|
+
turns.
|
|
1007
|
+
|
|
1008
|
+
`/conversation` draws a conversation's lines with @yaks/ui: a person's words, a
|
|
1009
|
+
reply, a tool call as one step that opens on what it asked for and what came
|
|
1010
|
+
back, a failure, and a stop, with the files that came with a line: `files`, each
|
|
1011
|
+
a `Filed` (a picture as itself, any other file as its kind, name and size, with
|
|
1012
|
+
a remove button where a box holds it to send). Each is a `Kind`, a
|
|
1013
|
+
`Conversation.Line` registration (@yaks/render) that matches on which components
|
|
1014
|
+
an entry wears, so it selects the same under any vocabulary.
|
|
1015
|
+
`draw(registry, entry, beside)` draws an entry by the most specific kind, and a
|
|
1016
|
+
kind that returns `undefined` passes the entry to the next best. A host with
|
|
1017
|
+
rows of its own puts its kinds ahead of `kinds` in its own registry; the
|
|
1018
|
+
Operator's chat on yaks.app does (workers/yak/operator-draw.ts). A **host** is
|
|
1019
|
+
the process that opened the graph; effects and tools receive its graph and,
|
|
1020
|
+
where needed, its process entity ID.
|
|
1021
|
+
|
|
1022
|
+
<a id="what-is-deliberately-not-here"></a>
|
|
1023
|
+
<a id="compatibility"></a>
|
|
1024
|
+
|
|
1025
|
+
The main package runs in Deno, Node, browsers, and Cloudflare Workers. Process
|
|
1026
|
+
execution belongs to `@yaks/process`; command-line agent execution belongs to
|
|
1027
|
+
`@yaks/spawn`.
|
|
1028
|
+
|
|
1029
|
+
## Watching a task
|
|
1030
|
+
|
|
1031
|
+
A task's watchers hear it change. They are the session that filed it, each
|
|
1032
|
+
session whose own entries mention its id (what it said or was told; a tool's
|
|
1033
|
+
result is what it read), the writer of any task, comment or letter whose body
|
|
1034
|
+
mentions it, and each actor a `subscription` (@yaks/notify) has watching it; an
|
|
1035
|
+
actor muting it hears nothing. When the task is completed, cancelled or
|
|
1036
|
+
answered, or someone comments on it, `session_watch` knocks each watcher once:
|
|
1037
|
+
|
|
1038
|
+
```text
|
|
1039
|
+
knock K-9 at S-4: T-8 completed by Jeff: Give the Worker a token
|
|
1040
|
+
```
|
|
1041
|
+
|
|
1042
|
+
A knock about a comment carries the comment's words whole, so its reader needs
|
|
1043
|
+
no second command to read it.
|
|
1044
|
+
|
|
1045
|
+
A watcher's session is knocked while it can hear. Once it is over, the knock
|
|
1046
|
+
goes to its project's operator (the live session a person opened for that
|
|
1047
|
+
project or for one it is filed under, the one that spoke last), else to the
|
|
1048
|
+
project. A person's comment, which reaches the filer and the holder as a comment
|
|
1049
|
+
already, knocks neither of them. His comment on an open task that is not blocked
|
|
1050
|
+
is taken up by a session at work on it
|
|
1051
|
+
([a comment starts a session](#a-comment-starts-a-session)), so a watcher that
|
|
1052
|
+
is over passes that knock to nobody: the operator is not asked to relay it.
|
|
1053
|
+
|
|
1054
|
+
A writer is never knocked about its own write, and its subagents write for it: a
|
|
1055
|
+
subagent runs inside its parent's process and hands back what it did as the
|
|
1056
|
+
result of the parent's own call, so a change written through one knocks no
|
|
1057
|
+
session up its line (`writers`). A helper writes in its operator's place
|
|
1058
|
+
([an operator's helper](#an-operators-helper)), so what it writes knocks neither
|
|
1059
|
+
that operator nor the project it helps or one filed under it: such a knock would
|
|
1060
|
+
be routine, and start the next helper on the work the first one just did.
|
|
1061
|
+
|
|
1062
|
+
A mark that names nobody who made it, no `by` and no `via`, records an act in
|
|
1063
|
+
another store at that store's time: @yaks/heal closes a bug's task with the
|
|
1064
|
+
tracker's resolution or archival. That store tells of the act (the bug's
|
|
1065
|
+
letters, and its fixer's own report), so the mark knocks nobody.
|
|
1066
|
+
|
|
1067
|
+
One event is one knock. A managed run that ends leaves its whole report as a
|
|
1068
|
+
comment on its task that knocks whoever started it, or the nearest session up
|
|
1069
|
+
that one's line once it is over (`reported`, which @yaks/spawn's completion
|
|
1070
|
+
writes by). The session that receipt knocks is knocked neither for the comment a
|
|
1071
|
+
second time nor for the run completing or cancelling the task a little earlier.
|
|
1072
|
+
The receipt is said with where the task stands:
|
|
1073
|
+
|
|
1074
|
+
```text
|
|
1075
|
+
knock K-12 on T-8 (done) from S-6: S-6 — exited 0 Landed 3f9f64d. The Worker has its token.
|
|
1076
|
+
```
|
|
1077
|
+
|
|
1078
|
+
`knocks(graph, eid)` returns the knocks a change owes, and
|
|
1079
|
+
[`watch_test.ts`](./watch_test.ts) runs each case through the effect. A knock
|
|
1080
|
+
says whose act it tells in `knock.from` (@yaks/notify): the actor who finished
|
|
1081
|
+
the task or wrote the comment.
|
|
1082
|
+
|
|
1083
|
+
## An operator's helper
|
|
1084
|
+
|
|
1085
|
+
An operator's session carries its whole context, and waking it costs a read of
|
|
1086
|
+
all of it. A project wearing `helper{persona, provider, model, effort}` has what
|
|
1087
|
+
is addressed to its operator taken by a **helper** instead: a session of its own
|
|
1088
|
+
wearing `persona`, whose context holds only what was waiting.
|
|
1089
|
+
|
|
1090
|
+
**Routine** is what is addressed to the operator and is not the operator's own:
|
|
1091
|
+
|
|
1092
|
+
| Addressed to the operator | The operator's own, never routine |
|
|
1093
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
1094
|
+
| a knock at the project, at a project filed under it at any depth, or at a session a person opened (`session.operator`) wearing a persona homed there | a person's act or words: `knock.from`, else the knock's writer, wears `person`; a letter's `mail.from` is a person's `email.address` |
|
|
1095
|
+
| a letter that arrived for one of those projects or for an address filed under one, unless it answers a letter another session wrote that is not over (that session hears the answer) | a hand-up: a knock written through a helper's session, or through a session opened on a topic (`session.topic`) |
|
|
1096
|
+
|
|
1097
|
+
The rule runs in the write that leaves the knock or letter (`routing`, a
|
|
1098
|
+
`precondition` hook in [`routine.ts`](./routine.ts)) and marks a routine one
|
|
1099
|
+
`routine{project}`. No listener says a marked item to any session, so the
|
|
1100
|
+
operator's session is woken only by a person's mail, comment, text or answer, a
|
|
1101
|
+
hand-up, or a progress knock from a worker it started. A worker's knock about a
|
|
1102
|
+
task goes to its parent directly. An exit report carries a comment on the task
|
|
1103
|
+
and goes through the helper.
|
|
1104
|
+
|
|
1105
|
+
`session_help` runs after that commit ([`help.ts`](./help.ts)). When no helper
|
|
1106
|
+
of the project is at work, it writes one session, `helping{project}` and
|
|
1107
|
+
`native{}`, wearing the helper's persona. Its first input says whose place it
|
|
1108
|
+
takes and how to hand up, then each waiting item whole, as a listener would say
|
|
1109
|
+
it. The same write marks each item `notified`, `via` the helper. That input
|
|
1110
|
+
carries `using{provider, model, effort}`, and the native harness answers it:
|
|
1111
|
+
outside words (a letter anyone could send) reach a helper, so it runs isolated,
|
|
1112
|
+
with reads and `session_handup` in place of the box's shell and keys
|
|
1113
|
+
([@yaks/harness](../harness/README.md#sessions-outside-words-start)), never
|
|
1114
|
+
under an outside CLI. It carries no `spawned` link, so its ending is told by
|
|
1115
|
+
this rule and not delivered to the operator as a child's. How each kind of item
|
|
1116
|
+
is handled is the persona's to say.
|
|
1117
|
+
|
|
1118
|
+
One helper is at work at a time, and it takes everything waiting, so a storm of
|
|
1119
|
+
bugs is one helper's batch. What arrives while it works waits for its end, which
|
|
1120
|
+
asks again: a managed helper's `exit`, or a native one's transcript settling,
|
|
1121
|
+
failing or stopping. Two workers that race to start one hold a waiting item in
|
|
1122
|
+
common, and the guard on its `notified` lets one write through.
|
|
1123
|
+
|
|
1124
|
+
A helper hands up what needs the operator's judgment or a person with
|
|
1125
|
+
`yak session handup <id> "<one line>"` (`session_handup`): a knock at the
|
|
1126
|
+
operator written through the helper, which the rule leaves unmarked. The knock
|
|
1127
|
+
names the entity it concerns in `knock.about`, and its line starts with that
|
|
1128
|
+
entity's id. With no operator's session able to hear, it waits at the project
|
|
1129
|
+
for the next one a person opens.
|
|
1130
|
+
|
|
1131
|
+
The session that stays on a topic (see Standing duties) is no helper, and hands
|
|
1132
|
+
up with the same tool: its project is the home of the persona it wears. That
|
|
1133
|
+
knock is all of its writing that reaches another session. Such sessions do not
|
|
1134
|
+
message each other or the operator, and what needs a person is a decision or a
|
|
1135
|
+
task assigned to them, not a hand-up. The same line from any other session is an
|
|
1136
|
+
ordinary knock at the operator, and so routine.
|
|
1137
|
+
|
|
1138
|
+
Two more hand-ups are written for a helper, each naming what it had taken: a
|
|
1139
|
+
helper that exited with anything but 0 or whose transcript failed, and one the
|
|
1140
|
+
next routine item asks to stop before starting another, because its transcript
|
|
1141
|
+
gained no entry for 5 minutes (`QUIET`) or it was still going after 30
|
|
1142
|
+
(`LIMIT`). That hand-up carries the helper's last words. A run that has said its
|
|
1143
|
+
last words can linger for good on a background command it started, and
|
|
1144
|
+
everything behind it would wait. A helper's own ending knocks nobody
|
|
1145
|
+
(`reported`), and a run it started that ends after it knocks the operator, where
|
|
1146
|
+
it is routine again.
|
|
1147
|
+
|
|
1148
|
+
A run's ending and a task's mark are routine to read, not to hear of. When a
|
|
1149
|
+
helper exits, each task it took an exited run's report or a mark for reaches the
|
|
1150
|
+
session that was knocked (else the operator) as one line: the task, its verdict
|
|
1151
|
+
as the helper leaves it, and the report's id, as in
|
|
1152
|
+
`T-12 done: Fix the gate (report #054d79a6d0)`. The verdict is `done` or
|
|
1153
|
+
`cancelled` from the task's status, `stopped` for a run somebody asked to stop
|
|
1154
|
+
(`session_stop`), `ended early` for one that otherwise did not exit 0, and
|
|
1155
|
+
otherwise `not ready`. A stopped run's report says so before its exit code, as
|
|
1156
|
+
in `S-6 — asked to stop, exited 143`: its signal is the stop it was asked for,
|
|
1157
|
+
not a crash, and nothing restarts it. A comment on a task is talk, not a change,
|
|
1158
|
+
and stays the helper's: its knock's `about` is the comment, a mark's the task.
|
|
1159
|
+
|
|
1160
|
+
The helpers' trail is one query, newest first:
|
|
1161
|
+
|
|
1162
|
+
```sh
|
|
1163
|
+
yak graph query '.helping.project=P-1&.order=-created.at&.limit=20&.fields=created.at,session.status,exit.code,brief.text'
|
|
1164
|
+
```
|
|
1165
|
+
|
|
1166
|
+
`yak session peek <helper>` reads one, `.created.via=<helper>` lists what it
|
|
1167
|
+
wrote, and `.routine&.notified.via=<helper>` what it took. Removing `helper`
|
|
1168
|
+
from the project gives what is still waiting back to the operator.
|
|
1169
|
+
[`help_test.ts`](./help_test.ts) runs each case through the rule and the effect.
|
|
1170
|
+
|
|
1171
|
+
## Texts back
|
|
1172
|
+
|
|
1173
|
+
A text that arrives (@yaks/phone's `text`) from a number a session texted knocks
|
|
1174
|
+
that session while it can hear, else its project's operator, else the project,
|
|
1175
|
+
as a watcher's knock is routed. A text from a number no session texted goes the
|
|
1176
|
+
same way to the project the number it reached is filed under (`filed.project` on
|
|
1177
|
+
the entity wearing that `phone{number}`). `session_texted` knocks once per text
|
|
1178
|
+
([`texted_test.ts`](./texted_test.ts)), and the knock names the entity wearing
|
|
1179
|
+
the sender's number in `knock.from`, so a person's text is never a helper's.
|
|
1180
|
+
|
|
1181
|
+
## Standing duties
|
|
1182
|
+
|
|
1183
|
+
A standing duty is a wake aimed at who is to do it (@yaks/wake's
|
|
1184
|
+
`wake{every, target, note}`, written by `wake_new`). Each time the box's clock
|
|
1185
|
+
fires it, `session_woken` knocks once with the note
|
|
1186
|
+
([`woken_test.ts`](./woken_test.ts)). For a cron schedule, the knock includes
|
|
1187
|
+
the weekday and date of the firing in the schedule's time zone.
|
|
1188
|
+
|
|
1189
|
+
- **Aimed at a persona**, it knocks the persona's operator, else its project,
|
|
1190
|
+
where the knock waits for the next session at work. TaskMaster's morning
|
|
1191
|
+
standup is
|
|
1192
|
+
`wake{every: '0 7 * * * America/Detroit', target: <TaskMaster>, note}`, the
|
|
1193
|
+
owner's morning in his time zone.
|
|
1194
|
+
- **Aimed at a topic**, it knocks the session opened on that topic
|
|
1195
|
+
(`session.topic`, [@yaks/topic](../topic)) that has not ended or stopped, the
|
|
1196
|
+
one opened first where several have not (`attending`). One whose last turn
|
|
1197
|
+
failed still attends: a failed transcript hears what is said to it by name, a
|
|
1198
|
+
knock at it or a letter delivered to it, and that opens its next turn. A goal
|
|
1199
|
+
or a project that is its own topic is aimed at directly. Such a session is
|
|
1200
|
+
opened by an agent, so it is no operator, and with no session opened on the
|
|
1201
|
+
topic nobody is knocked.
|
|
1202
|
+
|
|
1203
|
+
A wake still to fire keeps the session it reaches from being marked over
|
|
1204
|
+
(`awaited`, below), so a session that stays on a topic rests between daily turns
|
|
1205
|
+
and is still the one its wake finds, while a run that once answered a question
|
|
1206
|
+
about the topic ends after its two quiet hours.
|
|
1207
|
+
|
|
1208
|
+
## A comment starts a session
|
|
1209
|
+
|
|
1210
|
+
A person's comment on an open task that no live session holds starts a session
|
|
1211
|
+
on that task, with the comment as its first input. The person is whoever
|
|
1212
|
+
`created.by` names, wearing `person`, writing through no session.
|
|
1213
|
+
|
|
1214
|
+
Whether a start is owed is settled in the comment's own commit, by the match
|
|
1215
|
+
`session_start` declares in the vocabulary: the comment is not yet said to
|
|
1216
|
+
anyone, and its task is open, not `blocked{on, since}`, and unclaimed or claimed
|
|
1217
|
+
by a session with `session.ended`. An agent's comment owes none. A comment
|
|
1218
|
+
committed before the effect was declared owes none either, and nothing looks
|
|
1219
|
+
back for one.
|
|
1220
|
+
|
|
1221
|
+
The run is one write, guarded by what the commit saw: the session
|
|
1222
|
+
(`session{persona, source, operator: false}`, `native{}`, `filed{project}`), its
|
|
1223
|
+
claim on the task, the input that asks its model for a turn, and `notified` on
|
|
1224
|
+
the comment. A comment someone heard meanwhile, or a task closed, blocked or
|
|
1225
|
+
taken meanwhile, starts nothing. `session.source` names the comment. The input
|
|
1226
|
+
is the bus's line for the comment, then a request to reply first with a comment
|
|
1227
|
+
on the task, so its writer sees it was picked up.
|
|
1228
|
+
|
|
1229
|
+
From that write on the task is held, so his next comment reaches the same
|
|
1230
|
+
session as an input ([claimed-work comments](#claimed-work-comments)) and owes
|
|
1231
|
+
no second start. Such a comment is for the session at work and nobody else: it
|
|
1232
|
+
does not follow the session that filed the task, and it is not held for the
|
|
1233
|
+
project.
|
|
1234
|
+
|
|
1235
|
+
At most two sessions started this way are at work (mid-turn) at once; the host
|
|
1236
|
+
sets the number (`starting`'s `limit`, the harness plugin's `starts`). A start
|
|
1237
|
+
past it keeps its run and waits in the pool, asking again every ten seconds. The
|
|
1238
|
+
host also says what a session on a task opens with (`opening`): the harness
|
|
1239
|
+
gives the common persona of the task's lineage, and the model the task's project
|
|
1240
|
+
says its work runs on, `using{provider, model}` on the project, or its own
|
|
1241
|
+
default model where the project names none. [`start_test.ts`](./start_test.ts)
|
|
1242
|
+
runs each case through the commit, the pool and the bus.
|
|
1243
|
+
|
|
1244
|
+
## Claimed-work comments
|
|
1245
|
+
|
|
1246
|
+
A person's comment on a record a session holds a claim on reaches that session:
|
|
1247
|
+
a native transcript gets it as an input, once, and an outside harness hears it
|
|
1248
|
+
from `yak session listen`, at its hook door, or beside its next tool reply. A
|
|
1249
|
+
person's comment is one whose own `created.via` is not a session.
|
|
1250
|
+
|
|
1251
|
+
An agent's comment on a claimed record reaches an outside session only, never a
|
|
1252
|
+
native transcript, which its inputs wake for a model turn. A comment at a
|
|
1253
|
+
session itself stays a message in its thread, and no bus delivers it.
|
|
1254
|
+
|
|
1255
|
+
```sh
|
|
1256
|
+
yak claim take <task> --session <outside-session>
|
|
1257
|
+
yak session listen --session <outside-session>
|
|
1258
|
+
```
|
|
1259
|
+
|
|
1260
|
+
A native transcript is recognized by a `using` entry and no `process`.
|
|
1261
|
+
|
|
1262
|
+
## Words given from outside
|
|
1263
|
+
|
|
1264
|
+
A person's words that reach a session by a page, a channel or a conversation
|
|
1265
|
+
tool are its next input, taken in by `take` (`@yaks/session/intake`). The input
|
|
1266
|
+
says the item they came in (`intake{item}`, a request or letter), the channel
|
|
1267
|
+
they came by and the framing said before them (`channel{name,
|
|
1268
|
+
framing}`), and
|
|
1269
|
+
the model chosen to answer them (`using`). The files sent with them are attached
|
|
1270
|
+
to that item (`attachment{message}`, @yaks/blob). Words named by an item, or by
|
|
1271
|
+
an id the caller gives them, are taken in once: given again, even at the same
|
|
1272
|
+
moment, they write nothing, and neither does what the host writes beside them.
|
|
1273
|
+
`conversation_start` and `conversation_send` (@yaks/harness) give theirs this
|
|
1274
|
+
way, as yaks.app's Operator gives a person's requests.
|
|
1275
|
+
|
|
1276
|
+
## Whose turn it is
|
|
1277
|
+
|
|
1278
|
+
Whether a turn is the listener's is decided the same way for every channel, a
|
|
1279
|
+
group text, a chat room or a call (`@yaks/session/turn`). A channel says only
|
|
1280
|
+
whether the words were said where others hear them and whether they were said to
|
|
1281
|
+
the listener; `named(text, names)` tells it for a channel without mentions.
|
|
1282
|
+
`cue({group, to})` is what the listener is told before them: in a group,
|
|
1283
|
+
everyone reads its answer, and it answers only when the words are for it and
|
|
1284
|
+
their speaker is done. Otherwise it answers `PASS` alone, which is kept in its
|
|
1285
|
+
transcript and sent nowhere (`passes(text)`). A pause is not a turn.
|
|
1286
|
+
|
|
1287
|
+
## When the bus looks
|
|
1288
|
+
|
|
1289
|
+
The `@yaks/session/service` duty follows the graph's commits, its own and,
|
|
1290
|
+
through the host's feed, every other process's (`follow` in
|
|
1291
|
+
[`bus.ts`](./bus.ts)). A pass asks about what was written since the last one: a
|
|
1292
|
+
written item alone, and a transcript entry's own session, which may have come to
|
|
1293
|
+
work and so hear what its project holds. A claim, a session, a persona, a
|
|
1294
|
+
process or a filing written asks about everything again, as the first pass does.
|
|
1295
|
+
A quiet graph costs the bus no read. A host with no feed asks about everything
|
|
1296
|
+
every second.
|
|
1297
|
+
|
|
1298
|
+
A native transcript answers its inputs with a model turn that reads its whole
|
|
1299
|
+
context, so everything waiting for one is taken in one turn, as one wake of
|
|
1300
|
+
`yak session listen --once` carries all that is waiting. What a session is owed
|
|
1301
|
+
waits through the same quiet window (`QUIET` in [`listen.ts`](./listen.ts), 5
|
|
1302
|
+
seconds; the duty's `quiet` option): it is said once nothing new was written for
|
|
1303
|
+
that session in a window, at most six windows after the oldest of it, counted
|
|
1304
|
+
from when each item was written (`ripe` in [`bus.ts`](./bus.ts)). So an item
|
|
1305
|
+
that waited longer, held for a project or unheard through a restart, is said at
|
|
1306
|
+
once. A session's lines are written in one batch, in the order their items were
|
|
1307
|
+
written (`give`): one input for each item, one wake and one turn for them all.
|
|
1308
|
+
An item another session was given meanwhile is left out of the batch.
|
|
1309
|
+
|
|
1310
|
+
The doors an outside session hears at (its hook and its tool replies) follow the
|
|
1311
|
+
same commits through a ledger (`ledger` in [`bus.ts`](./bus.ts)): the unsaid
|
|
1312
|
+
person-written comments and replies, by the creator of what each answers, and
|
|
1313
|
+
the graph's projects, by the project each is filed under. Its first use reads
|
|
1314
|
+
them all once; after that a door reads again only what was written since its
|
|
1315
|
+
last use and what its own session is owed, never the unsaid history, and reads
|
|
1316
|
+
the projects again only after a commit writes one. A host with no feed reads
|
|
1317
|
+
everything at each door.
|
|
1318
|
+
|
|
1319
|
+
## Replies to a session's letters
|
|
1320
|
+
|
|
1321
|
+
A letter answering one a session wrote (`mail.reply_to` naming a letter whose
|
|
1322
|
+
`created.via` is that session) is that session's: a native transcript gets it as
|
|
1323
|
+
input, and an outside harness hears it from `yak session listen`, at its hook
|
|
1324
|
+
door, or beside its next tool reply when it has no hook, once. The reply reaches
|
|
1325
|
+
the session wherever the far side sent it, to the session's own address or to
|
|
1326
|
+
its project's. While that session may still hear it, the reply waits for it
|
|
1327
|
+
unmarked, and a session resumed under the same id hears it then.
|
|
1328
|
+
|
|
1329
|
+
Once the session that wrote the letter is over (its harness ended it, or its
|
|
1330
|
+
transcript stopped or failed), a reply sent to a project is held for that
|
|
1331
|
+
project: the next session of the project hears it, the same way and once. A
|
|
1332
|
+
session's projects are the home of the persona it wears (`session.persona`,
|
|
1333
|
+
@yaks/persona's `persona.home`) and every project filed under that home, at any
|
|
1334
|
+
depth. A session that chose none wears the persona of the checkout it starts in:
|
|
1335
|
+
its start hook says the directory, and `session_context` records the common
|
|
1336
|
+
persona of the checkout holding it (@yaks/persona's `carried`), the one its
|
|
1337
|
+
instruction files say. A session wearing no persona hears only its own replies.
|
|
1338
|
+
A letter sent with `mail send --about <project>` goes out from the project's
|
|
1339
|
+
address, so its answer is routed to the project (@yaks/mail). An entity wears
|
|
1340
|
+
one address, so a project's other addresses are filed under it: a letter to an
|
|
1341
|
+
entity wearing `email` with `filed.project` naming the project (hello@yaks.app,
|
|
1342
|
+
filed under the platform's project) is held for the project the same way. Such a
|
|
1343
|
+
letter is also filed as a task on the project's board (@yaks/mail `mail_task`),
|
|
1344
|
+
so it stays in sight until it is answered after a session has heard it.
|
|
1345
|
+
|
|
1346
|
+
What is held for a project a person operates goes to its operator alone. A
|
|
1347
|
+
project is operated when a session a person opened (`session.operator`) wears a
|
|
1348
|
+
persona homed at it or at a project it is filed under, as TaskMaster's is. The
|
|
1349
|
+
agents it starts wear the same persona and hear only what is addressed to them,
|
|
1350
|
+
so the platform's feedback reaches TaskMaster rather than whichever agent calls
|
|
1351
|
+
a tool first. While no operator can hear, the item stays held, and the next
|
|
1352
|
+
session a person opens for the project hears it. Only a project nobody has ever
|
|
1353
|
+
operated gives what is held for it to any session that works for it. A mark said
|
|
1354
|
+
at the hook door or beside a tool reply names the session that heard it as
|
|
1355
|
+
`notified.via`, as `yak session listen` does.
|
|
1356
|
+
|
|
1357
|
+
The next session is one at work. An outside session hears what is held on its
|
|
1358
|
+
own calls; a native transcript hears it only mid-turn (`pending` or `running`).
|
|
1359
|
+
One settled between turns hears only what is addressed to it, since a settled
|
|
1360
|
+
transcript is never over and would otherwise wake for every alert its project
|
|
1361
|
+
ever gets.
|
|
1362
|
+
|
|
1363
|
+
Nothing starts a session for a held reply; it waits for one. A managed spawn in
|
|
1364
|
+
the project's checkout, with the thread as its brief and the project's common
|
|
1365
|
+
persona, is where that will plug in (./listen.ts), once sessions may be started
|
|
1366
|
+
again (T-95308) and its provider, model and spend are chosen.
|
|
1367
|
+
|
|
1368
|
+
### Prompt context
|
|
1369
|
+
|
|
1370
|
+
Each prompt the harness submits reaches `POST /session/hook`, which answers with
|
|
1371
|
+
the prompt's timing from the local transcript and, beside it,
|
|
1372
|
+
[what its person said before](../memory/README.md#earlier-words-beside-a-prompt)
|
|
1373
|
+
on the same subject: the configured `person`'s nearest earlier words, memories
|
|
1374
|
+
and answered decisions, a line each. The recall gets `wait` ms (700 by default,
|
|
1375
|
+
a plugin option); a slower one is left out of that prompt's context. With the
|
|
1376
|
+
server down, `yak session context --hook -` prints the timing alone.
|
|
1377
|
+
Session-start context is independent.
|
|
1378
|
+
|
|
1379
|
+
The person's words reach an agent through other doors too, and the same recall
|
|
1380
|
+
(`recall` in [`recall.ts`](./recall.ts)) rides under each: a comment or letter
|
|
1381
|
+
of theirs that the bus owes a session, said at the hook door, beside a tool
|
|
1382
|
+
reply or as a native transcript's input, and the comment a session is started
|
|
1383
|
+
on. Its subject is the item's words, and only what the person said before the
|
|
1384
|
+
item was written is recalled. An item anyone else wrote arrives alone.
|
|
1385
|
+
`yak session listen` prints one line an item and adds nothing to it.
|
|
1386
|
+
|
|
1387
|
+
### Request context
|
|
1388
|
+
|
|
1389
|
+
A runner projects explicit transcript inputs, admitted instructions and
|
|
1390
|
+
source-bound media into model requests. `requestItems` supplies dynamic context
|
|
1391
|
+
such as the available skill catalogue. Sending a request does not retrieve
|
|
1392
|
+
historical quotations. Stored `input_context{items}` snapshots remain
|
|
1393
|
+
inspectable and are excluded from model requests.
|