portable-agent-layer 0.118.0 → 0.119.0-canary.2

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.
@@ -265,6 +265,18 @@
265
265
  "name": "cost",
266
266
  "summary": "What each month was paid against its API-equivalent cost, per agent"
267
267
  },
268
+ {
269
+ "name": "context",
270
+ "summary": "What PAL adds to an agent's context per session, largest first",
271
+ "options": [
272
+ {
273
+ "name": "days",
274
+ "type": "string",
275
+ "value": "<n>",
276
+ "description": "How many days back to read (default 30)"
277
+ }
278
+ ]
279
+ },
268
280
  {
269
281
  "name": "wrapped",
270
282
  "summary": "A year of your work in numbers, read from the event log",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "portable-agent-layer",
3
- "version": "0.118.0",
3
+ "version": "0.119.0-canary.2",
4
4
  "description": "PAL — Portable Agent Layer: persistent personal context for AI coding assistants",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,266 @@
1
+ /** The fields each bronze event type may carry; anything else is dropped before it is written. */
2
+
3
+ export const USAGE_FIELDS = [
4
+ "inputTokens",
5
+ "outputTokens",
6
+ "cacheWrite5m",
7
+ "cacheWrite1h",
8
+ "cacheRead",
9
+ "thinkingTokens",
10
+ "costUsd",
11
+ ] as const;
12
+
13
+ export const EVENT_FIELDS = {
14
+ turn: [
15
+ "hour",
16
+ "weekday",
17
+ "words",
18
+ "gapSec",
19
+ "afterBreak",
20
+ "skimmed",
21
+ "interrupted",
22
+ "repeated",
23
+ "corrected",
24
+ "reply",
25
+ "reaction",
26
+ "reactionRules",
27
+ "mood",
28
+ "hinted",
29
+ "complied",
30
+ "language",
31
+ "pastedChars",
32
+ "images",
33
+ "command",
34
+ "backAfterSec",
35
+ ],
36
+ reply: [
37
+ "words",
38
+ "listItems",
39
+ "headings",
40
+ "asked",
41
+ "mode",
42
+ "latencySec",
43
+ "turn",
44
+ "narrationBlocks",
45
+ "thinkingBlocks",
46
+ ],
47
+ session_start: [
48
+ "source",
49
+ "model",
50
+ "effort",
51
+ "entrypoint",
52
+ "branch",
53
+ "palVersion",
54
+ "tz",
55
+ "utcOffsetMin",
56
+ ],
57
+ session_end: ["reason", "durationSec", "turns", "messages", "status"],
58
+ sync: ["pushed", "pulled", "written", "quarantined", "refused"],
59
+ sync_account: ["action", "store"],
60
+ actor_adopted: ["from", "to"],
61
+ upstream_report: ["action", "report", "leaks", "via"],
62
+ doctor_run: ["failing", "warnings"],
63
+ pal_bug_signal: ["trigger", "surface", "verdict"],
64
+ compaction: ["trigger", "withInstructions", "contextTokens"],
65
+ context_injected: ["instructionsChars", "semiStaticChars", "dynamicChars"],
66
+ hook_timing: ["hook", "totalMs", "handlers"],
67
+ inference_call: [
68
+ "caller",
69
+ "route",
70
+ "model",
71
+ "tier",
72
+ "web",
73
+ "latencyMs",
74
+ "failure",
75
+ ...USAGE_FIELDS,
76
+ ],
77
+ judge_call: [
78
+ "caller",
79
+ "mode",
80
+ "route",
81
+ "provider",
82
+ "model",
83
+ "inputTokens",
84
+ "costUsd",
85
+ "latencyMs",
86
+ "failure",
87
+ "systemOneAnswers",
88
+ "fallbackAnswers",
89
+ ],
90
+ pal_update: ["outcome", "from", "to", "durationSec", "skipReason"],
91
+ memory_move: [
92
+ "migration",
93
+ "outcome",
94
+ "entries",
95
+ "files",
96
+ "bytes",
97
+ "manifest",
98
+ "reason",
99
+ "hashTotal",
100
+ "archive",
101
+ "lines",
102
+ "kept",
103
+ "differ",
104
+ ],
105
+ migration_run: [
106
+ "migration",
107
+ "outcome",
108
+ "migrated",
109
+ "skipped",
110
+ "dryRun",
111
+ "undo",
112
+ "sweep",
113
+ ],
114
+ pal_heartbeat: ["outcome", "payload", "status", "skipReason"],
115
+ commitment: ["iscProject", "isc", "outcome", "surface", "snoozeDays"],
116
+ ticket: ["iscProject", "ticket", "status", "at", "since", "was"],
117
+ entity_first_seen: ["domain", "entityType"],
118
+ discord_nag: ["stage", "kind", "responseSec"],
119
+ model_call: [
120
+ "billing",
121
+ "plan",
122
+ "extraUsage",
123
+ "model",
124
+ "requestedModel",
125
+ "provider",
126
+ "inputTokens",
127
+ "outputTokens",
128
+ "cacheWrite5m",
129
+ "cacheWrite1h",
130
+ "cacheRead",
131
+ "thinkingTokens",
132
+ "thinkingMs",
133
+ "webSearches",
134
+ "webFetches",
135
+ "serviceTier",
136
+ "speed",
137
+ "effort",
138
+ "stopReason",
139
+ "entrypoint",
140
+ "sidechain",
141
+ "costUsd",
142
+ "agent",
143
+ "mode",
144
+ "durationMs",
145
+ "ttftMs",
146
+ "aiu",
147
+ "initiator",
148
+ "host",
149
+ ],
150
+ conversation: ["steps", "status", "depth", "subagent", "killed"],
151
+ commit: [
152
+ "hash",
153
+ "committedAt",
154
+ "files",
155
+ "added",
156
+ "deleted",
157
+ "commitType",
158
+ "breaking",
159
+ "revert",
160
+ "merge",
161
+ "tags",
162
+ "coAuthors",
163
+ "aiCoAuthored",
164
+ ],
165
+ rating: ["rating", "source"],
166
+ forgotten: ["target", "undone"],
167
+ project: ["change", "status"],
168
+ setting: ["key", "change"],
169
+ rule_decision: ["rule", "decision"],
170
+ calibration_label: ["deck", "item", "answer"],
171
+ decision: ["words"],
172
+ promise: ["change", "dueInSec", "lateSec", "snoozes", "nags"],
173
+ action: [
174
+ "tool",
175
+ "outcome",
176
+ "fileExt",
177
+ "change",
178
+ "linesAdded",
179
+ "linesRemoved",
180
+ "beforeBytes",
181
+ "afterBytes",
182
+ ],
183
+ permission_prompt: ["tool"],
184
+ notification: ["kind"],
185
+ tool_call: [
186
+ "tool",
187
+ "outcome",
188
+ "denial",
189
+ "toolUseId",
190
+ "promptWaitSec",
191
+ "durationMs",
192
+ "inputChars",
193
+ "outputChars",
194
+ "fileExt",
195
+ "program",
196
+ "skill",
197
+ "subagent",
198
+ "subagentTokens",
199
+ "subagentTools",
200
+ "mcpServer",
201
+ "host",
202
+ ],
203
+ slurp_check: [
204
+ "mode",
205
+ "predicted",
206
+ "oom",
207
+ "hitCount",
208
+ "maxBytes",
209
+ "thresholdBytes",
210
+ "idioms",
211
+ ],
212
+ compaction_near: [
213
+ "mode",
214
+ "trigger",
215
+ "contextTokens",
216
+ "windowTokens",
217
+ "windowSource",
218
+ "compactAtTokens",
219
+ "tokensLeft",
220
+ "marginTokens",
221
+ "predicted",
222
+ "idleMinTokens",
223
+ ],
224
+ algorithm_run: [
225
+ "mode",
226
+ "change",
227
+ "run",
228
+ "node",
229
+ "turn",
230
+ "phases",
231
+ "header",
232
+ "headerFirst",
233
+ "startsNew",
234
+ "verdict",
235
+ "source",
236
+ "runType",
237
+ "wouldNudge",
238
+ "exempt",
239
+ ],
240
+ deadline_run: [
241
+ "kind",
242
+ "change",
243
+ "blocks",
244
+ "logEntries",
245
+ "minutesLeft",
246
+ "estimateMin",
247
+ "done",
248
+ ],
249
+ minimum_run: [
250
+ "change",
251
+ "lens",
252
+ "blocks",
253
+ "rounds",
254
+ "floorMin",
255
+ "minutesLeft",
256
+ "bar",
257
+ "early",
258
+ ],
259
+ worktree_pruned: ["branch"],
260
+ worktree_prune_failed: ["branch"],
261
+ git_state_injected: ["trigger", "source", "changed", "committedFiles", "chars"],
262
+ hook_run: ["hook", "event", "part", "durationMs", "exitCode", "outputChars"],
263
+ repo_state: ["head", "branch", "changed", "ahead", "behind"],
264
+ } as const satisfies Record<string, readonly string[]>;
265
+
266
+ export type EventType = keyof typeof EVENT_FIELDS;
@@ -12,256 +12,12 @@ import { logError } from "../core/log";
12
12
  import { boundProjectAt } from "../core/project-bindings";
13
13
  import { storeDir } from "./bronze";
14
14
  import { currentChannel } from "./channel";
15
+ import { EVENT_FIELDS, type EventType } from "./event-fields";
15
16
 
16
17
  export const EVENT_SCHEMA_VERSION = 1;
17
18
  const MAX_STRING = 64;
18
19
  const MAX_ARRAY = 50;
19
20
 
20
- export const USAGE_FIELDS = [
21
- "inputTokens",
22
- "outputTokens",
23
- "cacheWrite5m",
24
- "cacheWrite1h",
25
- "cacheRead",
26
- "thinkingTokens",
27
- "costUsd",
28
- ] as const;
29
-
30
- export const EVENT_FIELDS = {
31
- turn: [
32
- "hour",
33
- "weekday",
34
- "words",
35
- "gapSec",
36
- "afterBreak",
37
- "skimmed",
38
- "interrupted",
39
- "repeated",
40
- "corrected",
41
- "reply",
42
- "reaction",
43
- "reactionRules",
44
- "mood",
45
- "hinted",
46
- "complied",
47
- "language",
48
- "pastedChars",
49
- "images",
50
- "command",
51
- "backAfterSec",
52
- ],
53
- reply: ["words", "listItems", "headings", "asked", "mode", "latencySec", "turn"],
54
- session_start: [
55
- "source",
56
- "model",
57
- "effort",
58
- "entrypoint",
59
- "branch",
60
- "palVersion",
61
- "tz",
62
- "utcOffsetMin",
63
- ],
64
- session_end: ["reason", "durationSec", "turns", "messages", "status"],
65
- sync: ["pushed", "pulled", "written", "quarantined", "refused"],
66
- sync_account: ["action", "store"],
67
- actor_adopted: ["from", "to"],
68
- upstream_report: ["action", "report", "leaks", "via"],
69
- doctor_run: ["failing", "warnings"],
70
- pal_bug_signal: ["trigger", "surface", "verdict"],
71
- compaction: ["trigger", "withInstructions", "contextTokens"],
72
- context_injected: ["instructionsChars", "semiStaticChars", "dynamicChars"],
73
- hook_timing: ["hook", "totalMs", "handlers"],
74
- inference_call: [
75
- "caller",
76
- "route",
77
- "model",
78
- "tier",
79
- "web",
80
- "latencyMs",
81
- "failure",
82
- ...USAGE_FIELDS,
83
- ],
84
- judge_call: [
85
- "caller",
86
- "mode",
87
- "route",
88
- "provider",
89
- "model",
90
- "inputTokens",
91
- "costUsd",
92
- "latencyMs",
93
- "failure",
94
- "systemOneAnswers",
95
- "fallbackAnswers",
96
- ],
97
- pal_update: ["outcome", "from", "to", "durationSec", "skipReason"],
98
- memory_move: [
99
- "migration",
100
- "outcome",
101
- "entries",
102
- "files",
103
- "bytes",
104
- "manifest",
105
- "reason",
106
- "hashTotal",
107
- "archive",
108
- "lines",
109
- "kept",
110
- "differ",
111
- ],
112
- migration_run: [
113
- "migration",
114
- "outcome",
115
- "migrated",
116
- "skipped",
117
- "dryRun",
118
- "undo",
119
- "sweep",
120
- ],
121
- pal_heartbeat: ["outcome", "payload", "status", "skipReason"],
122
- commitment: ["iscProject", "isc", "outcome", "surface", "snoozeDays"],
123
- ticket: ["iscProject", "ticket", "status", "at", "since", "was"],
124
- entity_first_seen: ["domain", "entityType"],
125
- discord_nag: ["stage", "kind", "responseSec"],
126
- model_call: [
127
- "billing",
128
- "plan",
129
- "extraUsage",
130
- "model",
131
- "requestedModel",
132
- "provider",
133
- "inputTokens",
134
- "outputTokens",
135
- "cacheWrite5m",
136
- "cacheWrite1h",
137
- "cacheRead",
138
- "thinkingTokens",
139
- "thinkingMs",
140
- "webSearches",
141
- "webFetches",
142
- "serviceTier",
143
- "speed",
144
- "effort",
145
- "stopReason",
146
- "entrypoint",
147
- "sidechain",
148
- "costUsd",
149
- "agent",
150
- "mode",
151
- "durationMs",
152
- "ttftMs",
153
- "aiu",
154
- "initiator",
155
- "host",
156
- ],
157
- conversation: ["steps", "status", "depth", "subagent", "killed"],
158
- commit: [
159
- "hash",
160
- "committedAt",
161
- "files",
162
- "added",
163
- "deleted",
164
- "commitType",
165
- "breaking",
166
- "revert",
167
- "merge",
168
- "tags",
169
- "coAuthors",
170
- "aiCoAuthored",
171
- ],
172
- rating: ["rating", "source"],
173
- forgotten: ["target", "undone"],
174
- project: ["change", "status"],
175
- setting: ["key", "change"],
176
- rule_decision: ["rule", "decision"],
177
- calibration_label: ["deck", "item", "answer"],
178
- decision: ["words"],
179
- promise: ["change", "dueInSec", "lateSec", "snoozes", "nags"],
180
- action: [
181
- "tool",
182
- "outcome",
183
- "fileExt",
184
- "change",
185
- "linesAdded",
186
- "linesRemoved",
187
- "beforeBytes",
188
- "afterBytes",
189
- ],
190
- permission_prompt: ["tool"],
191
- notification: ["kind"],
192
- tool_call: [
193
- "tool",
194
- "outcome",
195
- "denial",
196
- "toolUseId",
197
- "promptWaitSec",
198
- "durationMs",
199
- "inputChars",
200
- "outputChars",
201
- "fileExt",
202
- "program",
203
- "skill",
204
- "subagent",
205
- "subagentTokens",
206
- "subagentTools",
207
- "mcpServer",
208
- "host",
209
- ],
210
- slurp_check: [
211
- "mode",
212
- "predicted",
213
- "oom",
214
- "hitCount",
215
- "maxBytes",
216
- "thresholdBytes",
217
- "idioms",
218
- ],
219
- compaction_near: [
220
- "mode",
221
- "trigger",
222
- "contextTokens",
223
- "windowTokens",
224
- "windowSource",
225
- "compactAtTokens",
226
- "tokensLeft",
227
- "marginTokens",
228
- "predicted",
229
- "idleMinTokens",
230
- ],
231
- algorithm_run: [
232
- "mode",
233
- "change",
234
- "run",
235
- "node",
236
- "turn",
237
- "phases",
238
- "header",
239
- "headerFirst",
240
- "startsNew",
241
- "verdict",
242
- "source",
243
- "runType",
244
- "wouldNudge",
245
- "exempt",
246
- ],
247
- minimum_run: [
248
- "change",
249
- "lens",
250
- "blocks",
251
- "rounds",
252
- "floorMin",
253
- "minutesLeft",
254
- "bar",
255
- "early",
256
- ],
257
- worktree_pruned: ["branch"],
258
- worktree_prune_failed: ["branch"],
259
- git_state_injected: ["trigger", "source", "changed", "committedFiles", "chars"],
260
- hook_run: ["hook", "event", "part", "durationMs", "exitCode"],
261
- repo_state: ["head", "branch", "changed", "ahead", "behind"],
262
- } as const satisfies Record<string, readonly string[]>;
263
-
264
- export type EventType = keyof typeof EVENT_FIELDS;
265
21
  // answers keep their probabilities: question → answer → probabilities
266
22
  const NESTING_DEPTH: Partial<Record<EventType, number>> = { judge_call: 2 };
267
23
  type EventValue =
@@ -6,11 +6,11 @@
6
6
 
7
7
  import { readdirSync } from "node:fs";
8
8
  import { resolve } from "node:path";
9
+ import type { EventType } from "./event-fields";
9
10
  import {
10
11
  allEventsSince,
11
12
  appendEvent,
12
13
  contentDir,
13
- type EventType,
14
14
  eventsSince,
15
15
  type LoggedEvent,
16
16
  parseLines,
@@ -27,7 +27,14 @@ export interface EvidenceTurn {
27
27
  project: string | null;
28
28
  text: string | null;
29
29
  pastedChars: number | null;
30
- reply: { id: string; text: string | null } | null;
30
+ reply: EvidenceReply | null;
31
+ }
32
+
33
+ interface EvidenceReply {
34
+ id: string;
35
+ text: string | null;
36
+ narration: string[];
37
+ thinking: string[];
31
38
  }
32
39
 
33
40
  export interface Exclusion {
@@ -50,6 +57,21 @@ export function contentById(): Map<string, ContentRow> {
50
57
  const textOf = (row: ContentRow | undefined, field: string): string | null =>
51
58
  typeof row?.[field] === "string" ? (row[field] as string) : null;
52
59
 
60
+ const textsOf = (row: ContentRow | undefined, field: string): string[] => {
61
+ const texts = row?.[field];
62
+
63
+ return Array.isArray(texts) ? texts.filter((t) => typeof t === "string") : [];
64
+ };
65
+
66
+ function replyOf(row: ContentRow | undefined, id: string): EvidenceReply {
67
+ return {
68
+ id,
69
+ text: textOf(row, "reply"),
70
+ narration: textsOf(row, "narration"),
71
+ thinking: textsOf(row, "thinking"),
72
+ };
73
+ }
74
+
53
75
  export function contentFor(id: string): ContentRow | null {
54
76
  return contentById().get(id) ?? null;
55
77
  }
@@ -80,6 +102,8 @@ export function userTurnsSince(since: Date): EvidenceTurn[] {
80
102
  const excluded = new Set(exclusions().map((e) => e.id));
81
103
  const textIfKept = (id: string, field: string) =>
82
104
  excluded.has(id) ? null : textOf(content.get(id), field);
105
+ const replyIfKept = (id: string) =>
106
+ replyOf(excluded.has(id) ? undefined : content.get(id), id);
83
107
 
84
108
  return ofType(events, "turn")
85
109
  .filter((e) => e.authority === "user" && !excluded.has(e.id))
@@ -95,7 +119,7 @@ export function userTurnsSince(since: Date): EvidenceTurn[] {
95
119
  project: turn.project,
96
120
  text: textIfKept(turn.id, "prompt"),
97
121
  pastedChars: typeof turn.pastedChars === "number" ? turn.pastedChars : null,
98
- reply: reply ? { id: reply.id, text: textIfKept(reply.id, "reply") } : null,
122
+ reply: reply ? replyIfKept(reply.id) : null,
99
123
  };
100
124
  });
101
125
  }
@@ -118,7 +118,7 @@ function entryId(entry: EntryIds): string | undefined {
118
118
  return id === undefined ? undefined : String(id);
119
119
  }
120
120
 
121
- function messageOfLine(line: string): Message | null {
121
+ export function messageOfLine(line: string): Message | null {
122
122
  try {
123
123
  const entry = JSON.parse(line);
124
124
  const message = parseTranscriptEntry(entry);