@nightloom/isy 1.0.7 → 1.0.8-next.1

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.
@@ -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, hooksLeftToTheUser } from "../githook.js";
6
+ import { gitHookState, 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";
@@ -55,7 +55,7 @@ export interface StatusReport {
55
55
  /** Across every CLI installed here. */
56
56
  sessions: number;
57
57
  /** The per-repository git hooks that start the fast loop. */
58
- gitHook: "installed" | "missing" | "not-a-repository";
58
+ gitHook: "installed" | "missing" | "not-executable" | "not-a-repository";
59
59
  /** Hooks written in another language: they take no block, and `isy init` says what to add. */
60
60
  gitHooksLeft: string[];
61
61
  };
@@ -116,11 +116,7 @@ export async function collectStatus(cwd: string): Promise<StatusReport> {
116
116
  : undefined;
117
117
 
118
118
  const gitHook: StatusReport["project"]["gitHook"] =
119
- (await gitHooksDir(cwd)) === undefined
120
- ? "not-a-repository"
121
- : (await gitHookInstalled(cwd))
122
- ? "installed"
123
- : "missing";
119
+ (await gitHooksDir(cwd)) === undefined ? "not-a-repository" : await gitHookState(cwd);
124
120
 
125
121
  const newest = agents
126
122
  .map((entry) => entry.latest)
@@ -184,11 +180,13 @@ export function formatStatus(report: StatusReport): string {
184
180
  lines.push(
185
181
  row(
186
182
  "git hooks",
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",
183
+ report.project.gitHook === "not-executable"
184
+ ? "not executable, so git skips them — run isy init here"
185
+ : report.project.gitHook !== "installed"
186
+ ? "missing — run isy init here to analyse on every commit and push"
187
+ : report.project.gitHooksLeft.length > 0
188
+ ? `installed, except ${series(report.project.gitHooksLeft)}: not a shell script, isy init says what to add`
189
+ : "installed",
192
190
  ),
193
191
  );
194
192
  }
@@ -56,6 +56,8 @@ export interface UploadReport {
56
56
  scanned?: number;
57
57
  /** Sessions left out because their transcript could not be read. */
58
58
  unreadable?: number;
59
+ /** Sessions a backfill left out: which branch they worked on is not known here. */
60
+ unplaced?: number;
59
61
  /** The server's hourly upload allowance ran out; nothing was lost by it. */
60
62
  throttled?: boolean;
61
63
  /** Why the server refused the key. Nothing was lost by that either. */
@@ -216,7 +218,9 @@ async function changedSessions(cwd: string, state: ClientState, since?: number):
216
218
  for await (const file of sessionsInTree(agent, cwd)) {
217
219
  // Newest first, so the first one older than the date ends the list.
218
220
  if (since !== undefined && lastActive(file) < since) break;
219
- if (looksUnchanged(state[file.path] ?? {}, file)) continue;
221
+ const known = state[file.path] ?? {};
222
+ // A backfill also sends again what went up under another branch than its own.
223
+ if (looksUnchanged(known, file) && (since === undefined || known.uploadedBranch === known.branch)) continue;
220
224
  targets.push({ agent, path: file.path, file, cwd: file.cwd });
221
225
  }
222
226
  }
@@ -296,6 +300,7 @@ async function sendOne(
296
300
  workingDir: string,
297
301
  fallbackSessionId: string,
298
302
  report: UploadReport,
303
+ ownGit?: (branch: string) => Promise<GitResult>,
299
304
  ): Promise<void> {
300
305
  const built = await buildPayload(
301
306
  target.agent,
@@ -313,6 +318,19 @@ async function sendOne(
313
318
  if (!built) return;
314
319
  const { payload, gitBranch } = built;
315
320
 
321
+ // A backfill runs wherever it is typed, and the checkout's branch and HEAD say
322
+ // nothing about a session long over: the pull request they lead to is someone
323
+ // else's. Each goes up on its own branch, or not at all.
324
+ if (ownGit) {
325
+ const branch = namedBranch(state[target.path]?.branch, gitBranch);
326
+ const own = branch === undefined ? undefined : await ownGit(branch);
327
+ if (!own?.ok) {
328
+ report.unplaced = (report.unplaced ?? 0) + 1;
329
+ return;
330
+ }
331
+ payload.git = { ...own.metadata, own: true };
332
+ }
333
+
316
334
  if (await isAbandoned(payload.sessionId, payload.contentHash)) {
317
335
  report.skipped = `session ${payload.sessionId} was given up on after ${MAX_ATTEMPTS} attempts`;
318
336
  logError(`upload: ${report.skipped}`);
@@ -333,7 +351,8 @@ async function sendOne(
333
351
  ...current,
334
352
  uploadedHash: payload.contentHash,
335
353
  uploadedCommit: payload.commits?.at(-1)?.sha,
336
- branch: namedBranch(current.branch, gitBranch, git.branch),
354
+ uploadedBranch: payload.git.branch,
355
+ branch: namedBranch(current.branch, gitBranch, payload.git.branch),
337
356
  ...seen,
338
357
  }));
339
358
  await updateConfig({ lastUploadAt: new Date().toISOString() });
@@ -373,6 +392,7 @@ async function passOver(target: Target, payload: UploadPayload): Promise<void> {
373
392
  ...current,
374
393
  rejectedHash: payload.contentHash,
375
394
  uploadedCommit: payload.commits?.at(-1)?.sha,
395
+ uploadedBranch: payload.git.branch,
376
396
  ...seen,
377
397
  }));
378
398
  }
@@ -437,13 +457,14 @@ export async function runUpload(
437
457
  return report;
438
458
  }
439
459
 
440
- // One git call per directory, however many sessions ran in it.
460
+ // One git call per directory, however many sessions ran in it, and per branch.
441
461
  const repositories = new Map<string, GitResult>();
442
- const gitFor = async (directory: string): Promise<GitResult> => {
443
- const known = repositories.get(directory);
462
+ const gitFor = async (directory: string, branch?: string): Promise<GitResult> => {
463
+ const key = `${directory}\0${branch ?? ""}`;
464
+ const known = repositories.get(key);
444
465
  if (known) return known;
445
- const result = await collectGitMetadata(directory);
446
- repositories.set(directory, result);
466
+ const result = await collectGitMetadata(directory, branch);
467
+ repositories.set(key, result);
447
468
  return result;
448
469
  };
449
470
 
@@ -506,7 +527,8 @@ export async function runUpload(
506
527
  // server keys on, so each would replace the last.
507
528
  const sessionId = target.file?.sessionId ?? hook?.session_id ?? "unknown";
508
529
  try {
509
- await sendOne(target, git.metadata, state, config, api, workingDir, sessionId, report);
530
+ const ownGit = options.since === undefined ? undefined : (branch: string) => gitFor(target.cwd ?? workingDir, branch);
531
+ await sendOne(target, git.metadata, state, config, api, workingDir, sessionId, report, ownGit);
510
532
  } catch (error) {
511
533
  // A `sudo` session's, owned by root, one deleted since the listing, or one
512
534
  // redaction throws on. That says nothing about the sessions behind it or the
@@ -518,6 +540,7 @@ export async function runUpload(
518
540
  }
519
541
 
520
542
  if (outside > 0) logLine(`upload: ${outside} changed session(s) ran outside a repository`);
543
+ if (report.unplaced) logLine(`upload: ${report.unplaced} session(s) left out, on no branch known here`);
521
544
 
522
545
  // "Nothing new to analyse" only when every session sent was already known.
523
546
  report.deduplicated = report.sent > 0 && report.fresh === 0;
@@ -540,6 +563,7 @@ export function formatUploadReport(report: UploadReport): string {
540
563
  if (report.drained > 0) parts.push(`${report.drained} queued session(s) sent`);
541
564
  if (report.abandoned > 0) parts.push(`${report.abandoned} session(s) given up on`);
542
565
  if (report.unreadable) parts.push(`${report.unreadable} session(s) could not be read, see isy health`);
566
+ if (report.unplaced) parts.push(`${report.unplaced} session(s) left out: which branch they worked on is not known here`);
543
567
 
544
568
  const line = parts.length > 0 ? `isy: ${parts.join(", ")}` : "isy: nothing to upload";
545
569
  // Its own line rather than another clause: this one is about the account, and
package/src/git.ts CHANGED
@@ -13,6 +13,11 @@ export interface GitMetadata {
13
13
  branch: string;
14
14
  headSha: string;
15
15
  recentShas: string[];
16
+ /**
17
+ * Set by a backfill alone: the branch and head are the session's own, not the
18
+ * checkout's, so the server may file a session it already holds under them.
19
+ */
20
+ own?: true;
16
21
  }
17
22
 
18
23
  export type GitFailure = "not-a-repository" | "no-commits" | "no-remote";
@@ -77,22 +82,30 @@ async function headName(cwd: string): Promise<string | undefined> {
77
82
  return (await git(cwd, ["rev-parse", "--symbolic-full-name", "HEAD"]))?.replace(/^refs\/heads\//, "");
78
83
  }
79
84
 
80
- export async function collectGitMetadata(cwd: string): Promise<GitResult> {
85
+ /**
86
+ * Where the checkout stands, or with `branch` where that branch stands: in this
87
+ * clone, or as origin last showed it once it is deleted here.
88
+ */
89
+ export async function collectGitMetadata(cwd: string, branch?: string): Promise<GitResult> {
81
90
  const insideWorkTree = await git(cwd, ["rev-parse", "--is-inside-work-tree"]);
82
91
  if (insideWorkTree !== "true") return { ok: false, reason: "not-a-repository" };
83
92
 
84
- const headSha = await git(cwd, ["rev-parse", "HEAD"]);
93
+ const headSha =
94
+ branch === undefined
95
+ ? await git(cwd, ["rev-parse", "HEAD"])
96
+ : ((await git(cwd, ["rev-parse", "--verify", "-q", `refs/heads/${branch}^{commit}`])) ??
97
+ (await git(cwd, ["rev-parse", "--verify", "-q", `refs/remotes/origin/${branch}^{commit}`])));
85
98
  if (!headSha) return { ok: false, reason: "no-commits" };
86
99
 
87
100
  const remoteUrl = await git(cwd, ["config", "--get", "remote.origin.url"]);
88
101
  const remote = remoteUrl ? normalizeRemote(remoteUrl) : undefined;
89
102
  if (!remote) return { ok: false, reason: "no-remote" };
90
103
 
91
- const branch = (await headName(cwd)) ?? "HEAD";
92
- const log = await git(cwd, ["log", "--format=%H", "-n", String(RECENT_SHA_COUNT)]);
104
+ const name = branch ?? (await headName(cwd)) ?? "HEAD";
105
+ const log = await git(cwd, ["log", "--format=%H", "-n", String(RECENT_SHA_COUNT), ...(branch === undefined ? [] : [headSha, "--"])]);
93
106
  const recentShas = log ? log.split("\n").map((line) => line.trim()).filter(Boolean) : [headSha];
94
107
 
95
- return { ok: true, metadata: { remote, branch, headSha, recentShas } };
108
+ return { ok: true, metadata: { remote, branch: name, headSha, recentShas } };
96
109
  }
97
110
 
98
111
  /**
package/src/githook.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { execFile } from "node:child_process";
2
- import { chmod, lstat, mkdir, readFile, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
2
+ import { constants } from "node:fs";
3
+ import { access, chmod, lstat, mkdir, readFile, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
3
4
  import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
4
5
  import { promisify } from "node:util";
5
6
  import { workTreeTop } from "./git.js";
@@ -87,6 +88,14 @@ function takesBlock(contents: string): boolean {
87
88
  return program === undefined || /^(?:a|ba|da|k|mk|pdk|y|z)?sh\d*$/.test(program);
88
89
  }
89
90
 
91
+ /**
92
+ * A shebang saved with CRLF names an interpreter called "sh\r": git cannot run
93
+ * the hook, and no line of it has run since it was saved that way.
94
+ */
95
+ function carriageReturn(contents: string): boolean {
96
+ return /^#![^\n]*\r\n/.test(contents);
97
+ }
98
+
90
99
  /**
91
100
  * Where a new block goes: straight after the shebang, ahead of whatever the
92
101
  * user's own script does.
@@ -179,19 +188,45 @@ function withoutBlock(contents: string, existing: string): string {
179
188
  return contents.slice(0, start) + contents.slice(contents[stop] === "\n" ? stop + 1 : stop);
180
189
  }
181
190
 
182
- async function oneInstalled(cwd: string, hook: { name: string; command: string }): Promise<boolean> {
191
+ /** Git skips a hook it cannot execute, with a hint to whoever commits, and runs nothing in it. */
192
+ async function executable(path: string): Promise<boolean> {
193
+ try {
194
+ await access(path, constants.X_OK);
195
+ return true;
196
+ } catch {
197
+ return false;
198
+ }
199
+ }
200
+
201
+ async function oneState(
202
+ cwd: string,
203
+ hook: { name: string; command: string },
204
+ ): Promise<"installed" | "missing" | "not-executable"> {
183
205
  const path = await hookPath(cwd, hook.name);
184
- if (!path) return false;
206
+ if (!path) return "missing";
185
207
  const contents = await readHook(path);
186
- if (contents === undefined) return false;
208
+ if (contents === undefined) return "missing";
187
209
  // Nothing is missing from a hook that takes no block, and `isy init` cannot add it.
188
- return existingBlock(contents) === (takesBlock(contents) ? block(hook.command) : undefined);
210
+ if (!takesBlock(contents)) return existingBlock(contents) === undefined ? "installed" : "missing";
211
+ // A hook git will not execute is not installed, whatever the file says.
212
+ if (existingBlock(contents) !== undefined && carriageReturn(contents)) return "not-executable";
213
+ if (existingBlock(contents) !== block(hook.command)) return "missing";
214
+ return (await executable(path)) ? "installed" : "not-executable";
215
+ }
216
+
217
+ /** "installed" only with every hook in place and run by git: half-wired is not installed. */
218
+ export async function gitHookState(cwd: string): Promise<"installed" | "missing" | "not-executable"> {
219
+ let state: "installed" | "not-executable" = "installed";
220
+ for (const hook of GIT_HOOKS) {
221
+ const one = await oneState(cwd, hook);
222
+ if (one === "missing") return one;
223
+ if (one === "not-executable") state = one;
224
+ }
225
+ return state;
189
226
  }
190
227
 
191
- /** True only with every hook in place: half-wired is not installed. */
192
228
  export async function gitHookInstalled(cwd: string): Promise<boolean> {
193
- for (const hook of GIT_HOOKS) if (!(await oneInstalled(cwd, hook))) return false;
194
- return true;
229
+ return (await gitHookState(cwd)) === "installed";
195
230
  }
196
231
 
197
232
  /** The hooks that take no block, and what each would have to run: wiring them is the user's to do. */
@@ -235,13 +270,16 @@ async function installOne(
235
270
  return "not-shell";
236
271
  }
237
272
 
238
- if (existing === desired) {
273
+ if (existing === desired && !carriageReturn(contents)) {
239
274
  // A hook git will not execute is not installed, whatever the file says.
240
275
  await chmod(path, 0o755);
241
276
  return "already-present";
242
277
  }
243
278
 
244
- const next = existing === undefined ? insert(contents, desired) : contents.replace(existing, desired);
279
+ // A hook git cannot run goes back to LF whole: the user's lines were not running either.
280
+ const text = carriageReturn(contents) ? contents.replace(/\r\n/g, "\n") : contents;
281
+ const old = existingBlock(text);
282
+ const next = old === undefined ? insert(text, desired) : text.replace(old, desired);
245
283
 
246
284
  await replaceHook(path, next);
247
285
  await chmod(path, 0o755);
@@ -317,11 +355,13 @@ async function linkedIntoTree(path: string, gitDir: string): Promise<boolean> {
317
355
  }
318
356
 
319
357
  /**
320
- * Bring the blocks an older isy wrote up to date where they stand, adding none:
321
- * what every run from a hook does first, so that an upgrade reaches a repository
322
- * the next time anything happens in it, with no `isy init` to go through. A block
323
- * that is only old waits in a shared file. One that breaks its hook comes out
324
- * wherever it is: the file goes back to what the user had, and a push stops failing.
358
+ * Bring the blocks an older isy wrote up to date where they stand, and the files
359
+ * git will not execute back to executable, adding none: what every run from a hook
360
+ * does first, so that an upgrade reaches a repository the next time anything
361
+ * happens in it, with no `isy init` to go through. A block that is only old, or
362
+ * only not executable, waits in a shared file: git tracks a file's mode too. One
363
+ * that breaks its hook comes out wherever it is: the file goes back to what the
364
+ * user had, and a push stops failing.
325
365
  */
326
366
  export async function repairGitHook(cwd: string): Promise<void> {
327
367
  const location = await hookLocation(cwd);
@@ -333,9 +373,11 @@ export async function repairGitHook(cwd: string): Promise<void> {
333
373
  if (contents === undefined) continue;
334
374
  const existing = existingBlock(contents);
335
375
  if (existing === undefined) continue;
336
- const old =
337
- existing !== block(hook.command) && !isShared(location) && !(await linkedIntoTree(path, location.gitDir));
338
- if (old || !takesBlock(contents)) await installOne(cwd, hook);
376
+ const stale =
377
+ (existing !== block(hook.command) || !(await executable(path)) || carriageReturn(contents)) &&
378
+ !isShared(location) &&
379
+ !(await linkedIntoTree(path, location.gitDir));
380
+ if (stale || !takesBlock(contents)) await installOne(cwd, hook);
339
381
  }
340
382
  }
341
383
 
package/src/parser.ts CHANGED
@@ -78,8 +78,9 @@ interface ParseState {
78
78
  thinkingBlocks: number;
79
79
  hiddenThinkingBlocks: number;
80
80
  editToolUses: number;
81
- shellWrote: boolean;
82
- /** A call the parser cannot see into that could have written a file (`mayWrite`). */
81
+ /** Calls that could have written a file: an edit, a shell write, one the parser cannot see into (`mayWrite`). */
82
+ writers: ToolUse[];
83
+ /** A line the parser could not read, which could have held any call. */
83
84
  opaqueWrite: boolean;
84
85
  /** A subagent's result says it edited files, whether or not its own records came along. */
85
86
  delegatedEdits: boolean;
@@ -116,7 +117,7 @@ function createState(): ParseState {
116
117
  thinkingBlocks: 0,
117
118
  hiddenThinkingBlocks: 0,
118
119
  editToolUses: 0,
119
- shellWrote: false,
120
+ writers: [],
120
121
  opaqueWrite: false,
121
122
  delegatedEdits: false,
122
123
  delegated: new Set(),
@@ -818,6 +819,7 @@ function pushToolUse(
818
819
 
819
820
  if (EDIT_TOOLS.has(name)) {
820
821
  state.editToolUses += 1;
822
+ state.writers.push(use);
821
823
  pushFileEdits(state, use);
822
824
  }
823
825
  if (LOOKUP_TOOLS.has(name)) pushLookup(state, use);
@@ -825,17 +827,17 @@ function pushToolUse(
825
827
  const { command } = use.input;
826
828
  if (command.length <= COMMAND_CHARS && spend(state.shell, command.length)) {
827
829
  for (const path of shellReadPaths(command, state.shell)) state.filesRead.add(path);
828
- if (shellWrites(command)) state.shellWrote = true;
830
+ if (shellWrites(command)) state.writers.push(use);
829
831
  pushShellEdits(state, use, command, record.cwd);
830
832
  } else {
831
833
  // Not read, which does not say nothing was written. The call keeps no command,
832
834
  // so that nothing after this reads it either.
833
- state.opaqueWrite = true;
835
+ state.writers.push(use);
834
836
  use.input = {};
835
837
  }
836
838
  }
837
839
 
838
- if (mayWrite(name, use.input)) state.opaqueWrite = true;
840
+ if (mayWrite(name, use.input)) state.writers.push(use);
839
841
  }
840
842
 
841
843
  function pushBlocks(state: ParseState, record: TranscriptRecord, recordIndex: number): void {
@@ -909,10 +911,11 @@ const DELEGATION_TOOLS = new Set(["Agent", "Task", "AgentSwarm", "TowerSpawn"]);
909
911
  * the file gone — carries nothing else of it. What it did cannot be seen, so
910
912
  * it may have edited. A call that failed started nothing.
911
913
  */
912
- function delegatedUnseen(state: ParseState): boolean {
914
+ function delegatedUnseen(state: ParseState, stop: number): boolean {
913
915
  return state.toolUses.some(
914
916
  (use) =>
915
917
  DELEGATION_TOOLS.has(use.name) &&
918
+ ran(use, stop) &&
916
919
  use.result?.isError !== true &&
917
920
  !state.delegated.has(use.id) &&
918
921
  !state.counted.has(use.id),
@@ -924,11 +927,12 @@ function delegatedUnseen(state: ParseState): boolean {
924
927
  * files got there, and a formatter, a generator or a script writes nothing
925
928
  * `shellWrites` can read. A call that failed committed nothing.
926
929
  */
927
- function committedFromShell(state: ParseState): boolean {
930
+ function committedFromShell(state: ParseState, stop: number): boolean {
928
931
  return state.toolUses.some((use) => {
929
932
  const { command } = use.input;
930
933
  return (
931
934
  use.name === "Bash" &&
935
+ ran(use, stop) &&
932
936
  typeof command === "string" &&
933
937
  use.result?.isError !== true &&
934
938
  gitCommands(command).includes("commit")
@@ -936,6 +940,33 @@ function committedFromShell(state: ParseState): boolean {
936
940
  });
937
941
  }
938
942
 
943
+ /**
944
+ * Where the session last stopped: Claude Code writes `cost-state` when a turn ends
945
+ * and when it exits. A subagent's record never is one.
946
+ */
947
+ function lastStop(records: TranscriptRecord[]): number {
948
+ for (let i = records.length - 1; i >= 0; i -= 1) {
949
+ if (records[i]!.type === "cost-state" && records[i]!.isSidechain !== true) return i;
950
+ }
951
+ return -1;
952
+ }
953
+
954
+ /**
955
+ * Whether a call ran, or may still be running. One with no result is taken as
956
+ * running — `isy commit` reads the session from inside its `git commit`, and the
957
+ * sweep uploads a session in the middle of a call — unless the session stopped
958
+ * after it: no call it ran stays open across a stop, and a session killed at a
959
+ * permission prompt leaves exactly that behind. A subagent can go on working past
960
+ * its session's turn, so its calls are not judged by the session's stops.
961
+ *
962
+ * ponytail: a call killed while it ran leaves the same trace and reads as never
963
+ * run, as nothing in the transcript tells the two apart. Look again if Claude Code
964
+ * starts recording when a call starts.
965
+ */
966
+ function ran(use: ToolUse, stop: number): boolean {
967
+ return use.result !== undefined || use.isSidechain || use.recordIndex > stop;
968
+ }
969
+
939
970
  /**
940
971
  * Records of what Claude Code sent to the API, not of what happened: a blob
941
972
  * repeats messages already in the session — tool calls and results included —
@@ -1104,6 +1135,7 @@ function finish(state: ParseState): ParsedSession {
1104
1135
  }
1105
1136
 
1106
1137
  const byUuid = buildByUuid(state.records);
1138
+ const stop = lastStop(state.records);
1107
1139
 
1108
1140
  return {
1109
1141
  sessionId,
@@ -1128,14 +1160,13 @@ function finish(state: ParseState): ParsedSession {
1128
1160
  // shell counts, a call the parser cannot see into is "cannot tell", which
1129
1161
  // must not read as "edited nothing", and so is a subagent that says it
1130
1162
  // edited, or whose work never came back to say. So does a commit the agent
1131
- // ran, whatever changed the files in it.
1163
+ // ran, whatever changed the files in it. A call that never ran does not (`ran`).
1132
1164
  hasFileEdits:
1133
- state.editToolUses > 0 ||
1134
- state.shellWrote ||
1165
+ state.writers.some((use) => ran(use, stop)) ||
1135
1166
  state.opaqueWrite ||
1136
1167
  state.delegatedEdits ||
1137
- delegatedUnseen(state) ||
1138
- committedFromShell(state),
1168
+ delegatedUnseen(state, stop) ||
1169
+ committedFromShell(state, stop),
1139
1170
  sidechainRecords,
1140
1171
  },
1141
1172
  skipped: state.skipped,
package/src/state.ts CHANGED
@@ -43,6 +43,12 @@ export interface SessionState {
43
43
  * is matched on, so it has to count as a change.
44
44
  */
45
45
  uploadedCommit?: string;
46
+ /**
47
+ * The branch that upload was filed under. A backfill sends a session under its
48
+ * own branch (`upload.ts:sendOne`), so one filed under another — by the push
49
+ * hook, or by an isy that sent the checkout's — has not been sent as it should.
50
+ */
51
+ uploadedBranch?: string;
46
52
  /** Candidate keys already printed, so a later commit does not repeat them. */
47
53
  shown?: string[];
48
54
  /** Record count at each commit, oldest first: maps a record index to a commit. */
package/src/update.ts CHANGED
@@ -32,8 +32,14 @@ export function isNewer(latest: string | undefined, current: string): boolean {
32
32
  * package manager; anything else is a source checkout, where pulling and
33
33
  * rebuilding is the only honest answer — and where `npm install -g` would
34
34
  * quietly replace the checkout the developer is working in.
35
+ *
36
+ * npx's own copy is replaced by any npx run of the bare name that asks the
37
+ * registry, and the hooks run that same copy. A global install is the one
38
+ * thing that stops it: npx then runs the global copy instead, hooks included,
39
+ * whatever the registry says, and only `npm install -g` moves it on.
35
40
  */
36
41
  export function updateCommand(dir: string = import.meta.dirname): string {
42
+ if (dir.includes(`${sep}_npx${sep}`)) return "npx @nightloom/isy --version";
37
43
  return dir.includes(`${sep}node_modules${sep}`)
38
44
  ? "npm install -g @nightloom/isy@latest"
39
45
  : "git pull && npm install && npm run build";