@nightloom/isy 1.0.5 → 1.0.6-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +17 -2
  2. package/dist/agents/claude.js +3 -2
  3. package/dist/agents/claude.js.map +1 -1
  4. package/dist/agents/codex.js +14 -5
  5. package/dist/agents/codex.js.map +1 -1
  6. package/dist/agents/index.d.ts +14 -10
  7. package/dist/agents/index.js +65 -15
  8. package/dist/agents/index.js.map +1 -1
  9. package/dist/agents/kimi.js +26 -8
  10. package/dist/agents/kimi.js.map +1 -1
  11. package/dist/agents/types.d.ts +12 -3
  12. package/dist/commands/commit.d.ts +6 -0
  13. package/dist/commands/commit.js +326 -16
  14. package/dist/commands/commit.js.map +1 -1
  15. package/dist/commands/health.js +1 -1
  16. package/dist/commands/health.js.map +1 -1
  17. package/dist/commands/init.js +30 -5
  18. package/dist/commands/init.js.map +1 -1
  19. package/dist/commands/status.d.ts +2 -0
  20. package/dist/commands/status.js +7 -4
  21. package/dist/commands/status.js.map +1 -1
  22. package/dist/commands/upload.d.ts +8 -1
  23. package/dist/commands/upload.js +46 -39
  24. package/dist/commands/upload.js.map +1 -1
  25. package/dist/detectors.d.ts +32 -0
  26. package/dist/detectors.js +279 -72
  27. package/dist/detectors.js.map +1 -1
  28. package/dist/git.d.ts +52 -0
  29. package/dist/git.js +166 -9
  30. package/dist/git.js.map +1 -1
  31. package/dist/githook.d.ts +18 -7
  32. package/dist/githook.js +147 -17
  33. package/dist/githook.js.map +1 -1
  34. package/dist/hook.d.ts +22 -2
  35. package/dist/hook.js +28 -3
  36. package/dist/hook.js.map +1 -1
  37. package/dist/index.js +14 -5
  38. package/dist/index.js.map +1 -1
  39. package/dist/mask-paths.d.ts +4 -3
  40. package/dist/mask-paths.js +4 -3
  41. package/dist/mask-paths.js.map +1 -1
  42. package/dist/parser.d.ts +58 -9
  43. package/dist/parser.js +337 -58
  44. package/dist/parser.js.map +1 -1
  45. package/dist/paths.d.ts +19 -1
  46. package/dist/paths.js +28 -3
  47. package/dist/paths.js.map +1 -1
  48. package/dist/redact.d.ts +2 -0
  49. package/dist/redact.js +956 -97
  50. package/dist/redact.js.map +1 -1
  51. package/dist/stage0.js +27 -8
  52. package/dist/stage0.js.map +1 -1
  53. package/dist/state.d.ts +15 -0
  54. package/dist/state.js +8 -0
  55. package/dist/state.js.map +1 -1
  56. package/dist/test/check.test.js +1 -1
  57. package/dist/test/check.test.js.map +1 -1
  58. package/dist/test/codex.test.js +27 -4
  59. package/dist/test/codex.test.js.map +1 -1
  60. package/dist/test/commit.test.js +1466 -6
  61. package/dist/test/commit.test.js.map +1 -1
  62. package/dist/test/e2e-harness.test.d.ts +1 -0
  63. package/dist/test/e2e-harness.test.js +53 -0
  64. package/dist/test/e2e-harness.test.js.map +1 -0
  65. package/dist/test/git.test.js +72 -2
  66. package/dist/test/git.test.js.map +1 -1
  67. package/dist/test/hook.test.js +138 -3
  68. package/dist/test/hook.test.js.map +1 -1
  69. package/dist/test/init.test.js +60 -1
  70. package/dist/test/init.test.js.map +1 -1
  71. package/dist/test/kimi-config.test.js +27 -5
  72. package/dist/test/kimi-config.test.js.map +1 -1
  73. package/dist/test/kimi-hook.test.js +1 -1
  74. package/dist/test/kimi-hook.test.js.map +1 -1
  75. package/dist/test/kimi-listing.test.js +42 -2
  76. package/dist/test/kimi-listing.test.js.map +1 -1
  77. package/dist/test/kimi.test.js +26 -2
  78. package/dist/test/kimi.test.js.map +1 -1
  79. package/dist/test/parser.test.js +527 -1
  80. package/dist/test/parser.test.js.map +1 -1
  81. package/dist/test/redact.test.js +2442 -14
  82. package/dist/test/redact.test.js.map +1 -1
  83. package/dist/test/stage0.test.js +617 -1
  84. package/dist/test/stage0.test.js.map +1 -1
  85. package/dist/test/sweep.test.js +99 -3
  86. package/dist/test/sweep.test.js.map +1 -1
  87. package/package.json +1 -1
  88. package/src/agents/claude.ts +3 -2
  89. package/src/agents/codex.ts +14 -5
  90. package/src/agents/index.ts +71 -16
  91. package/src/agents/kimi.ts +28 -8
  92. package/src/agents/types.ts +12 -3
  93. package/src/commands/commit.ts +354 -18
  94. package/src/commands/health.ts +1 -1
  95. package/src/commands/init.ts +37 -7
  96. package/src/commands/status.ts +9 -4
  97. package/src/commands/upload.ts +54 -54
  98. package/src/detectors.ts +284 -75
  99. package/src/git.ts +175 -9
  100. package/src/githook.ts +151 -19
  101. package/src/hook.ts +30 -3
  102. package/src/index.ts +15 -5
  103. package/src/mask-paths.ts +5 -4
  104. package/src/parser.ts +355 -51
  105. package/src/paths.ts +30 -3
  106. package/src/redact.ts +959 -100
  107. package/src/stage0.ts +28 -8
  108. package/src/state.ts +18 -0
