agent-yes 1.299.1 → 1.300.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.
Files changed (51) hide show
  1. package/README.md +9 -0
  2. package/default.config.yaml +12 -0
  3. package/dist/{SUPPORTED_CLIS-MftynU62.js → SUPPORTED_CLIS-BAeTuI-p.js} +3 -3
  4. package/dist/{SUPPORTED_CLIS-YZvIGQvw.js → SUPPORTED_CLIS-BZlaxyEH.js} +2 -2
  5. package/dist/{agentShare-dKQQSOD7.js → agentShare-DGQM24wU.js} +3 -3
  6. package/dist/{callback-BEbbWLKe.js → callback-3RsdcuV0.js} +3 -3
  7. package/dist/{callback-DWxTSlly.js → callback-CQadU_zP.js} +3 -3
  8. package/dist/cli.js +5 -5
  9. package/dist/{cmdPs-D7HWttUU.js → cmdPs-CQxFAs9M.js} +3 -3
  10. package/dist/index.js +2 -2
  11. package/dist/{notifyDaemon-B0aU7koS.js → notifyDaemon-CxkiJvOo.js} +3 -3
  12. package/dist/{parentPingLoop-DSiOXQeU.js → parentPingLoop-vZ8I9k5K.js} +2 -2
  13. package/dist/{remotes-DrYe_nfw.js → remotes-B4v0Nowo.js} +64 -7
  14. package/dist/remotes-DnMQWaqQ.js +5 -0
  15. package/dist/{rustBinary-CKuufNRn.js → rustBinary-B1buVId2.js} +2 -2
  16. package/dist/{rustBinary-DgRg5H6V.js → rustBinary-etb0Jsga.js} +2 -2
  17. package/dist/{schedule-BStFx0_s.js → schedule-CMBHLSlz.js} +4 -4
  18. package/dist/{serve-Cis4oJM-.js → serve-D5ijYGTv.js} +42 -28
  19. package/dist/{setup-B0sg4AV1.js → setup-DMJYufvD.js} +2 -2
  20. package/dist/{shareCmd-DKIvwe0I.js → shareCmd-CNhCKuOK.js} +3 -3
  21. package/dist/{subcommands-CvL_1Nt9.js → subcommands-BncoxUN6.js} +775 -78
  22. package/dist/subcommands-ZEjbTV_7.js +13 -0
  23. package/dist/{terminal-DqsAuqhw.js → terminal-DzbPI4n0.js} +2 -2
  24. package/dist/{trayApp-Dayj9Frx.js → trayApp-BvtgbxMB.js} +2 -2
  25. package/dist/trayApp-CpPsP3_a.js +5 -0
  26. package/dist/{ts-C2osm4MO.js → ts-Gr1eJOUk.js} +3 -3
  27. package/dist/{versionChecker-BmXwOe40.js → versionChecker-BrjeGNf1.js} +2 -2
  28. package/dist/{widget-D5tsB-oi.js → widget-p4Db_OXd.js} +3 -3
  29. package/dist/{ws-B4jdOeB2.js → ws-D_QClddd.js} +3 -3
  30. package/dist/{ws-mz7VJJwO.js → ws-DnKPi3TS.js} +2 -2
  31. package/package.json +1 -1
  32. package/ts/composerGuard.spec.ts +279 -0
  33. package/ts/composerGuard.ts +366 -0
  34. package/ts/globalPidIndex.ts +7 -0
  35. package/ts/messageLog.ts +2 -0
  36. package/ts/needsInput.bun.spec.ts +36 -0
  37. package/ts/needsInput.spec.ts +36 -0
  38. package/ts/remotes.bun.spec.ts +125 -0
  39. package/ts/remotes.spec.ts +125 -0
  40. package/ts/remotes.ts +95 -5
  41. package/ts/serve.bun.spec.ts +50 -0
  42. package/ts/serve.spec.ts +57 -1
  43. package/ts/serve.ts +50 -9
  44. package/ts/subcommands.spec.ts +564 -42
  45. package/ts/subcommands.ts +650 -79
  46. package/ts/workDir.bun.spec.ts +90 -0
  47. package/ts/workDir.spec.ts +90 -0
  48. package/ts/workDir.ts +75 -0
  49. package/dist/remotes-BDMnvGI6.js +0 -5
  50. package/dist/subcommands-DioyG80q.js +0 -13
  51. package/dist/trayApp-C6C7-TSh.js +0 -5
