@nightloom/isy 1.0.2 → 1.0.4

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.
Files changed (69) hide show
  1. package/README.md +1 -1
  2. package/dist/agents/codex-records.js +13 -1
  3. package/dist/agents/codex-records.js.map +1 -1
  4. package/dist/api.d.ts +3 -0
  5. package/dist/api.js +5 -2
  6. package/dist/api.js.map +1 -1
  7. package/dist/commands/health.js +2 -2
  8. package/dist/commands/health.js.map +1 -1
  9. package/dist/commands/init.js +9 -0
  10. package/dist/commands/init.js.map +1 -1
  11. package/dist/commands/upload.d.ts +2 -0
  12. package/dist/commands/upload.js +30 -3
  13. package/dist/commands/upload.js.map +1 -1
  14. package/dist/detectors.js +10 -4
  15. package/dist/detectors.js.map +1 -1
  16. package/dist/mask-paths.js +36 -16
  17. package/dist/mask-paths.js.map +1 -1
  18. package/dist/parser.d.ts +5 -0
  19. package/dist/parser.js +21 -8
  20. package/dist/parser.js.map +1 -1
  21. package/dist/plan.d.ts +3 -1
  22. package/dist/plan.js +5 -1
  23. package/dist/plan.js.map +1 -1
  24. package/dist/queue.d.ts +14 -2
  25. package/dist/queue.js +25 -3
  26. package/dist/queue.js.map +1 -1
  27. package/dist/redact.d.ts +7 -0
  28. package/dist/redact.js +281 -8
  29. package/dist/redact.js.map +1 -1
  30. package/dist/state.d.ts +9 -3
  31. package/dist/state.js +4 -4
  32. package/dist/state.js.map +1 -1
  33. package/dist/subagents.d.ts +8 -4
  34. package/dist/subagents.js +13 -7
  35. package/dist/subagents.js.map +1 -1
  36. package/dist/test/codex.test.js +15 -0
  37. package/dist/test/codex.test.js.map +1 -1
  38. package/dist/test/init.test.js +9 -0
  39. package/dist/test/init.test.js.map +1 -1
  40. package/dist/test/mask-paths.test.js +45 -0
  41. package/dist/test/mask-paths.test.js.map +1 -1
  42. package/dist/test/parser.test.js +16 -0
  43. package/dist/test/parser.test.js.map +1 -1
  44. package/dist/test/plan.test.js +7 -6
  45. package/dist/test/plan.test.js.map +1 -1
  46. package/dist/test/redact.test.js +239 -11
  47. package/dist/test/redact.test.js.map +1 -1
  48. package/dist/test/stage0.test.js +11 -0
  49. package/dist/test/stage0.test.js.map +1 -1
  50. package/dist/test/subagents.test.js +18 -0
  51. package/dist/test/subagents.test.js.map +1 -1
  52. package/dist/test/sweep.test.js +33 -0
  53. package/dist/test/sweep.test.js.map +1 -1
  54. package/dist/test/upload.test.js +68 -6
  55. package/dist/test/upload.test.js.map +1 -1
  56. package/package.json +3 -2
  57. package/src/agents/codex-records.ts +14 -1
  58. package/src/api.ts +9 -3
  59. package/src/commands/health.ts +2 -2
  60. package/src/commands/init.ts +9 -0
  61. package/src/commands/upload.ts +38 -3
  62. package/src/detectors.ts +9 -4
  63. package/src/mask-paths.ts +36 -15
  64. package/src/parser.ts +17 -8
  65. package/src/plan.ts +4 -1
  66. package/src/queue.ts +30 -4
  67. package/src/redact.ts +287 -9
  68. package/src/state.ts +10 -4
  69. package/src/subagents.ts +20 -11
@@ -62,6 +62,19 @@ function contentText(content: unknown): string {
62
62
  return parts.join("\n");
63
63
  }
64
64
 