@@ -4,7 +4,7 @@ import { drainAlerts, parkAlert } from "../alert.js";
4
4
  import { DEFAULT_API_BASE_URL, verifyToken } from "../api.js";
5
5
  import { readConfig, writeConfig } from "../config.js";
6
6
  import { presentAgents } from "../agents/index.js";
7
- import { GIT_HOOKS, gitHooksDir, installGitHook } from "../githook.js";
7
+ import { GIT_HOOKS, gitHooksDir, hooksLeftToTheUser, installGitHook } from "../githook.js";
8
8
  import { logLine } from "../log.js";
9
9
  import { awaitPairedKey, openPairing } from "../pairing.js";
10
10
  import type { Pairing } from "../pairing.js";
@@ -203,14 +203,44 @@ export async function runInit(options: { token?: string }, cwd: string): Promise
203
203
  if (gitHook === "not-a-repository") {
204
204
  console.log(`${cwd} is not a git repository, so no git hooks were added.`);
205
205
  } else {
206
- const names = GIT_HOOKS.map((hook) => hook.name).join(" and ");
206
+ const left = await hooksLeftToTheUser(cwd);
207
+ const names = GIT_HOOKS.filter((hook) => !left.some((other) => other.name === hook.name))
208
+ .map((hook) => hook.name)
209
+ .join(" and ");
207
210
  const where = await gitHooksDir(cwd);
208
- console.log(
209
- gitHook === "installed"
210
- ? `Added the ${names} hooks in ${where}`
211
- : `The ${names} hooks are already present in ${where}`,
212
- );
211
+ if (names) {
212
+ console.log(
213
+ gitHook === "installed"
214
+ ? `Added the ${names} ${left.length > 0 ? "hook" : "hooks"} in ${where}`
215
+ : `The ${names} ${left.length > 0 ? "hook is" : "hooks are"} already present in ${where}`,
216
+ );
217
+ }
218
+ for (const hook of left) {
219
+ console.log(
220
+ `The ${hook.name} hook in ${where} is not a shell script (${hook.language}), so isy left it as it was. ` +
221
+ `To send sessions from it, have it run this through sh:\n ${hook.command}`,
222
+ );
223
+ }
213
224
  }
214
225
 
215
226
  if (verified.githubLogin) console.log(`Signed in as ${verified.githubLogin}`);
