@memnexus-ai/mx-agent-cli 0.1.302 → 0.1.304

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 (163) hide show
  1. package/dist/agent-config/.mx-config-generation.json +2 -2
  2. package/dist/agent-config/AGENTS.md.template +1 -1
  3. package/dist/agent-config/agents/bar-raiser.md +41 -1
  4. package/dist/agent-config/agents/git-expert.md +58 -54
  5. package/dist/agent-config/claude-md/CLAUDE.core.md +1 -1
  6. package/dist/agent-config/hooks/session-idle-gate.sh +14 -1
  7. package/dist/agent-config/hooks/subagent-write-guard.sh +198 -12
  8. package/dist/agent-config/hooks/worktree-guard.sh +8 -6
  9. package/dist/agent-config/skills/mx-post-merge-sync/SKILL.md +57 -51
  10. package/dist/commands/codex-agent-gate.d.ts +1 -2
  11. package/dist/commands/codex-agent-gate.d.ts.map +1 -1
  12. package/dist/commands/codex-agent-gate.js +1 -2
  13. package/dist/commands/codex-agent-gate.js.map +1 -1
  14. package/dist/commands/codex-deploy-config.d.ts +6 -0
  15. package/dist/commands/codex-deploy-config.d.ts.map +1 -1
  16. package/dist/commands/codex-deploy-config.js +28 -8
  17. package/dist/commands/codex-deploy-config.js.map +1 -1
  18. package/dist/commands/codex-prove-guards.d.ts +2 -0
  19. package/dist/commands/codex-prove-guards.d.ts.map +1 -1
  20. package/dist/commands/codex-prove-guards.js +31 -3
  21. package/dist/commands/codex-prove-guards.js.map +1 -1
  22. package/dist/commands/codex-trust-keys.d.ts +2 -0
  23. package/dist/commands/codex-trust-keys.d.ts.map +1 -1
  24. package/dist/commands/codex-trust-keys.js +27 -7
  25. package/dist/commands/codex-trust-keys.js.map +1 -1
  26. package/dist/commands/coordination.d.ts +16 -0
  27. package/dist/commands/coordination.d.ts.map +1 -1
  28. package/dist/commands/coordination.js +24 -2
  29. package/dist/commands/coordination.js.map +1 -1
  30. package/dist/commands/create.d.ts +164 -7
  31. package/dist/commands/create.d.ts.map +1 -1
  32. package/dist/commands/create.js +293 -91
  33. package/dist/commands/create.js.map +1 -1
  34. package/dist/commands/doctor.d.ts +17 -0
  35. package/dist/commands/doctor.d.ts.map +1 -1
  36. package/dist/commands/doctor.js +33 -0
  37. package/dist/commands/doctor.js.map +1 -1
  38. package/dist/commands/gh.d.ts +3 -2
  39. package/dist/commands/gh.d.ts.map +1 -1
  40. package/dist/commands/gh.js +3 -2
  41. package/dist/commands/gh.js.map +1 -1
  42. package/dist/commands/new.d.ts +151 -13
  43. package/dist/commands/new.d.ts.map +1 -1
  44. package/dist/commands/new.js +486 -62
  45. package/dist/commands/new.js.map +1 -1
  46. package/dist/commands/start.d.ts +6 -0
  47. package/dist/commands/start.d.ts.map +1 -1
  48. package/dist/commands/start.js +105 -17
  49. package/dist/commands/start.js.map +1 -1
  50. package/dist/commands/status.d.ts +7 -0
  51. package/dist/commands/status.d.ts.map +1 -1
  52. package/dist/commands/status.js +21 -1
  53. package/dist/commands/status.js.map +1 -1
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.js +28 -4
  56. package/dist/index.js.map +1 -1
  57. package/dist/lib/agent-session.d.ts +11 -0
  58. package/dist/lib/agent-session.d.ts.map +1 -1
  59. package/dist/lib/agent-session.js +26 -7
  60. package/dist/lib/agent-session.js.map +1 -1
  61. package/dist/lib/behavioral-injection.d.ts.map +1 -1
  62. package/dist/lib/behavioral-injection.js +25 -7
  63. package/dist/lib/behavioral-injection.js.map +1 -1
  64. package/dist/lib/catalog-commit.d.ts.map +1 -1
  65. package/dist/lib/catalog-commit.js +17 -14
  66. package/dist/lib/catalog-commit.js.map +1 -1
  67. package/dist/lib/catalog.d.ts +93 -2
  68. package/dist/lib/catalog.d.ts.map +1 -1
  69. package/dist/lib/catalog.js +116 -9
  70. package/dist/lib/catalog.js.map +1 -1
  71. package/dist/lib/claude.d.ts.map +1 -1
  72. package/dist/lib/claude.js +28 -4
  73. package/dist/lib/claude.js.map +1 -1
  74. package/dist/lib/fleet-data.d.ts +98 -9
  75. package/dist/lib/fleet-data.d.ts.map +1 -1
  76. package/dist/lib/fleet-data.js +353 -34
  77. package/dist/lib/fleet-data.js.map +1 -1
  78. package/dist/lib/fleet-render.d.ts +8 -1
  79. package/dist/lib/fleet-render.d.ts.map +1 -1
  80. package/dist/lib/fleet-render.js +10 -3
  81. package/dist/lib/fleet-render.js.map +1 -1
  82. package/dist/lib/gh-remote.d.ts +15 -1
  83. package/dist/lib/gh-remote.d.ts.map +1 -1
  84. package/dist/lib/gh-remote.js +27 -2
  85. package/dist/lib/gh-remote.js.map +1 -1
  86. package/dist/lib/gh-token-run.d.ts +140 -14
  87. package/dist/lib/gh-token-run.d.ts.map +1 -1
  88. package/dist/lib/gh-token-run.js +187 -15
  89. package/dist/lib/gh-token-run.js.map +1 -1
  90. package/dist/lib/git-identity.d.ts +6 -2
  91. package/dist/lib/git-identity.d.ts.map +1 -1
  92. package/dist/lib/git-identity.js +17 -8
  93. package/dist/lib/git-identity.js.map +1 -1
  94. package/dist/lib/git-scrub-env.d.ts +35 -0
  95. package/dist/lib/git-scrub-env.d.ts.map +1 -0
  96. package/dist/lib/git-scrub-env.js +54 -0
  97. package/dist/lib/git-scrub-env.js.map +1 -0
  98. package/dist/lib/guarded-read.d.ts +15 -0
  99. package/dist/lib/guarded-read.d.ts.map +1 -0
  100. package/dist/lib/guarded-read.js +73 -0
  101. package/dist/lib/guarded-read.js.map +1 -0
  102. package/dist/lib/machine-setup.d.ts +165 -0
  103. package/dist/lib/machine-setup.d.ts.map +1 -0
  104. package/dist/lib/machine-setup.js +441 -0
  105. package/dist/lib/machine-setup.js.map +1 -0
  106. package/dist/lib/native-realpath.d.ts +70 -0
  107. package/dist/lib/native-realpath.d.ts.map +1 -0
  108. package/dist/lib/native-realpath.js +95 -0
  109. package/dist/lib/native-realpath.js.map +1 -0
  110. package/dist/lib/project-config.d.ts +2 -6
  111. package/dist/lib/project-config.d.ts.map +1 -1
  112. package/dist/lib/project-config.js.map +1 -1
  113. package/dist/lib/project-name.d.ts +15 -0
  114. package/dist/lib/project-name.d.ts.map +1 -0
  115. package/dist/lib/project-name.js +22 -0
  116. package/dist/lib/project-name.js.map +1 -0
  117. package/dist/lib/push-to.d.ts +113 -0
  118. package/dist/lib/push-to.d.ts.map +1 -0
  119. package/dist/lib/push-to.js +240 -0
  120. package/dist/lib/push-to.js.map +1 -0
  121. package/dist/lib/runtime/claude-gateway-routing.d.ts +161 -0
  122. package/dist/lib/runtime/claude-gateway-routing.d.ts.map +1 -0
  123. package/dist/lib/runtime/claude-gateway-routing.js +466 -0
  124. package/dist/lib/runtime/claude-gateway-routing.js.map +1 -0
  125. package/dist/lib/runtime/codex-adapter.d.ts +91 -5
  126. package/dist/lib/runtime/codex-adapter.d.ts.map +1 -1
  127. package/dist/lib/runtime/codex-adapter.js +204 -44
  128. package/dist/lib/runtime/codex-adapter.js.map +1 -1
  129. package/dist/lib/runtime/codex-config.d.ts +6 -12
  130. package/dist/lib/runtime/codex-config.d.ts.map +1 -1
  131. package/dist/lib/runtime/codex-config.js +17 -24
  132. package/dist/lib/runtime/codex-config.js.map +1 -1
  133. package/dist/lib/runtime/codex-guard-proof.d.ts +4 -7
  134. package/dist/lib/runtime/codex-guard-proof.d.ts.map +1 -1
  135. package/dist/lib/runtime/codex-guard-proof.js +16 -14
  136. package/dist/lib/runtime/codex-guard-proof.js.map +1 -1
  137. package/dist/lib/runtime/codex-hooks-list.d.ts +20 -0
  138. package/dist/lib/runtime/codex-hooks-list.d.ts.map +1 -1
  139. package/dist/lib/runtime/codex-hooks-list.js +20 -8
  140. package/dist/lib/runtime/codex-hooks-list.js.map +1 -1
  141. package/dist/lib/runtime/types.d.ts +1 -1
  142. package/dist/lib/runtime/types.d.ts.map +1 -1
  143. package/dist/lib/standards.d.ts +3 -0
  144. package/dist/lib/standards.d.ts.map +1 -1
  145. package/dist/lib/standards.js +1 -0
  146. package/dist/lib/standards.js.map +1 -1
  147. package/dist/lib/team-identity.d.ts.map +1 -1
  148. package/dist/lib/team-identity.js +18 -53
  149. package/dist/lib/team-identity.js.map +1 -1
  150. package/dist/lib/team-restore.d.ts +281 -0
  151. package/dist/lib/team-restore.d.ts.map +1 -0
  152. package/dist/lib/team-restore.js +533 -0
  153. package/dist/lib/team-restore.js.map +1 -0
  154. package/dist/lib/window-view.d.ts +5 -0
  155. package/dist/lib/window-view.d.ts.map +1 -1
  156. package/dist/lib/window-view.js +67 -6
  157. package/dist/lib/window-view.js.map +1 -1
  158. package/dist/lib/worktree-sync.d.ts +139 -11
  159. package/dist/lib/worktree-sync.d.ts.map +1 -1
  160. package/dist/lib/worktree-sync.js +327 -46
  161. package/dist/lib/worktree-sync.js.map +1 -1
  162. package/dist/standards/merge-gates.md +26 -0
  163. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-scrub-env.d.ts","sourceRoot":"","sources":["../../src/lib/git-scrub-env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,sEAAsE;AACtE,eAAO,MAAM,iBAAiB,EAAE,SAAS,MAAM,EAU7C,CAAC;AAIH;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAO7E"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * git-scrub-env -- remove git's repository-redirect variables from an