65
+ /**
66
+ * What Codex sends under the user's role that the user never typed: the
67
+ * working directory and shell (`<environment_context>`), AGENTS.md and the
68
+ * user's own instruction file, the plugins it recommends. Codex tells them from
69
+ * a turn by these openings, and sends several as parts of one message.
70
+ */
71
+ const HARNESS_USER_PART = /^\s*(?:<environment_context>|<user_instructions>|<recommended_plugins>|# AGENTS\.md instructions for )/;
72
+
73
+ function typedByUser(content: unknown): unknown {
74
+ if (!Array.isArray(content)) return HARNESS_USER_PART.test(contentText(content)) ? "" : content;
75
+ return content.filter((part) => !HARNESS_USER_PART.test(contentText([part])));
76
+ }
77
+
65
78
  /**
66
79
  * Reasoning Codex actually recorded in the clear. `encrypted_content` is an
67
80
  * opaque blob — megabytes of it per session — and is deliberately dropped:
@@ -468,7 +481,7 @@ export function toClaudeRecords(rollout: Iterable<string>, options: CodexOptions
468
481
  // `developer` messages are harness-injected context, not the user's work.
469
482
  if (role !== "user" && role !== "assistant") continue;
470
483
 
471
- const text = contentText(payload.content);
484
+ const text = contentText(role === "user" ? typedByUser(payload.content) : payload.content);
472
485
  if (!text) continue;
473
486
 
474
487
  emit({
package/src/api.ts CHANGED
@@ -66,7 +66,10 @@ export type UploadOutcome =
66
66
  // Too many uploads this hour. Not a failure: the session is kept as it is,
67
67
  // and the run stops rather than spending the retries of every session behind
68
68
  // it on an answer that will not change.
69
- | { status: "throttled" };
69
+ | { status: "throttled" }
70
+ // The key, not the session: missing, unknown or revoked. Handled like
71
+ // "throttled", so what was waiting still goes up once `isy init` has run.
72
+ | { status: "unauthorized"; error: string };
70
73
 
71
74
  export interface ApiOptions {
72
75
  baseUrl: string;
@@ -117,14 +120,17 @@ function accepted(body: string): UploadOutcome {
117
120
  function classify(status: number, body: string): UploadOutcome {
118
121
  if (status >= 200 && status < 300) return accepted(body);
119
122
  if (status === 401 || status === 403) {
120
- return { status: "permanent", error: `authentication rejected (${status}), run: isy init` };
123
+ return { status: "unauthorized", error: `authentication rejected (${status}), run: isy init` };
121
124
  }
122
125
  if (status === 413) return { status: "permanent", error: "transcript rejected as too large (413)" };
123
126
  // A backlog is drained over hours rather than given up on: a sweep can find
124
127
  // more sessions than an hour's allowance, and they are not at fault for it.
125
128
  if (status === 429) return { status: "throttled" };
129
+ // Retried rather than refused for good: a validation bug on the server's side
130
+ // reads the same as one in the payload, and a session passed over until it
131
+ // changes would be lost with every other that ended while the bug was live.
126
132
  if (status === 400 || status === 422) {
127
- return { status: "permanent", error: `server rejected the payload (${status}) ${body}`.trim() };
133
+ return { status: "retry", error: `server rejected the payload (${status}) ${body}`.trim() };
128
134
  }
129
135
  return { status: "retry", error: `server returned ${status} ${body}`.trim() };
130
136
  }
@@ -190,7 +190,7 @@ async function stateProblems(verified: string[]): Promise<HealthProblem[]> {
190
190
  }
191
191
  }
192
192
 
193
- /** Uploads that used up all three attempts. Their stored `lastError` is the evidence. */
193
+ /** Uploads that used up every attempt. Their stored `lastError` is the evidence. */
194
194
  async function queueProblems(): Promise<HealthProblem[]> {
195
195
  const failed = await listFailed();
196
196
  if (failed.length === 0) return [];
@@ -199,7 +199,7 @@ async function queueProblems(): Promise<HealthProblem[]> {
199
199
  {
200
200
  id: "uploads-abandoned",
201
201
  summary: `${failed.length} session${failed.length === 1 ? "" : "s"} never reached the server`,
202
- attempted: "POST /api/v1/sessions for each queued session, three times",
202
+ attempted: "POST /api/v1/sessions for each queued session, until the queue gave up on it",
203
203
  evidence: failed
204
204
  .map((item) => `${item.entry.sessionId}: ${item.entry.lastError ?? "no error recorded"}`)
205
205
  .join("\n"),
@@ -1,5 +1,6 @@
1
1
  import { execFile } from "node:child_process";
2
2
  import { createInterface } from "node:readline/promises";
3
+ import { drainAlerts, parkAlert } from "../alert.js";
3
4
  import { DEFAULT_API_BASE_URL, verifyToken } from "../api.js";
4
5
  import { readConfig, writeConfig } from "../config.js";
5
6
  import { presentAgents } from "../agents/index.js";
@@ -162,6 +163,14 @@ export async function runInit(options: { token?: string }, cwd: string): Promise
162
163
  await writeConfig({ ...config, token, githubLogin: verified.githubLogin });
163
164
  if (!kept) console.log(`Token stored in ${configPath()}`);
164
165
 
166
+ // A hook that found the key missing or refused parked "run: isy init", not
167
+ // always last on its line (`formatUploadAlert`), and this is that run. Left
168
+ // parked, the next session start would send the reader back here for
169
+ // nothing; anything else waiting stays for it.
170
+ for (const line of (await drainAlerts()).split("\n")) {
171
+ if (line && !line.includes("run: isy init")) await parkAlert(line);
172
+ }
173
+
165
174
  // Hooks go into every CLI actually installed here, and none that is not.
166
175
  const agents = await presentAgents();
167
176
  if (agents.length === 0) {
@@ -10,7 +10,17 @@ import type { DiscoveredSession, IsyConfig } from "../types.js";
10
10
  import { logError, logLine } from "../log.js";
11
11
  import { parseLines } from "../parser.js";
12
12
  import { packageVersion } from "../paths.js";
13
- import { MAX_ATTEMPTS, abandon, drop, enqueue, isAbandoned, listPending, recordFailure } from "../queue.js";
13
+ import {
14
+ MAX_ATTEMPTS,
15
+ abandon,
16
+ drop,
17
+ enqueue,
18
+ forget,
19
+ isAbandoned,
20
+ isDue,
21
+ listPending,
22
+ recordFailure,
23
+ } from "../queue.js";
14
24
  import { updateNotice } from "../update.js";
15
25
  import { planNotice } from "../plan.js";
16
26
  import type { PlanStatus } from "../plan.js";
@@ -42,6 +52,8 @@ export interface UploadReport {
42
52
  scanned?: number;
43
53
  /** The server's hourly upload allowance ran out; nothing was lost by it. */
44
54
  throttled?: boolean;
55
+ /** Why the server refused the key. Nothing was lost by that either. */
56
+ unauthorized?: string;
45
57
  }
46
58
 
47
59
  export async function readHookInput(
@@ -129,6 +141,7 @@ async function notePlan(plan: PlanStatus | undefined, report: UploadReport): Pro
129
141
  async function drainQueue(api: ApiOptions, deadline: number, report: UploadReport): Promise<void> {
130
142
  for (const item of await listPending()) {
131
143
  if (Date.now() >= deadline) return;
144
+ if (!isDue(item.entry)) continue;
132
145
 
133
146
  const outcome = await uploadSession(item.entry.payload, api);
134
147
  if (outcome.status === "ok") {
@@ -145,6 +158,11 @@ async function drainQueue(api: ApiOptions, deadline: number, report: UploadRepor
145
158
  logLine("upload: rate limited, the queue keeps its place for the next run");
146
159
  return;
147
160
  }
161
+ if (outcome.status === "unauthorized") {
162
+ report.unauthorized = outcome.error;
163
+ logError(`upload: the queue waits for a key the server takes: ${outcome.error}`);
164
+ return;
165
+ }
148
166
 
149
167
  if (outcome.status === "permanent") {
150
168
  await abandon(item, outcome.error);
@@ -308,6 +326,7 @@ async function sendOne(
308
326
  await noteClientVersion(outcome.clientVersion, payload.isyVersion, report);
309
327
  await notePlan(outcome.plan, report);
310
328
  if (outcome.deduplicated !== true) report.fresh += 1;
329
+ await forget(payload.sessionId, payload.contentHash);
311
330
  // Recorded only once the server has it: a failed send must stay "changed"
312
331
  // so the next commit tries again rather than skipping it forever.
313
332
  const seen = await fingerprint(target);
@@ -324,6 +343,11 @@ async function sendOne(
324
343
  // only burn its attempts.
325
344
  report.throttled = true;
326
345
  logLine(`upload: ${payload.sessionId} not sent, this hour's uploads are spent`);
346
+ } else if (outcome.status === "unauthorized") {
347
+ // Neither queued nor dropped either: the transcript still reads as changed,
348
+ // so the first run with a key the server takes sends it.
349
+ report.unauthorized = outcome.error;
350
+ logError(`upload: ${payload.sessionId} not sent: ${outcome.error}`);
327
351
  } else if (outcome.status === "retry") {
328
352
  await enqueue(payload, outcome.error);
329
353
  report.queued += 1;
@@ -331,6 +355,15 @@ async function sendOne(
331
355
  } else {
332
356
  report.abandoned += 1;
333
357
  logError(`upload: dropped ${payload.sessionId}: ${outcome.error}`);
358
+ // Refused for what it holds, so building it again only to hear the same is
359
+ // all the next sweep would do: it is passed over until it changes.
360
+ const seen = await fingerprint(target);
361
+ await updateSession(target.path, (current) => ({
362
+ ...current,
363
+ rejectedHash: payload.contentHash,
364
+ uploadedCommit: payload.commits?.at(-1)?.sha,
365
+ ...seen,
366
+ }));
334
367
  }
335
368
  }
336
369
 
@@ -444,8 +477,8 @@ export async function runUpload(
444
477
  logLine(`upload: out of budget with ${targets.length - report.sent} session(s) left`);
445
478
  break;
446
479
  }
447
- // One "throttled" answers for every session in the run.
448
- if (report.throttled) break;
480
+ // One "throttled", or one refused key, answers for every session in the run.
481
+ if (report.throttled || report.unauthorized) break;
449
482
 
450
483
  const git = await gitFor(target.cwd ?? workingDir);
451
484
  if (!git.ok) {
@@ -486,6 +519,7 @@ export function formatUploadReport(report: UploadReport): string {
486
519
  const parts: string[] = [];
487
520
  if (report.sent > 0) parts.push("session uploaded");
488
521
  if (report.throttled) parts.push("rate limited, the rest go out on the next run");
522
+ if (report.unauthorized) parts.push(report.unauthorized);
489
523
  if (report.queued > 0) parts.push("session queued for retry");
490
524
  if (report.drained > 0) parts.push(`${report.drained} queued session(s) sent`);
491
525
  if (report.abandoned > 0) parts.push(`${report.abandoned} session(s) given up on`);
@@ -516,6 +550,7 @@ export function formatUploadAlert(report: UploadReport): string | undefined {
516
550
  if (report.drained > 0) parts.push(`${report.drained} queued session(s) sent`);
517
551
  if (report.queued > 0) parts.push("upload failed, queued for retry");
518
552
  if (report.throttled) parts.push("rate limited, the rest upload on the next run");
553
+ if (report.unauthorized) parts.push(report.unauthorized);
519
554
  if (report.abandoned > 0) parts.push(`${report.abandoned} session(s) given up on`);
520
555
  if (report.gitHook === "installed") parts.push("commit and push hooks added to this repository");
521
556
  if (report.gitHook === "shared-hooks") {
package/src/detectors.ts CHANGED
@@ -25,13 +25,18 @@ const GIT_STASH = /\bgit\s+stash\b(?!\s+(pop|apply|list|show))/;
25
25
  const GIT_CHECKOUT = /\bgit\s+checkout\s+(?:--\s+)?(?<paths>[^&|;]+)/;
26
26
  const GIT_RESTORE = /\bgit\s+restore\s+(?<paths>[^&|;]+)/;
27
27
 
28
+ // Trimmed without a regex: `\s+$` and `\n+$` rescan the rest of a run from
29
+ // every character in it, and a file holding a long run of spaces or blank
30
+ // lines took half a minute to digest.
28
31
  function normalize(content: string): string {
29
- return content
32
+ const joined = content
30
33
  .replace(/\r\n/g, "\n")
31
34
  .split("\n")
32
- .map((line) => line.replace(/\s+$/, ""))
33
- .join("\n")
34
- .replace(/\n+$/, "");
35
+ .map((line) => line.trimEnd())
36
+ .join("\n");
37
+ let end = joined.length;
38
+ while (end > 0 && joined.charCodeAt(end - 1) === 10) end -= 1;
39
+ return joined.slice(0, end);
35
40
  }
36
41
 
37
42
  function digest(content: string): string {
package/src/mask-paths.ts CHANGED
@@ -102,17 +102,22 @@ const SEG = /[^\s"'`<>:;,|&$*?()[\]{}\\/]/;
102
102
  /**
103
103
  * A scheme makes it a URL, and `https://example.com/home/alice/x` names a page
104
104
  * rather than this machine. Matched first, so no path rule sees a hostname.
105
+ * The scheme is capped for the reason `redact.ts` caps the connection string's:
106
+ * unbounded, every letter of a long run with no `://` in it started a scan of
107
+ * the rest of the run. A longer scheme still matches on its tail, and the URL
108
+ * is still kept away from the path rules.
105
109
  */
106
- const URL_LIKE = /[A-Za-z][A-Za-z0-9+.-]*:\/\/[^\s"'`<>]*/;
110
+ const URL_LIKE = /[A-Za-z][A-Za-z0-9+.-]{0,31}:\/\/[^\s"'`<>]*/;
107
111
 
108
112
  /**
109
113
  * The two schemes that are the exception: they carry a path on this machine
110
114
  * rather than an address on the network. Node, vitest and Next print
111
115
  * `imported from file:///home/alice/…` on an unresolved import, and that lands
112
116
  * in a tool result like any other line of stdout; an editor spells the same
113
- * path `vscode://file/home/alice/…`. The scheme is kept, the path masked.
117
+ * path `vscode://file/home/alice/…`, and some tools `file://localhost/home/…`.
118
+ * The scheme is kept, the path masked.
114
119
  */
115
- const LOCAL_URL = /^((?:file|vscode(?:-insiders)?):\/\/(?:file)?)(\/[^\s"'`<>]*)$/;
120
+ const LOCAL_URL = /^((?:file|vscode(?:-insiders)?):\/\/(?:file|localhost)?)(\/[^\s"'`<>]*)$/;
116
121
 
117
122
  /**
118
123
  * `\\host\share\…`. The lookbehind keeps a drive letter out: a transcript line
@@ -127,9 +132,19 @@ const UNC = new RegExp(
127
132
  `(?<![A-Za-z0-9:~\\\\])\\\\\\\\${SEG.source}+(?:[\\\\/]+${SEG.source}+)*[\\\\/]?`,
128
133
  );
129
134
 
135
+ /**
136
+ * What ends an escape rather than a word, so a path may open right after it:
137
+ * `\n`, `\u001b`, `\x22`, and a terminal's colour code (`ESC[2m`), raw or
138
+ * escaped — test runners colour the paths they print.
139
+ */
140
+ const ESCAPE_END = String.raw`(?:\\[A-Za-z0-9]|\\u[0-9A-Fa-f]{4}|\\x[0-9A-Fa-f]{2}|(?:\x1b|\\u001b|\\x1b|\\033|\\e)\[[0-9;]*m)`;
141
+
142
+ /** A letter or digit right before a path continues a word, unless it ends an escape. */
143
+ const NOT_A_WORD = `(?<![A-Za-z0-9](?<!${ESCAPE_END}))`;
144
+
130
145
  /** Separators repeat for the same reason: JSON doubles every backslash. */
131
146
  const WINDOWS = new RegExp(
132
- `(?<![A-Za-z0-9])[A-Za-z]:[\\\\/]+(?:${SEG.source}+[\\\\/]+)*${SEG.source}*`,
147
+ `${NOT_A_WORD}[A-Za-z]:[\\\\/]+(?:${SEG.source}+[\\\\/]+)*${SEG.source}*`,
133
148
  );
134
149
 
135
150
  /**
@@ -140,14 +155,17 @@ const WINDOWS = new RegExp(
140
155
  * `~` stays, and that is all idempotence needs: masking twice is masking once,
141
156
  * because `./dist/b.js` and `100%/x` are under no root and come back unchanged.
142
157
  *
143
- * The inner lookbehind is the one exception to the letter rule: a letter that
144
- * is itself behind a backslash ends an escape sequence rather than a word. Tool
145
- * output reaches a transcript JSON-encoded twice often enough for that to
146
- * matter — Prisma reports `invocation in\\n/home/alice/…`, and read as a word
147
- * `in\\n` carried the account name through untouched.
158
+ * The one exception to the letter rule is a letter that ends an escape rather
159
+ * than a word (`ESCAPE_END`). Tool output reaches a transcript JSON-encoded
160
+ * twice often enough for that to matter — Prisma reports
161
+ * `invocation in\\n/home/alice/…`, and read as a word `in\\n` carried the
162
+ * account name through untouched.
163
+ *
164
+ * A slash may come escaped, `\/home\/alice\/…`, as PHP and some loggers write
165
+ * JSON; that is still one path.
148
166
  */
149
167
  const POSIX = new RegExp(
150
- `(?<!~)(?<!(?<!\\\\)[A-Za-z0-9])\\/(?:${SEG.source}+\\/)*${SEG.source}+\\/?`,
168
+ `(?<!~)${NOT_A_WORD}\\\\?\\/(?:${SEG.source}+\\\\?\\/)*${SEG.source}+(?:\\\\?\\/)?`,
151
169
  );
152
170
 
153
171
  /**
@@ -180,7 +198,7 @@ const TRAILING = /[.,;:!?]+$/;
180
198
  * slug behind a newline is as much the account name as one behind a slash.
181
199
  */
182
200
  const PROJECT_SLUG =
183
- /(?<![A-Za-z0-9._-])-(?:home|root|users|[a-z]-users)-[A-Za-z0-9._-]*-[A-Za-z0-9._-]+(?![A-Za-z0-9._-])/gi;
201
+ /(?<![A-Za-z0-9._-])-(?:home|root|users|(?:mnt-|cygdrive-)?[a-z]-users)-[A-Za-z0-9._-]*-[A-Za-z0-9._-]+(?![A-Za-z0-9._-])/gi;
184
202
 
185
203
  /**
186
204
  * `-home-alice`: the slug of a session that ran in the home directory itself.
@@ -191,7 +209,7 @@ const PROJECT_SLUG =
191
209
  * known nothing here fires at all.
192
210
  */
193
211
  const HOME_SLUG =
194
- /(?<![A-Za-z0-9._-])-(?:home|root|users|[a-z]-users)-[A-Za-z0-9._]+(?![A-Za-z0-9._-])/gi;
212
+ /(?<![A-Za-z0-9._-])-(?:home|root|users|(?:mnt-|cygdrive-)?[a-z]-users)-[A-Za-z0-9._]+(?![A-Za-z0-9._-])/gi;
195
213
 
196
214
  function maskSlugs(value: string, home: readonly string[] | undefined): string {
197
215
  const masked = value.replace(PROJECT_SLUG, MASK_PROJECT);
@@ -221,7 +239,8 @@ const NOT_AN_ACCOUNT: ReadonlySet<string> = new Set(["shared", "public", "defaul
221
239
  * Which segment of a path would be the account name, or -1 when the path is
222
240
  * not shaped like a home at all. `/home/alice/…` and `/Users/alice/…` name it
223
241
  * second; `C:\Users\alice\…` and the Git Bash spelling `/c/Users/alice/…`
224
- * name it third.
242
+ * name it third, and WSL's `/mnt/c/Users/alice/…` and Cygwin's
243
+ * `/cygdrive/c/Users/alice/…` fourth.
225
244
  *
226
245
  * The spellings are exact because the near misses are ordinary text:
227
246
  * `/users/42/profile` is a URL and `/root/app` is a `WORKDIR`, and neither
@@ -231,7 +250,8 @@ const NOT_AN_ACCOUNT: ReadonlySet<string> = new Set(["shared", "public", "defaul
231
250
  function accountAt(parts: readonly string[]): number {
232
251
  const head = parts[0] ?? "";
233
252
  if (head === "home" || head === "Users") return 1;
234
- if (/^[a-z]:?$/i.test(head) && (parts[1] ?? "").toLowerCase() === "users") return 2;
253
+ const drive = head === "mnt" || head === "cygdrive" ? 1 : 0;
254
+ if (/^[a-z]:?$/i.test(parts[drive] ?? "") && (parts[drive + 1] ?? "").toLowerCase() === "users") return drive + 2;
235
255
  return -1;
236
256
  }
237
257
 
@@ -259,8 +279,9 @@ function genericHome(parts: readonly string[]): string[] | undefined {
259
279
  return parts.slice(account + 1);
260
280
  }
261
281
 
262
- /** `\` when the path was written the Windows way, so a `~` path keeps its shape. */
282
+ /** The separator the path was written with, so a `~` path keeps its shape. */
263
283
  function joiner(value: string): string {
284
+ if (value.includes("\\/")) return "\\/";
264
285
  return value.includes("\\") ? "\\" : "/";
265
286
  }
266
287
 
package/src/parser.ts CHANGED
@@ -16,9 +16,10 @@ export const LOOKUP_TOOLS = new Set(["Read", "Grep", "Glob"]);
16
16
  /**
17
17
  * Every record type Claude Code writes to a session file: the table its 2.1.285
18
18
  * session writer routes each append by, plus `progress`, which older builds
19
- * wrote inline. A type outside it is kept and counted in `skipped.unknownTypes`,
20
- * which is what `isy status` reports as records it could not place — so a type
21
- * missing here reads to the user as a transcript this client half-understood.
19
+ * wrote inline, and `tools-used`, which 2.1.304 and later add. A type outside
20
+ * it is kept and counted in `skipped.unknownTypes`, which is what `isy status`
21
+ * reports as records it could not place — so a type missing here reads to the
22
+ * user as a transcript this client half-understood.
22
23
  */
23
24
  const KNOWN_RECORD_TYPES = new Set([
24
25
  "user",
@@ -61,6 +62,7 @@ const KNOWN_RECORD_TYPES = new Set([
61
62
  "api-request-blob",
62
63
  "fork-context-ref",
63
64
  "observer-ref",
65
+ "tools-used",
64
66
  ]);
65
67
 
66
68
  interface ParseState {
@@ -206,7 +208,7 @@ function pushLookup(state: ParseState, use: ToolUse): void {
206
208
  * A heredoc opener: `<<EOF`, `<<-EOF`, `<<'PY'`. The delimiter is what ends the
207
209
  * body, and quoting it changes nothing about where the body stops.
208
210
  */
209
- const HEREDOC = /<<-?\s*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/;
211
+ export const HEREDOC = /<<-?\s*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/;
210
212
 
211
213
  /**
212
214
  * The command with every heredoc body cut out.
@@ -794,13 +796,20 @@ function finish(state: ParseState): ParsedSession {
794
796
 
795
797
  for (const record of state.records) {
796
798
  sessionId ??= asString(record.sessionId);
797
- cwd = asString(record.cwd) ?? cwd;
798
- gitBranch = asString(record.gitBranch) ?? gitBranch;
799
- claudeVersion = asString(record.version) ?? claudeVersion;
799
+ // A subagent can work in a directory of its own and outlast the session, and
800
+ // one whose call is nowhere follows all of it (`subagents.ts`): where and on
801
+ // what the session ran comes off its own records, and off a subagent's only
802
+ // when it has none — a subagent's file read alone.
803
+ const own = record.isSidechain !== true;
804
+ if (own || cwd === undefined) cwd = asString(record.cwd) ?? cwd;
805
+ if (own || gitBranch === undefined) gitBranch = asString(record.gitBranch) ?? gitBranch;
806
+ if (own || claudeVersion === undefined) claudeVersion = asString(record.version) ?? claudeVersion;
800
807
  const timestamp = asString(record.timestamp);
801
808
  if (timestamp) {
802
809
  startedAt ??= timestamp;
803
- endedAt = timestamp;
810
+ // The latest, not the last: a subagent that follows the session can have
811
+ // ended before it.
812
+ if (endedAt === undefined || timestamp > endedAt) endedAt = timestamp;
804
813
  }
805
814
  if (record.type === "assistant") assistantRecords += 1;
806
815
  if (record.isSidechain === true) sidechainRecords += 1;
package/src/plan.ts CHANGED
@@ -46,9 +46,12 @@ function resetDay(iso: string | undefined): string | undefined {
46
46
  /**
47
47
  * The line, or nothing while there is still room. Credits count as room: they
48
48
  * are what the gate spends once the allowance is gone (`billing.ts:checkQuota`).
49
+ * So does a cycle that has rolled over since: the snapshot is only as new as
50
+ * the last upload, which can be days old.
49
51
  */
50
- export function planNotice(plan: PlanStatus | undefined): string | undefined {
52
+ export function planNotice(plan: PlanStatus | undefined, now = Date.now()): string | undefined {
51
53
  if (!plan || plan.analysesLeft > 0 || plan.credits > 0) return undefined;
54
+ if (plan.resetsAt && Date.parse(plan.resetsAt) <= now) return undefined;
52
55
  const day = resetDay(plan.resetsAt);
53
56
  return `plan limit reached on ${plan.tier} — pull requests are not analysed${
54
57
  day ? ` until ${day}` : ""
package/src/queue.ts CHANGED
@@ -3,7 +3,14 @@ import { join } from "node:path";
3
3
  import { queueDir } from "./paths.js";
4
4
  import type { UploadPayload } from "./api.js";
5
5
 
6
- export const MAX_ATTEMPTS = 3;
6
+ /**
7
+ * Attempts are spaced rather than made once per run: the wait before the next
8
+ * one doubles from ten minutes, so the last comes nearly two days after the
9
+ * session was queued. Runs come minutes apart — a session's start and end,
10
+ * every commit — so counted per run, one short outage would use them all up.
11
+ */
12
+ export const MAX_ATTEMPTS = 8;
13
+ const RETRY_AFTER_MS = 10 * 60_000;
7
14
  const FAILED_SUFFIX = ".failed";
8
15
 
9
16
  export interface QueueEntry {
@@ -11,6 +18,8 @@ export interface QueueEntry {
11
18
  contentHash: string;
12
19
  attempts: number;
13
20
  queuedAt: string;
21
+ /** When the last attempt failed. isy 1.0 did not record it; `queuedAt` stands in. */
22
+ lastAttemptAt?: string;
14
23
  lastError?: string;
15
24
  payload: UploadPayload;
16
25
  }
@@ -42,12 +51,17 @@ export async function enqueue(payload: UploadPayload, lastError?: string): Promi
42
51
 
43
52
  const path = join(dir, entryName(payload.sessionId, payload.contentHash));
44
53
  const existing = await readEntry(path);
54
+ const now = new Date().toISOString();
45
55
 
46
56
  const entry: QueueEntry = {
47
57
  sessionId: payload.sessionId,
48
58
  contentHash: payload.contentHash,
49
59
  attempts: existing ? existing.attempts : 0,
50
- queuedAt: existing ? existing.queuedAt : new Date().toISOString(),
60
+ queuedAt: existing ? existing.queuedAt : now,
61
+ // The send that failed starts the wait, or the drain closing the same run
62
+ // would try again a second later. Queued again by a later failed send, an
63
+ // entry keeps both this and `attempts`: the queue keeps its own schedule.
64
+ lastAttemptAt: existing ? existing.lastAttemptAt : now,
51
65
  lastError,
52
66
  payload,
53
67
  };
@@ -93,6 +107,12 @@ export async function listPending(): Promise<QueueItem[]> {
93
107
  return listBySuffix(".json");
94
108
  }
95
109
 
110
+ /** Whether a queued upload has waited out the delay since it last failed. */
111
+ export function isDue(entry: QueueEntry, now = Date.now()): boolean {
112
+ const last = Date.parse(entry.lastAttemptAt ?? entry.queuedAt);
113
+ return Number.isNaN(last) || now - last >= RETRY_AFTER_MS * 2 ** entry.attempts;
114
+ }
115
+
96
116
  /** Uploads that ran out of attempts. Their `lastError` is the only record of why. */
97
117
  export async function listFailed(): Promise<QueueItem[]> {
98
118
  return listBySuffix(FAILED_SUFFIX);
@@ -103,7 +123,8 @@ export async function recordFailure(
103
123
  error: string,
104
124
  ): Promise<"retained" | "abandoned"> {
105
125
  const attempts = item.entry.attempts + 1;
106
- const updated: QueueEntry = { ...item.entry, attempts, lastError: error };
126
+ const lastAttemptAt = new Date().toISOString();
127
+ const updated: QueueEntry = { ...item.entry, attempts, lastAttemptAt, lastError: error };
107
128
  await writeFile(item.path, JSON.stringify(updated), { mode: 0o600 });
108
129
 
109
130
  if (attempts >= MAX_ATTEMPTS) {
@@ -113,7 +134,7 @@ export async function recordFailure(
113
134
  return "retained";
114
135
  }
115
136
 
116
- export async function drop(item: QueueItem): Promise<void> {
137
+ export async function drop(item: Pick<QueueItem, "path">): Promise<void> {
117
138
  try {
118
139
  await unlink(item.path);
119
140
  } catch {
@@ -121,6 +142,11 @@ export async function drop(item: QueueItem): Promise<void> {
121
142
  }
122
143
  }
123
144
 
145
+ /** Bytes that went up some other way: a copy waiting out its delay here is done. */
146
+ export async function forget(sessionId: string, contentHash: string): Promise<void> {
147
+ await drop({ path: join(queueDir(), entryName(sessionId, contentHash)) });
148
+ }
149
+
124
150
  export async function abandon(item: QueueItem, error: string): Promise<void> {
125
151
  const updated: QueueEntry = { ...item.entry, attempts: MAX_ATTEMPTS, lastError: error };
126
152
  await writeFile(item.path, JSON.stringify(updated), { mode: 0o600 });