227
+
228
+ // The hooks only send sessions. Nothing tells the server a pull request exists
229
+ // until the App is on its repository, and this machine cannot see whether it
230
+ // is, so without this line the silence that follows explains itself to nobody.
231
+ // The docs page rather than the App's own address: a published CLI cannot
232
+ // follow a rename. No CLI hooked means no session, and nothing to go on to yet.
233
+ if (agents.length > 0) {
234
+ console.log(
235
+ [
236
+ "",
237
+ "Next:",
238
+ " 1. Install the GitHub App on the repositories you want analysed, if it is not there yet:",
239
+ ` ${new URL("/docs/github-app", baseUrl)}`,
240
+ " Without it sessions upload, but no pull request ever gets a comment.",
241
+ " 2. Work with your agent as usual and commit. The hooks send the session.",
242
+ " 3. Push and open a pull request. The analysis arrives as one comment on it.",
243
+ ].join("\n"),
244
+ );
245
+ }
216
246
  }
@@ -3,7 +3,7 @@ import { series } from "./check.js";
3
3
  import type { AgentId } from "../agents/index.js";
4
4
  import { DEFAULT_API_BASE_URL } from "../api.js";
5
5
  import { readConfig } from "../config.js";
6
- import { gitHookInstalled, gitHooksDir } from "../githook.js";
6
+ import { gitHookInstalled, gitHooksDir, hooksLeftToTheUser } from "../githook.js";
7
7
  import { packageVersion, projectSlug } from "../paths.js";
8
8
  import { countQueue } from "../queue.js";
9
9
  import { updateNotice } from "../update.js";
@@ -56,6 +56,8 @@ export interface StatusReport {
56
56
  sessions: number;
57
57
  /** The per-repository git hooks that start the fast loop. */
58
58
  gitHook: "installed" | "missing" | "not-a-repository";
59
+ /** Hooks written in another language: they take no block, and `isy init` says what to add. */
60
+ gitHooksLeft: string[];
59
61
  };
60
62
  agents: AgentSessions[];
61
63
  /** The newest session for this directory, whichever CLI produced it. */
@@ -139,6 +141,7 @@ export async function collectStatus(cwd: string): Promise<StatusReport> {
139
141
  slug: projectSlug(cwd),
140
142
  sessions: agents.reduce((total, entry) => total + entry.sessions, 0),
141
143
  gitHook,
144
+ gitHooksLeft: (await hooksLeftToTheUser(cwd)).map((hook) => hook.name),
142
145
  },
143
146
  agents,
144
147
  latestSession: newest,
@@ -181,9 +184,11 @@ export function formatStatus(report: StatusReport): string {
181
184
  lines.push(
182
185
  row(
183
186
  "git hooks",
184
- report.project.gitHook === "installed"
185
- ? "installed"
186
- : "missing — run isy init here to analyse on every commit and push",
187
+ report.project.gitHook !== "installed"
188
+ ? "missing — run isy init here to analyse on every commit and push"
189
+ : report.project.gitHooksLeft.length > 0
190
+ ? `installed, except ${series(report.project.gitHooksLeft)}: not a shell script, isy init says what to add`
191
+ : "installed",
187
192
  ),
188
193
  );
189
194
  }
@@ -1,4 +1,4 @@
1
- import { detectAgent, presentAgents } from "../agents/index.js";
1
+ import { detectAgent, presentAgents, sessionsInTree } from "../agents/index.js";
2
2
  import type { Agent, AgentId, HookInput } from "../agents/index.js";
3
3
  import { DEFAULT_API_BASE_URL, buildTranscriptFields, uploadSession } from "../api.js";
4
4
  import type { ApiOptions, UploadPayload } from "../api.js";
@@ -7,9 +7,9 @@ import { collectGitMetadata } from "../git.js";
7
7
  import { autoInstallGitHook } from "../githook.js";
8
8
  import type { GitMetadata, GitResult } from "../git.js";
9
9
  import type { DiscoveredSession, IsyConfig } from "../types.js";