3
+ * environment before `mx-agent new project` runs git (for #860, plan #864).
4
+ *
5
+ * WHY. `git push` from a linked worktree exports GIT_DIR into its hooks
6
+ * (`testing-tools/git-env.cjs`, "WHY THIS EXISTS"). GIT_DIR takes precedence
7
+ * over repository discovery, and `git -C <dir>` sets only the working
8
+ * directory. So under an inherited GIT_DIR, `git init <new dir>` re-initialises
9
+ * another repository, `symbolic-ref` rewrites that repository's HEAD, and the
10
+ * `extensions.worktreeConfig` write lands in its config (PR #858 security
11
+ * review, comment 6560613312, reproduced on git 2.49.0).
12
+ *
13
+ * WHY A NAMED LIST AND NOT A `GIT_` PREFIX SWEEP. The test helper
14
+ * `testing-tools/git-env.cjs` sweeps every `GIT_` name, which is right for a
15
+ * test suite that reads no ambient git state. This is production code acting
16
+ * for an operator, whose commit may depend on GIT_AUTHOR_*, GIT_COMMITTER_*,
17
+ * GIT_CONFIG_GLOBAL or GIT_SSH_COMMAND. Those stay. Only the nine names below,
18
+ * each of which points git at a different repository, index, object store or
19
+ * discovery boundary, are removed.
20
+ *
21
+ * Names compare case-insensitively, as in `testing-tools/git-env.cjs` (SF-3):
22
+ * a Windows environment name is case-insensitive, so `Git_Dir` reaches git as
23
+ * GIT_DIR.
24
+ *
25
+ * The drift test in `src/__tests__/git-scrub-env.test.ts` asserts the test
26
+ * helper strips all nine too.
27
+ */
28
+ /** The nine names plan #864 item 1 lists. A named list, by design. */
29
+ export const GIT_REDIRECT_VARS = Object.freeze([
30
+ 'GIT_DIR',
31
+ 'GIT_WORK_TREE',
32
+ 'GIT_COMMON_DIR',
33
+ 'GIT_INDEX_FILE',
34
+ 'GIT_OBJECT_DIRECTORY',
35
+ 'GIT_ALTERNATE_OBJECT_DIRECTORIES',
36
+ 'GIT_NAMESPACE',
37
+ 'GIT_PREFIX',
38
+ 'GIT_CEILING_DIRECTORIES',
39
+ ]);
40
+ const REDIRECT_UPPER = new Set(GIT_REDIRECT_VARS);
41
+ /**
42
+ * A copy of `env` without the nine redirect names. Never mutates `env`, so a
43
+ * caller can pass `process.env` and keep its own environment intact.
44
+ */
45
+ export function scrubGitRedirectEnv(env) {
46
+ const out = {};
47
+ for (const [name, value] of Object.entries(env)) {
48
+ if (REDIRECT_UPPER.has(name.toUpperCase()))
49
+ continue;
50
+ out[name] = value;
51
+ }
52
+ return out;
53
+ }
54
+ //# sourceMappingURL=git-scrub-env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-scrub-env.js","sourceRoot":"","sources":["../../src/lib/git-scrub-env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,sEAAsE;AACtE,MAAM,CAAC,MAAM,iBAAiB,GAAsB,MAAM,CAAC,MAAM,CAAC;IAChE,SAAS;IACT,eAAe;IACf,gBAAgB;IAChB,gBAAgB;IAChB,sBAAsB;IACtB,kCAAkC;IAClC,eAAe;IACf,YAAY;IACZ,yBAAyB;CAC1B,CAAC,CAAC;AAEH,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAElD;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAsB;IACxD,MAAM,GAAG,GAAsB,EAAE,CAAC;IAClC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAChD,IAAI,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YAAE,SAAS;QACrD,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;IACpB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,15 @@
1
+ export type GuardedRead = {
2
+ kind: 'ok';
3
+ bytes: Buffer;
4
+ }
5
+ /** ENOENT at open. Nothing is there, which is not the same as a refused file. */
6
+ | {
7
+ kind: 'absent';
8
+ }
9
+ /** Something is there and was not read. `reason` is one line, for the operator. */
10
+ | {
11
+ kind: 'refused';
12
+ reason: string;
13
+ };
14
+ export declare function readRegularFileGuarded(path: string, maxBytes: number): GuardedRead;
15
+ //# sourceMappingURL=guarded-read.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guarded-read.d.ts","sourceRoot":"","sources":["../../src/lib/guarded-read.ts"],"names":[],"mappings":"AA8BA,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE;AAC/B,iFAAiF;GAC/E;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE;AACpB,mFAAmF;GACjF;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAMxC,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,WAAW,CAgClF"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Read a file that must be a regular file of bounded size, without following a
3
+ * symlink and without blocking on a FIFO (#902).
4
+ *
5
+ * A bare `readFileSync(path)` on a FIFO blocks in the kernel until a writer
6
+ * opens the other end, and nothing ever does, so the command hangs with no
7
+ * output. The red-team reproduced this on a FIFO named `<x>.md` in the teams
8
+ * directory at `4bfe9d5`: `readCatalog`, `listTeams` and `getTeam` all hung, and
9
+ * through them `start`, `provision` and every fleet command that lists teams.
10
+ *
11
+ * This is the descriptor-checked read `readFallbackFile` uses
12
+ * (`coordination-fallback.ts`, the security review of #525 at eba08f4), without
13
+ * its owner check and with a size cap:
14
+ *
15
+ * - opened `O_RDONLY | O_NOFOLLOW | O_NONBLOCK`, so a symlink in the final
16
+ * component is refused (ELOOP) and a FIFO open returns at once;
17
+ * - `fstatSync` on the descriptor that is read, so the check and the read are
18
+ * about the same file, and anything that is not a regular file is refused;
19
+ * - a file larger than `maxBytes` is refused, and the read itself stops at
20
+ * `maxBytes + 1` bytes, so a file that grows after the `fstat` is refused too
21
+ * rather than read whole;
22
+ * - the descriptor is closed in `finally`.
23
+ *
24
+ * It does not warn. The result says what happened and the caller decides what
25
+ * to print, because one caller skips the file and another stops the command.
26
+ * `coordination-fallback.ts` keeps its own copy: it also refuses a file another
27
+ * user owns, and its warnings name what it left in place.
28
+ */
29
+ import { closeSync, constants as fsConstants, fstatSync, openSync, readSync } from 'fs';
30
+ // `?? 0`: Windows defines neither flag. There the open is a plain O_RDONLY, and
31
+ // the `isFile()` check on the descriptor still refuses what is not a file.
32
+ const OPEN_FLAGS = fsConstants.O_RDONLY | (fsConstants.O_NOFOLLOW ?? 0) | (fsConstants.O_NONBLOCK ?? 0);
33
+ export function readRegularFileGuarded(path, maxBytes) {
34
+ let fd;
35
+ try {
36
+ fd = openSync(path, OPEN_FLAGS);
37
+ }
38
+ catch (err) {
39
+ const code = err.code;
40
+ if (code === 'ENOENT')
41
+ return { kind: 'absent' };
42
+ if (code === 'ELOOP')
43
+ return { kind: 'refused', reason: 'it is a symbolic link, which is not followed' };
44
+ return { kind: 'refused', reason: `it could not be opened (${code ?? 'error'})` };
45
+ }
46
+ try {
47
+ const st = fstatSync(fd);
48
+ if (!st.isFile())
49
+ return { kind: 'refused', reason: 'it is not a regular file' };
50
+ if (st.size > maxBytes) {
51
+ return { kind: 'refused', reason: `it is ${st.size} bytes, over the ${maxBytes}-byte limit` };
52
+ }
53
+ const buf = Buffer.alloc(maxBytes + 1);
54
+ let total = 0;
55
+ while (total < buf.length) {
56
+ const n = readSync(fd, buf, total, buf.length - total, null);
57
+ if (n === 0)
58
+ break;
59
+ total += n;
60
+ }
61
+ if (total > maxBytes) {
62
+ return { kind: 'refused', reason: `it grew past the ${maxBytes}-byte limit while it was read` };
63
+ }
64
+ return { kind: 'ok', bytes: buf.subarray(0, total) };
65
+ }
66
+ catch (err) {
67
+ return { kind: 'refused', reason: `it could not be read (${err.code ?? 'error'})` };
68
+ }
69
+ finally {
70
+ closeSync(fd);
71
+ }
72
+ }
73
+ //# sourceMappingURL=guarded-read.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guarded-read.js","sourceRoot":"","sources":["../../src/lib/guarded-read.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAAE,SAAS,EAAE,SAAS,IAAI,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AASxF,gFAAgF;AAChF,2EAA2E;AAC3E,MAAM,UAAU,GAAG,WAAW,CAAC,QAAQ,GAAG,CAAC,WAAW,CAAC,UAAU,IAAI,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC;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gBAAE,MAAM;YACnB,KAAK,IAAI,CAAC,CAAC;QACb,CAAC;QACD,IAAI,KAAK,GAAG,QAAQ,EAAE,CAAC;YACrB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,oBAAoB,QAAQ,+BAA+B,EAAE,CAAC;QAClG,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;IACvD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,yBAA0B,GAA6B,CAAC,IAAI,IAAI,OAAO,GAAG,EAAE,CAAC;IACjH,CAAC;YAAS,CAAC;QACT,SAAS,CAAC,EAAE,CAAC,CAAC;IAChB,CAAC;AACH,CAAC"}
@@ -0,0 +1,165 @@
1
+ /**
2
+ * The machine setup `mx-agent start` runs itself (#1155 slice 2).
3
+ *
4
+ * SPEC. Plan comment 6961512321 on #1155 and its amendment 1, comment
5
+ * 6961573086. The amendment governs where they differ.
6
+ *
7
+ * `ensureMachineSetup` checks three settings and returns exactly one result for
8
+ * each: `already-set`, `set`, `not-set` (with the one command that sets it) or
9
+ * `could-not-check` (with the reason). In `apply` mode it writes a setting only
10
+ * under that setting's rule below. In `report` mode it writes nothing.
11
+ *
12
+ * extensions.worktreeConfig The repository's own `.git/config`. Set only when
13
+ * the repository has no linked worktree other than
14
+ * the main one and the pre-flight passes.
15
+ * coordination-brief-enabled `~/.mx-agent/config.json`. Set to the string
16
+ * "true" only when the key is absent.
17
+ * project slug Tracked `mx-agent.config.json`. Report only.
18
+ *
19
+ * ONE WRITER PER SETTING. `setWorktreeConfigExtension` is the only code that
20
+ * writes `extensions.worktreeConfig`; `enableWorktreeConfig` in
21
+ * `commands/new.ts` calls it. `ensureBriefEnabled` is the only code that writes
22
+ * `coordination-brief-enabled` on its own initiative; `mx-agent config set`
23
+ * still writes it when an operator asks.
24
+ */
25
+ export type MachineSetupMode = 'apply' | 'report';
26
+ export type SettingStatus = 'already-set' | 'set' | 'not-set' | 'could-not-check';
27
+ export type SettingName = 'extensions.worktreeConfig' | 'coordination-brief-enabled' | 'projectSlug';
28
+ /**
29
+ * Why a setting is `not-set` or `could-not-check`. `enableWorktreeConfig` maps
30
+ * these to its own three return values, so they are part of the contract.
31
+ */
32
+ export type SettingCause = 'other-worktrees' | 'preflight' | 'write-failed' | 'unreadable' | 'report-mode' | 'present-value' | 'read-only';
33
+ export interface SettingResult {
34
+ setting: SettingName;
35
+ status: SettingStatus;
36
+ /** One clause: what is true now. Sanitized for a terminal. */
37
+ detail: string;
38
+ /** The one command an operator runs, for `not-set`. */
39
+ command?: string;
40
+ /** Set when `status` is `set`: the value before and after the write. */
41
+ change?: {
42
+ from: string;
43
+ to: string;
44
+ };
45
+ cause?: SettingCause;
46
+ /** For `extensions.worktreeConfig`: the main worktree the setting belongs to. */
47
+ repo?: string;
48
+ /** For `write-failed`: git's exit status and stderr, sanitized. */
49
+ writeError?: {
50
+ status: number | null;
51
+ why: string;
52
+ };
53
+ }
54
+ export interface MachineSetupResult {
55
+ mode: MachineSetupMode;
56
+ results: SettingResult[];
57
+ }
58
+ /** How the `extensions.worktreeConfig` write runs git. Injectable so a test can force a failure. */
59
+ export type GitConfigRunner = (args: string[]) => {
60
+ status: number | null;
61
+ stderr?: string | null;
62
+ error?: Error;
63
+ };
64
+ /** How the read-only git calls run. Injectable so a test can force a failure. */
65
+ export type GitReader = (args: string[]) => {
66
+ status: number | null;
67
+ stdout: string;
68
+ stderr: string;
69
+ };
70
+ export interface MachineSetupOptions {
71
+ projectRoot: string;
72
+ mode: MachineSetupMode;
73
+ /**
74
+ * The `~/.mx-agent/config.json` path. Defaults to the real one. Under the
75
+ * test runner a call without it throws (the #651 guard): no unit test of this
76
+ * module may read or write the operator's file.
77
+ */
78
+ configPath?: string;
79
+ /** Test seams. */
80
+ runGitConfig?: GitConfigRunner;
81
+ readGit?: GitReader;
82
+ /** Called after the first read of config.json and before the re-read. Test seam for the race. */
83
+ beforeConfigWrite?: () => void;
84
+ }
85
+ export declare const BRIEF_KEY = "coordination-brief-enabled";
86
+ export declare const BRIEF_COMMAND = "mx-agent config set coordination-brief-enabled true";
87
+ /** The command that enables the extension on `repo`. */
88
+ export declare function worktreeConfigCommand(repo: string): string;
89
+ interface WorktreeCount {
90
+ /** Linked worktrees, every entry after the first. */
91
+ others: number;
92
+ /** True when the first entry is `bare`. */
93
+ bare: boolean;
94
+ }
95
+ /**
96
+ * Count the linked worktrees from `git worktree list --porcelain`.
97
+ *
98
+ * Skips the first entry, which is the main worktree or a `bare` entry. Counts
99
+ * every other entry, including `prunable`, `locked` and entries whose directory
100
+ * is gone, because each still has an admin directory that reads the shared
101
+ * config (amendment 1 section 2, red-team finding 2).
102
+ */
103
+ export declare function countLinkedWorktrees(porcelain: string): WorktreeCount;
104
+ export interface WorktreeConfigOptions {
105
+ projectRoot: string;
106
+ mode: MachineSetupMode;
107
+ runGitConfig?: GitConfigRunner;
108
+ readGit?: GitReader;
109
+ }
110
+ /**
111
+ * Decide, and in `apply` mode set, `extensions.worktreeConfig`.
112
+ *
113
+ * Order (amendment 1 section 2):
114
+ * 1. already `true` locally: `already-set`, nothing more is read. Any other
115
+ * present value (`false`): `not-set` with the command, and no write.
116
+ * 2. count linked worktrees from the common directory.
117
+ * 3. a bare main entry, or any git failure: `could-not-check`.
118
+ * 4. count 0 and the pre-flight passes: set it and report the old and new value.
119
+ * Count above 0, or the pre-flight refuses: `not-set` with the command.
120
+ *
121
+ * THE GUARD IS STRICTER THAN GIT'S OWN HAZARD. With no `config.worktree` files,
122
+ * enabling the extension changes nothing for existing worktrees. It stays,
123
+ * because #919 is the precedent for refusing a shared git config change made
124
+ * from inside one worktree.
125
+ */
126
+ export declare function setWorktreeConfigExtension(opts: WorktreeConfigOptions): SettingResult;
127
+ /**
128
+ * Set `coordination-brief-enabled` to the string "true" when the key is absent.
129
+ *
130
+ * Any present value is respected, `false`, `0` and an empty string included,
131
+ * and reported as `not-set` with the command (amendment 1 section 3). The write
132
+ * goes to a temp file in the same directory and is renamed over the target,
133
+ * after a re-read that confirms the key is still absent.
134
+ *
135
+ * ACCEPTED RISK. Two writers can still race: the window is the time between the
136
+ * re-read and the rename, and a writer outside this function is not covered.
137
+ */
138
+ export declare function ensureBriefEnabled(opts: {
139
+ configPath: string;
140
+ mode: MachineSetupMode;
141
+ beforeConfigWrite?: () => void;
142
+ }): SettingResult;
143
+ /**
144
+ * Report `projectSlug` from the tracked `mx-agent.config.json`. Never written:
145
+ * a clone already carries it. `start` does not set `MX_PRODUCT_SLUG` either,
146
+ * because a process cannot set its parent shell's environment.
147
+ */
148
+ export declare function reportProjectSlug(projectRoot: string): SettingResult;
149
+ /**
150
+ * Check every setting and, in `apply` mode, write the ones whose rule allows it.
151
+ * Never throws for a setting it cannot read: that is a `could-not-check` result.
152
+ */
153
+ export declare function ensureMachineSetup(opts: MachineSetupOptions): MachineSetupResult;
154
+ /** One line for a result. */
155
+ export declare function describeSetting(r: SettingResult): string;
156
+ /**
157
+ * The lines `start` prints. `already-set` prints nothing, so a second start on
158
+ * a configured machine is quiet about these settings. Every other result prints
159
+ * one line, and a write prints its old and new value once.
160
+ */
161
+ export declare function describeMachineSetupForStart(result: MachineSetupResult): string[];
162
+ /** The lines `doctor` prints: every setting, every time. */
163
+ export declare function describeMachineSetupForReport(result: MachineSetupResult): string[];
164
+ export {};
165
+ //# sourceMappingURL=machine-setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"machine-setup.d.ts","sourceRoot":"","sources":["../../src/lib/machine-setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAuBH,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,QAAQ,CAAC;AAClD,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG,KAAK,GAAG,SAAS,GAAG,iBAAiB,CAAC;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