@@ -0,0 +1,90 @@
1
+ import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "fs";
2
+ import { tmpdir } from "os";
3
+ import path from "path";
4
+ import { afterEach, beforeEach, describe, expect, it } from "bun:test";
5
+ import { isWithin, resolveWorkDir, workdirSamplePath } from "./workDir.ts";
6
+
7
+ describe("resolveWorkDir", () => {
8
+ let root: string;
9
+ const saved = process.env.AGENT_YES_HOME;
10
+ beforeEach(() => {
11
+ root = realpathSync(mkdtempSync(path.join(tmpdir(), "ay-workdir-")));
12
+ process.env.AGENT_YES_HOME = path.join(root, "ay");
13
+ });
14
+ afterEach(() => {
15
+ rmSync(root, { recursive: true, force: true });
16
+ if (saved === undefined) delete process.env.AGENT_YES_HOME;
17
+ else process.env.AGENT_YES_HOME = saved;
18
+ });
19
+
20
+ function sample(pid: number, workdir: string, at: number, agent_id?: string) {
21
+ const p = workdirSamplePath(pid);
22
+ mkdirSync(path.dirname(p), { recursive: true });
23
+ writeFileSync(p, JSON.stringify({ workdir, at, agent_id }));
24
+ }
25
+
26
+ it("falls back to the spawn dir until the wrapper has sampled a workdir", async () => {
27
+ expect(await resolveWorkDir({ pid: 1111, cwd: "/repo/alpha/tree/main" })).toEqual({
28
+ workdir: "/repo/alpha/tree/main",
29
+ workdir_source: "spawn",
30
+ workdir_at: null,
31
+ });
32
+ });
33
+
34
+ it("uses the sampled repo when the lane works outside its spawn dir", async () => {
35
+ const wt = path.join(root, "feat-x");
36
+ mkdirSync(wt);
37
+ sample(1111, wt, 42, "abc123");
38
+ expect(
39
+ await resolveWorkDir({ pid: 1111, agent_id: "abc123", cwd: path.join(root, "main") }),
40
+ ).toEqual({ workdir: wt, workdir_source: "observed", workdir_at: 42 });
41
+ });
42
+
43
+ it("ignores a sample left by an earlier agent with the same pid", async () => {
44
+ const wt = path.join(root, "feat-x");
45
+ mkdirSync(wt);
46
+ sample(1111, wt, 42, "old000");
47
+ expect(
48
+ await resolveWorkDir({ pid: 1111, agent_id: "new111", cwd: "/repo/alpha" }),
49
+ ).toMatchObject({ workdir: "/repo/alpha", workdir_source: "spawn" });
50
+ });
51
+
52
+ it("ignores a sample when either side lacks an agent_id", async () => {
53
+ const wt = path.join(root, "feat-x");
54
+ mkdirSync(wt);
55
+ sample(1111, wt, 42);
56
+ expect(
57
+ await resolveWorkDir({ pid: 1111, agent_id: "abc123", cwd: "/repo/alpha" }),
58
+ ).toMatchObject({ workdir_source: "spawn" });
59
+ sample(1111, wt, 42, "abc123");
60
+ expect(await resolveWorkDir({ pid: 1111, cwd: "/repo/alpha" })).toMatchObject({
61
+ workdir_source: "spawn",
62
+ });
63
+ });
64
+
65
+ it("keeps the more precise spawn dir when the sampled repo contains it", async () => {
66
+ const spawn = path.join(root, "lib", "x");
67
+ mkdirSync(spawn, { recursive: true });
68
+ sample(1111, root, 1, "abc123");
69
+ expect(await resolveWorkDir({ pid: 1111, agent_id: "abc123", cwd: spawn })).toMatchObject({
70
+ workdir: spawn,
71
+ workdir_source: "spawn",
72
+ });
73
+ });
74
+
75
+ it("ignores a sampled dir that no longer exists (worktree removed)", async () => {
76
+ sample(1111, path.join(root, "gone"), 1, "abc123");
77
+ expect(
78
+ await resolveWorkDir({ pid: 1111, agent_id: "abc123", cwd: "/repo/alpha" }),
79
+ ).toMatchObject({
80
+ workdir: "/repo/alpha",
81
+ workdir_source: "spawn",
82
+ });
83
+ });
84
+
85
+ it("isWithin is path-segment aware", () => {
86
+ expect(isWithin("/repo/a/b", "/repo/a")).toBe(true);
87
+ expect(isWithin("/repo/a", "/repo/a")).toBe(true);
88
+ expect(isWithin("/repo/ab", "/repo/a")).toBe(false);
89
+ });
90
+ });
@@ -0,0 +1,90 @@
1
+ import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "fs";
2
+ import { tmpdir } from "os";
3
+ import path from "path";
4
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
5
+ import { isWithin, resolveWorkDir, workdirSamplePath } from "./workDir.ts";
6
+
7
+ describe("resolveWorkDir", () => {
8
+ let root: string;
9
+ const saved = process.env.AGENT_YES_HOME;
10
+ beforeEach(() => {
11
+ root = realpathSync(mkdtempSync(path.join(tmpdir(), "ay-workdir-")));
12
+ process.env.AGENT_YES_HOME = path.join(root, "ay");
13
+ });
14
+ afterEach(() => {
15
+ rmSync(root, { recursive: true, force: true });
16
+ if (saved === undefined) delete process.env.AGENT_YES_HOME;
17
+ else process.env.AGENT_YES_HOME = saved;
18
+ });
19
+
20
+ function sample(pid: number, workdir: string, at: number, agent_id?: string) {
21
+ const p = workdirSamplePath(pid);
22
+ mkdirSync(path.dirname(p), { recursive: true });
23
+ writeFileSync(p, JSON.stringify({ workdir, at, agent_id }));
24
+ }
25
+
26
+ it("falls back to the spawn dir until the wrapper has sampled a workdir", async () => {
27
+ expect(await resolveWorkDir({ pid: 1111, cwd: "/repo/alpha/tree/main" })).toEqual({
28
+ workdir: "/repo/alpha/tree/main",
29
+ workdir_source: "spawn",
30
+ workdir_at: null,
31
+ });
32
+ });
33
+
34
+ it("uses the sampled repo when the lane works outside its spawn dir", async () => {
35
+ const wt = path.join(root, "feat-x");
36
+ mkdirSync(wt);
37
+ sample(1111, wt, 42, "abc123");
38
+ expect(
39
+ await resolveWorkDir({ pid: 1111, agent_id: "abc123", cwd: path.join(root, "main") }),
40
+ ).toEqual({ workdir: wt, workdir_source: "observed", workdir_at: 42 });
41
+ });
42
+
43
+ it("ignores a sample left by an earlier agent with the same pid", async () => {
44
+ const wt = path.join(root, "feat-x");
45
+ mkdirSync(wt);
46
+ sample(1111, wt, 42, "old000");
47
+ expect(
48
+ await resolveWorkDir({ pid: 1111, agent_id: "new111", cwd: "/repo/alpha" }),
49
+ ).toMatchObject({ workdir: "/repo/alpha", workdir_source: "spawn" });
50
+ });
51
+
52
+ it("ignores a sample when either side lacks an agent_id", async () => {
53
+ const wt = path.join(root, "feat-x");
54
+ mkdirSync(wt);
55
+ sample(1111, wt, 42);
56
+ expect(
57
+ await resolveWorkDir({ pid: 1111, agent_id: "abc123", cwd: "/repo/alpha" }),
58
+ ).toMatchObject({ workdir_source: "spawn" });
59
+ sample(1111, wt, 42, "abc123");
60
+ expect(await resolveWorkDir({ pid: 1111, cwd: "/repo/alpha" })).toMatchObject({
61
+ workdir_source: "spawn",
62
+ });
63
+ });
64
+
65
+ it("keeps the more precise spawn dir when the sampled repo contains it", async () => {
66
+ const spawn = path.join(root, "lib", "x");
67
+ mkdirSync(spawn, { recursive: true });
68
+ sample(1111, root, 1, "abc123");
69
+ expect(await resolveWorkDir({ pid: 1111, agent_id: "abc123", cwd: spawn })).toMatchObject({
70
+ workdir: spawn,
71
+ workdir_source: "spawn",
72
+ });
73
+ });
74
+
75
+ it("ignores a sampled dir that no longer exists (worktree removed)", async () => {
76
+ sample(1111, path.join(root, "gone"), 1, "abc123");
77
+ expect(
78
+ await resolveWorkDir({ pid: 1111, agent_id: "abc123", cwd: "/repo/alpha" }),
79
+ ).toMatchObject({
80
+ workdir: "/repo/alpha",
81
+ workdir_source: "spawn",
82
+ });
83
+ });
84
+
85
+ it("isWithin is path-segment aware", () => {
86
+ expect(isWithin("/repo/a/b", "/repo/a")).toBe(true);
87
+ expect(isWithin("/repo/a", "/repo/a")).toBe(true);
88
+ expect(isWithin("/repo/ab", "/repo/a")).toBe(false);
89
+ });
90
+ });
package/ts/workDir.ts ADDED
@@ -0,0 +1,75 @@
1
+ import { readFile, stat } from "fs/promises";
2
+ import path from "path";
3
+ import { agentYesHome } from "./agentYesHome.ts";
4
+
5
+ /**
6
+ * Where an agent actually WORKS, as opposed to where it was spawned.
7
+ *
8
+ * A lane is often launched in one dir and works in another (`cd <worktree> &&
9
+ * …` per Bash call). The wrapped CLI's own cwd never moves, so the registry's
10
+ * `cwd` stays the spawn dir. The Rust wrapper samples the kernel cwd of the
11
+ * agent's shells and writes the repo they run in to
12
+ * `<agentYesHome>/workdir/<pid>.json` (rs/src/workdir_sampler.rs) — a
13
+ * measurement, not something the agent wrote or claimed. This module only
14
+ * reads it back.
15
+ */
16
+
17
+ export type WorkDirSource = "observed" | "spawn";
18
+
19
+ export interface WorkDir {
20
+ workdir: string;
21
+ workdir_source: WorkDirSource;
22
+ /** epoch ms of the latest sample that confirmed `workdir`; null for spawn. */
23
+ workdir_at: number | null;
24
+ }
25
+
26
+ export function isWithin(child: string, parent: string): boolean {
27
+ const rel = path.relative(parent, child);
28
+ return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
29
+ }
30
+
31
+ export function workdirSamplePath(pid: number): string {
32
+ return path.join(agentYesHome(), "workdir", `${pid}.json`);
33
+ }
34
+
35
+ /**
36
+ * The wrapper's latest sample for this agent, or null. A sample whose
37
+ * `agent_id` doesn't match belongs to an earlier agent that had the same pid.
38
+ */
39
+ export async function readWorkdirSample(r: {
40
+ pid: number;
41
+ agent_id?: string | null;
42
+ }): Promise<{ workdir: string; at: number } | null> {
43
+ try {
44
+ const j = JSON.parse(await readFile(workdirSamplePath(r.pid), "utf-8"));
45
+ if (typeof j?.workdir !== "string" || typeof j?.at !== "number") return null;
46
+ // Both sides must carry the id and agree: a sample without one (or a record
47
+ // without one) can't be told apart from a crashed predecessor's leftover.
48
+ if (!r.agent_id || j.agent_id !== r.agent_id) return null;
49
+ return { workdir: j.workdir, at: j.at };
50
+ } catch {
51
+ return null;
52
+ }
53
+ }
54
+
55
+ /**
56
+ * The effective work dir for a record. The sampled repo wins unless it merely
57
+ * contains the spawn dir (a lane working in the repo it was spawned in — the
58
+ * spawn cwd is the more precise answer) or it no longer exists.
59
+ */
60
+ export async function resolveWorkDir(r: {
61
+ pid: number;
62
+ cwd: string;
63
+ agent_id?: string | null;
64
+ }): Promise<WorkDir> {
65
+ const spawn: WorkDir = { workdir: r.cwd, workdir_source: "spawn", workdir_at: null };
66
+ const sample = await readWorkdirSample(r);
67
+ const w = sample?.workdir;
68
+ if (!w || isWithin(r.cwd, w)) return spawn;
69
+ const isDir = await stat(w).then(
70
+ (s) => s.isDirectory(),
71
+ () => false,
72
+ );
73
+ if (!isDir) return spawn;
74
+ return { workdir: w, workdir_source: "observed", workdir_at: sample.at };
75
+ }
@@ -1,5 +0,0 @@
1
- import "./e2e-z1xpwSAg.js";
2
- import "./webrtcLink-DFRyWNMs.js";
3
- import { a as parseDirectRemoteSpec, c as resolveRemoteSpec, i as deleteRemoteAlias, l as writeRemoteAlias, n as cmdRemote, o as parseShareUrl, r as defaultConnectAlias, s as readRemotes, t as cmdConnect } from "./remotes-DrYe_nfw.js";
4
-
5
- export { cmdConnect, cmdRemote };
@@ -1,13 +0,0 @@
1
- import "./logger-CDIsZ-Pp.js";
2
- import "./JsonlStore-BqF7AQ6E.js";
3
- import "./globalPidIndex-CRH9L9tn.js";
4
- import "./pidStore-DXWqzTSz.js";
5
- import "./messageLog-Brx3w6zT.js";
6
- import "./e2e-z1xpwSAg.js";
7
- import "./configShared-DKTgiz7K.js";
8
- import { $ as sendPayloadCapError, A as isUnknownManagerToken, B as readLogForRender, C as finalizedLines, D as isPidAlive, E as isExitRequest, F as listRecords, G as renderLogTailLines, H as readPtysize, I as matchKeyword, J as resolveOne, K as renderRawLog, L as menuSelectKeys, M as isUserTyping, N as lastReadAt, O as isSlashCommand, P as lastStdinAt, Q as runSubcommand, R as probeStdinReachable, S as extractTaskCounts, T as isBareManagerInvocation, U as recentMessageEdges, V as readNotes, W as recentReadEdges, X as resolveResumeArgs, Y as resolveReadWindow, Z as restartHintLines, _ as envelopeAttribution, a as SEND_BODY_MAX_CHARS, at as writeKeysPaced, b as extractMenu, c as backoffWhileTyping, d as cmdHelp, et as snapshotStatus, f as confirmStdinUnreachable, g as deriveLiveStatus, h as deriveLiveState, i as READ_WINDOW_MS, it as waitForLogQuiet, j as isUnreachableWriteErrno, k as isSubcommand, l as buildEnvelope, m as cursorAbs, n as MAX_RENDER_BYTES, nt as stopTipForCli, o as SEND_EXIT_UNREACHABLE, ot as writeToIpc, p as controlCodeFromName, q as renderRawLogLines, r as READ_PAGE_DEFAULT, rt as submitAndConfirm, s as TYPING_WINDOW_MS, t as GRACEFUL_EXIT_COMMANDS, tt as stdinActivityPath, u as cliDefaults, v as envelopeCostFor, w as isAgentStuck, x as extractNeedsInput, y as extractBadges, z as readAgentPtysize } from "./subcommands-CvL_1Nt9.js";
9
- import "./notifyStore-2SWKGwZI.js";
10
- import "./webrtcLink-DFRyWNMs.js";
11
- import "./remotes-DrYe_nfw.js";
12
-
13
- export { READ_WINDOW_MS, cmdHelp, isBareManagerInvocation, isSubcommand, isUnknownManagerToken, lastReadAt, runSubcommand };
@@ -1,5 +0,0 @@
1
- import "./versionChecker-BmXwOe40.js";
2
- import "./rustBinary-CKuufNRn.js";
3
- import { a as trayHiddenMarker, i as launchTray, n as hasDesktop, r as isTrayHidden, t as cmdTray } from "./trayApp-Dayj9Frx.js";
4
-
5
- export { cmdTray };