10
- import { logError, logLine } from "../log.js";
10
+ import { errorMessage, logError, logLine } from "../log.js";
11
11
  import { parseLines } from "../parser.js";
12
- import { packageVersion } from "../paths.js";
12
+ import { SWEEP_WINDOW_MS, packageVersion } from "../paths.js";
13
13
  import {
14
14
  MAX_ATTEMPTS,
15
15
  abandon,
@@ -24,7 +24,7 @@ import {
24
24
  import { updateNotice } from "../update.js";
25
25
  import { planNotice } from "../plan.js";
26
26
  import type { PlanStatus } from "../plan.js";
27
- import { looksUnchanged, readState, updateSession } from "../state.js";
27
+ import { looksUnchanged, namedBranch, readState, updateSession } from "../state.js";
28
28
  import { sessionFingerprint } from "../subagents.js";
29
29
  import type { ClientState, CommitMark } from "../state.js";
30
30
 
@@ -46,10 +46,14 @@ export interface UploadReport {
46
46
  updateNotice?: string;
47
47
  /** What a SessionEnd run did about this repository's git hooks, when it did anything. */
48
48
  gitHook?: "installed" | "shared-hooks";
49
+ /** Which repository, as owner/name: the line is parked, and read wherever the next session starts. */
50
+ gitHookRepository?: string;
49
51
  /** Set when the plan has nothing left: the next pull request will not be analysed. */
50
52
  planNotice?: string;
51
53
  /** Sessions a sweep looked at, across every CLI and every directory. */
52
54
  scanned?: number;
55
+ /** Sessions left out because their transcript could not be read. */
56
+ unreadable?: number;
53
57
  /** The server's hourly upload allowance ran out; nothing was lost by it. */
54
58
  throttled?: boolean;
55
59
  /** Why the server refused the key. Nothing was lost by that either. */
@@ -89,7 +93,7 @@ export async function buildPayload(
89
93
  git: GitMetadata,
90
94
  options: { extraPatterns?: readonly string[]; cwd?: string; commits?: CommitMark[] },
91
95
  fallbackSessionId: string,
92
- ): Promise<UploadPayload | undefined> {
96
+ ): Promise<{ payload: UploadPayload; gitBranch?: string } | undefined> {
93
97
  // Whatever the CLI's native format, this comes back Claude-record shaped:
94
98
  // the server re-parses the upload with the same parseLines (cascade.ts).
95
99
  const lines = await agent.redactedLines(transcriptPath, options);
@@ -102,16 +106,19 @@ export async function buildPayload(
102
106
  const now = new Date().toISOString();
103
107
 
104
108
  return {
105
- sessionId: session.sessionId ?? fallbackSessionId,
106
- agent: agent.id,
107
- contentHash,
108
- startedAt: session.meta.startedAt ?? now,
109
- endedAt: session.meta.endedAt ?? now,
110
- claudeVersion: session.meta.claudeVersion ?? "unknown",
111
- isyVersion: await packageVersion(),
112
- git,
113
- transcript,
114
- ...(options.commits && options.commits.length > 0 ? { commits: options.commits } : {}),
109
+ gitBranch: session.meta.gitBranch,
110
+ payload: {
111
+ sessionId: session.sessionId ?? fallbackSessionId,
112
+ agent: agent.id,
113
+ contentHash,
114
+ startedAt: session.meta.startedAt ?? now,
115
+ endedAt: session.meta.endedAt ?? now,
116
+ claudeVersion: session.meta.claudeVersion ?? "unknown",
117
+ isyVersion: await packageVersion(),
118
+ git,
119
+ transcript,
120
+ ...(options.commits && options.commits.length > 0 ? { commits: options.commits } : {}),
121
+ },
115
122
  };
116
123
  }
117
124
 
@@ -185,15 +192,16 @@ interface Target {
185
192
  /** Set when the target came from a scan, which already knows size and mtime. */
186
193
  file?: DiscoveredSession;
187
194
  /**
188
- * Where this session ran. Only a sweep sets it: every other path knows the
189
- * directory before it knows the session, because a hook named it.
195
+ * Where this session ran, when finding it took reading that: a sweep, or a
196
+ * session from elsewhere in the tree. Every other path knows the directory
197
+ * before it knows the session, because a hook named it.
190
198
  */
191
199
  cwd?: string;
192
200
  }
193
201
 
194
202
  /**
195
- * Every session recorded for this directory whose bytes are not already on the
196
- * server, across every CLI installed here.
203
+ * Every session of this work tree whose bytes are not already on the server,
204
+ * across every CLI installed here.
197
205
  *
198
206
  * Size and mtime both matching the last accepted upload means the content
199
207
  * matches, so an unchanged transcript is never read — and a session that ended
@@ -203,29 +211,15 @@ async function changedSessions(cwd: string, state: ClientState): Promise<Target[
203
211
  const targets: Target[] = [];
204
212
 
205
213
  for (const agent of await presentAgents()) {
206
- for (const file of await agent.sessionsIn(cwd)) {
214
+ for await (const file of sessionsInTree(agent, cwd)) {
207
215
  if (looksUnchanged(state[file.path] ?? {}, file)) continue;
208
- targets.push({ agent, path: file.path, file });
216
+ targets.push({ agent, path: file.path, file, cwd: file.cwd });
209
217
  }
210
218
  }
211
219
 
212
220
  return targets;
213
221
  }
214
222
 
215
- /**
216
- * How far back a sweep looks. A sweep has no baseline to start from — every
217
- * session it has never seen reads as changed — so without a window the first
218
- * one on a machine would upload years of transcripts from every directory the
219
- * CLI was ever used in. Nothing older than this can reach an analysis anyway:
220
- * sessions are matched to a pull request by commit SHA, and a transcript
221
- * untouched for a fortnight belongs to commits that were pushed long ago.
222
- *
223
- * ponytail: a fixed window, not a high-water mark. A machine that was offline
224
- * longer than this loses the tail; move the boundary to a `lastSweepAt` in the
225
- * config if that ever happens to anyone.
226
- */
227
- const SWEEP_WINDOW_MS = 14 * 24 * 60 * 60 * 1000;
228
-
229
223
  /**
230
224
  * Every recently changed session on this machine, whatever directory it ran in.
231
225
  *
@@ -267,7 +261,7 @@ async function sweptSessions(state: ClientState, report: UploadReport): Promise<
267
261
  // Counted, not listed. A sweep runs at every session start and the same
268
262
  // sessions are skipped every time; one line each would push everything worth
269
263
  // reading out of the journal `isy health` shows.
270
- if (rootless > 0) logLine(`upload: ${rootless} swept session(s) record no working directory`);
264
+ if (rootless > 0) logLine(`upload: ${rootless} swept session(s) record no working directory, or cannot be read`);
271
265
 
272
266
  // Smallest first. The run budget is checked between sessions, and the session
273
267
  // still open in the CLI that started this sweep is the biggest and always reads
@@ -299,20 +293,21 @@ async function sendOne(
299
293
  fallbackSessionId: string,
300
294
  report: UploadReport,
301
295
  ): Promise<void> {
302
- const payload = await buildPayload(
296
+ const built = await buildPayload(
303
297
  target.agent,
304
298
  target.path,
305
299
  git,
306
300
  {
307
301
  extraPatterns: config.extraRedactPatterns,
308
302
  // A swept session ran where the transcript says it ran, not where this
309
- // process happens to stand: masking is rooted on it.
303
+ // process happens to stand: masking starts from it.
310
304
  cwd: target.cwd ?? workingDir,
311
305
  commits: state[target.path]?.commits,
312
306
  },
313
307
  fallbackSessionId,
314
308
  );
315
- if (!payload) return;
309
+ if (!built) return;
310
+ const { payload, gitBranch } = built;
316
311
 
317
312
  if (await isAbandoned(payload.sessionId, payload.contentHash)) {
318
313
  report.skipped = `session ${payload.sessionId} was given up on after ${MAX_ATTEMPTS} attempts`;
@@ -334,6 +329,7 @@ async function sendOne(
334
329
  ...current,
335
330
  uploadedHash: payload.contentHash,
336
331
  uploadedCommit: payload.commits?.at(-1)?.sha,
332
+ branch: namedBranch(current.branch, gitBranch, git.branch),
337
333
  ...seen,
338
334
  }));
339
335
  await updateConfig({ lastUploadAt: new Date().toISOString() });
@@ -467,6 +463,8 @@ export async function runUpload(
467
463
  const outcome = await autoInstallGitHook(workingDir);
468
464
  if (outcome === "installed" || outcome === "shared-hooks") {
469
465
  report.gitHook = outcome;
466
+ const git = await gitFor(workingDir);
467
+ report.gitHookRepository = git.ok ? git.metadata.remote : workingDir;
470
468
  logLine(`upload: git hooks ${outcome} in ${workingDir}`);
471
469
  }
472
470
  } catch (error) {
@@ -496,19 +494,20 @@ export async function runUpload(
496
494
  continue;
497
495
  }
498
496
 
499
- await sendOne(
500
- target,
501
- git.metadata,
502
- state,
503
- config,
504
- api,
505
- workingDir,
506
- // Per target, not per run: a run covers many sessions, and one fallback
507
- // shared between them would file them all under the same id — which the
508
- // server keys on, so each would replace the last.
509
- target.file?.sessionId ?? hook?.session_id ?? "unknown",
510
- report,
511
- );
497
+ // Per target, not per run: a run covers many sessions, and one fallback
498
+ // shared between them would file them all under the same id — which the
499
+ // server keys on, so each would replace the last.
500
+ const sessionId = target.file?.sessionId ?? hook?.session_id ?? "unknown";
501
+ try {
502
+ await sendOne(target, git.metadata, state, config, api, workingDir, sessionId, report);
503
+ } catch (error) {
504
+ // A `sudo` session's, owned by root, one deleted since the listing, or one
505
+ // redaction throws on. That says nothing about the sessions behind it or the
506
+ // queue, which still go out. It fails again at every run, so the journal gets
507
+ // one reason a run, not a line a file.
508
+ if (!report.unreadable) logError(`upload: ${sessionId} could not be read or sent: ${errorMessage(error)}`);
509
+ report.unreadable = (report.unreadable ?? 0) + 1;
510
+ }
512
511
  }
513
512
 
514
513
  if (outside > 0) logLine(`upload: ${outside} changed session(s) ran outside a repository`);
@@ -533,6 +532,7 @@ export function formatUploadReport(report: UploadReport): string {
533
532
  if (report.queued > 0) parts.push("session queued for retry");
534
533
  if (report.drained > 0) parts.push(`${report.drained} queued session(s) sent`);
535
534
  if (report.abandoned > 0) parts.push(`${report.abandoned} session(s) given up on`);
535
+ if (report.unreadable) parts.push(`${report.unreadable} session(s) could not be read, see isy health`);
536
536
 
537
537
  const line = parts.length > 0 ? `isy: ${parts.join(", ")}` : "isy: nothing to upload";
538
538
  // Its own line rather than another clause: this one is about the account, and
@@ -562,9 +562,9 @@ export function formatUploadAlert(report: UploadReport): string | undefined {
562
562
  if (report.throttled) parts.push("rate limited, the rest upload on the next run");
563
563
  if (report.unauthorized) parts.push(report.unauthorized);
564
564
  if (report.abandoned > 0) parts.push(`${report.abandoned} session(s) given up on`);
565
- if (report.gitHook === "installed") parts.push("commit and push hooks added to this repository");
565
+ if (report.gitHook === "installed") parts.push(`commit and push hooks added to ${report.gitHookRepository}`);
566
566
  if (report.gitHook === "shared-hooks") {
567
- parts.push("no git hooks here: they live in a shared directory, run isy init to add them");
567
+ parts.push(`no git hooks in ${report.gitHookRepository}: they live in a shared directory, run isy init there to add them`);
568
568
  }
569
569
  if (report.planNotice) parts.push(report.planNotice);
570
570
  if (report.updateNotice) parts.push(report.updateNotice);