@memnexus-ai/mx-agent-cli 0.1.295-next.0 → 0.1.296-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 (53) hide show
  1. package/dist/__tests__/claude-local-sanitizer.test.d.ts +24 -0
  2. package/dist/__tests__/claude-local-sanitizer.test.d.ts.map +1 -0
  3. package/dist/__tests__/claude-local-sanitizer.test.js +906 -0
  4. package/dist/__tests__/claude-local-sanitizer.test.js.map +1 -0
  5. package/dist/__tests__/coordination-client.test.js +90 -1
  6. package/dist/__tests__/coordination-client.test.js.map +1 -1
  7. package/dist/__tests__/coordination-credential-endpoint.test.js +90 -30
  8. package/dist/__tests__/coordination-credential-endpoint.test.js.map +1 -1
  9. package/dist/__tests__/coordination-status-registration.test.js +8 -8
  10. package/dist/__tests__/coordination-status-registration.test.js.map +1 -1
  11. package/dist/__tests__/coordination-token-multitenant.test.js +14 -14
  12. package/dist/__tests__/coordination-token-multitenant.test.js.map +1 -1
  13. package/dist/__tests__/provision-completion-rows.test.js +96 -4
  14. package/dist/__tests__/provision-completion-rows.test.js.map +1 -1
  15. package/dist/__tests__/row15-detail-sanitizer.test.d.ts +20 -0
  16. package/dist/__tests__/row15-detail-sanitizer.test.d.ts.map +1 -0
  17. package/dist/__tests__/row15-detail-sanitizer.test.js +61 -0
  18. package/dist/__tests__/row15-detail-sanitizer.test.js.map +1 -0
  19. package/dist/commands/coordination.d.ts.map +1 -1
  20. package/dist/commands/coordination.js +5 -0
  21. package/dist/commands/coordination.js.map +1 -1
  22. package/dist/commands/create.d.ts +9 -0
  23. package/dist/commands/create.d.ts.map +1 -1
  24. package/dist/commands/create.js +98 -43
  25. package/dist/commands/create.js.map +1 -1
  26. package/dist/commands/start.d.ts.map +1 -1
  27. package/dist/commands/start.js +6 -0
  28. package/dist/commands/start.js.map +1 -1
  29. package/dist/lib/behavioral-injection.d.ts +9 -0
  30. package/dist/lib/behavioral-injection.d.ts.map +1 -1
  31. package/dist/lib/behavioral-injection.js +10 -1
  32. package/dist/lib/behavioral-injection.js.map +1 -1
  33. package/dist/lib/claude.d.ts +48 -0
  34. package/dist/lib/claude.d.ts.map +1 -1
  35. package/dist/lib/claude.js +172 -22
  36. package/dist/lib/claude.js.map +1 -1
  37. package/dist/lib/coordination-client.d.ts +29 -1
  38. package/dist/lib/coordination-client.d.ts.map +1 -1
  39. package/dist/lib/coordination-client.js +52 -0
  40. package/dist/lib/coordination-client.js.map +1 -1
  41. package/dist/lib/coordination-token.d.ts +42 -13
  42. package/dist/lib/coordination-token.d.ts.map +1 -1
  43. package/dist/lib/coordination-token.js +52 -28
  44. package/dist/lib/coordination-token.js.map +1 -1
  45. package/dist/lib/roster.d.ts +13 -1
  46. package/dist/lib/roster.d.ts.map +1 -1
  47. package/dist/lib/roster.js +7 -3
  48. package/dist/lib/roster.js.map +1 -1
  49. package/dist/lib/roster.test.js +4 -4
  50. package/dist/lib/roster.test.js.map +1 -1
  51. package/dist/lib/team-identity.js +2 -2
  52. package/dist/lib/team-identity.js.map +1 -1
  53. package/package.json +1 -1
@@ -18,6 +18,18 @@ import { vaultTokenPresent, VAULT_NAME } from '../lib/vault.js';
18
18
  // Row 10's other half (#288). For a credential-endpoint project the row asks
19
19
  // whether a credential is OBTAINABLE, not whether a Key Vault secret exists.
20
20
  import { usesCredentialEndpoint, provisionCredentialForWorktree, credentialCacheState, credentialCachePath, writeCredentialCache, } from '../lib/coordination-token.js';
21
+ /**
22
+ * Row 10's remedy for a 403 in a project the coordination service creates on
23
+ * login (#507). The compiled-project remedy ("an operator creates a grant", or
24
+ * row 9's "add the team to PROVISIONED_ROSTERS") is wrong there: the project is
25
+ * in no compiled roster by design. Fixed text: the service's 403 is
26
+ * byte-identical whether the team exists or not, and this adds nothing that
27
+ * tells the two apart.
28
+ */
29
+ export const SELF_SERVICE_REFUSED_DETAIL = 'the coordination service refused this identity for the team. In a project the service created on login, ' +
30
+ 'only the project\'s owner creates teams, and any other identity needs an operator grant on an existing team. ' +
31
+ 'Run this from the owner\'s MemNexus login (mx auth login), or ask an operator to add the team with ' +
32
+ 'POST /admin/provision and grant you with POST /admin/grant';
21
33
  import { isMxAvailable, bootstrapTeamMemories, logMemoryResult, teamMemorySpecs, logManualMemoryCommands, namedMemoryExists, namedMemoryResolvesById, readNamedMemoryJson, shellSingleQuote, PROVISIONED_MEMORY_SERVICE, EXTRA_ANCHOR_SUFFIX_RE } from '../lib/memory.js';
22
34
  // The reader `mx-agent window` uses, imported rather than reimplemented: rows 3
23
35
  // to 5 assert that the fleet view can read the seed, and a local copy of the
@@ -2521,50 +2533,81 @@ function checkCompletionRows(i) {
2521
2533
  // `origin/<base>`; row 10 asks the vault whether a secret of the team's name
2522
2534
  // exists, and never for its value.
2523
2535
  const rosterRef = `origin/${i.baseBranch}`;
2524
- const jsonRoster = i.projectRoot
2536
+ const rosterEntry = i.projectRoot
2525
2537
  ? rosterEntryOnRef(i.projectRoot, i.slug, { project: i.projectSlug, baseBranch: i.baseBranch, fetchOk: i.fetchOk })
2526
2538
  : 'unresolvable';
2539
+ // A SELF-SERVICE PROJECT (#507): it takes the credential endpoint and the
2540
+ // roster file on the ref keys no roster for it, so it is not compiled into
2541
+ // the coordination service. The service is then the registry: the first
2542
+ // credential request by the project's owner creates the team. Row 9 is
2543
+ // answered by that request (row 10) rather than by a compiled file the
2544
+ // project will never appear in. Every other project reads `project-absent`
2545
+ // as `absent` and keeps the behaviour it had.
2546
+ const selfService = usesCredentialEndpoint(i.projectSlug) && rosterEntry === 'project-absent';
2547
+ const jsonRoster = rosterEntry === 'project-absent' ? 'absent' : rosterEntry;
2527
2548
  // Asked only when the generated file does not hold the slug: it separates "the
2528
2549
  // source was edited and the file was not regenerated" from "neither was done",
2529
2550
  // and those have different remedies.
2530
- const sourceRoster = jsonRoster === 'present' || !i.projectRoot
2551
+ const sourceRoster = jsonRoster === 'present' || !i.projectRoot || selfService
2531
2552
  ? 'absent'
2532
2553
  : rosterSourceHasSlug(i.projectRoot, i.slug, i.projectSlug, { baseBranch: i.baseBranch, fetchOk: i.fetchOk });
2533
- rows.push({
2534
- n: 9,
2535
- label: `coordination roster entry for ${i.slug}`,
2536
- asserted: jsonRoster === 'present',
2537
- // Partly asserted is its own state: the service would admit the team once
2538
- // redeployed, and every CLI reading the generated file still refuses it.
2539
- partlyAsserted: jsonRoster !== 'present' && sourceRoster === 'present',
2540
- // Could-not-run is this row's own word too (#408). Without it the verdict
2541
- // column printed `not asserted` on a ref this run could not read, while the
2542
- // detail beside it said the roster is not established either way: the same
2543
- // upstream cause row 10 already prints `could not run` for. The condition is
2544
- // exactly the detail branch below that says "could not read", so the word
2545
- // and the sentence cannot disagree.
2546
- //
2547
- // `sourceRoster === 'present'` is excluded because that is `partlyAsserted`,
2548
- // a state where something DID hold: the source array on the ref names the
2549
- // team. The renderer checks could-not-run first (`create.ts:3437-3441`), so
2550
- // the two conditions are kept disjoint here rather than left to that order.
2551
- couldNotRun: jsonRoster === 'unresolvable' && sourceRoster !== 'present',
2552
- detail: jsonRoster === 'present'
2553
- ? `token-eligible per PROVISIONED_ROSTERS on ${rosterRef}; this row cannot see whether the service was redeployed`
2554
- : sourceRoster === 'present'
2555
- ? `in rosters.ts on ${rosterRef}, generated JSON stale; run generate-rosters (step 6a): `
2556
- + 'cd mx-agent-system/coordination-service && npm run build, then node dist/admin/generate-rosters.js > '
2557
- + '../agent-config/coordination-rosters.generated.json'
2558
- : jsonRoster === 'unresolvable'
2559
- ? `could not read ${rosterRef}: the roster is not established either way`
2560
- : `add ${i.slug} to the project's array in PROVISIONED_ROSTERS `
2561
- + '(coordination-service/src/config/rosters.ts), regenerate '
2562
- + 'mx-agent-system/agent-config/coordination-rosters.generated.json (cd '
2563
- + 'mx-agent-system/coordination-service && npm run build, then node dist/admin/generate-rosters.js > '
2564
- + `../agent-config/coordination-rosters.generated.json), and merge both in the step 6a PR; `
2565
- + 'this row cannot see whether the service was redeployed',
2566
- required: true,
2567
- });
2554
+ if (selfService) {
2555
+ const cred = i.credential;
2556
+ const held = cred?.kind === 'obtainable' && cred.mode === 0o600;
2557
+ rows.push({
2558
+ n: 9,
2559
+ label: `coordination roster entry for ${i.slug}`,
2560
+ asserted: held,
2561
+ couldNotRun: !held && cred?.kind !== 'refused',
2562
+ detail: held
2563
+ ? `project ${i.projectSlug} is in no compiled roster on ${rosterRef}, so the coordination service is its registry (#507); `
2564
+ + (cred.fromCache === true
2565
+ ? 'a credential cache for the team is present (row 10), and this run asked the service for nothing'
2566
+ : 'the credential request in row 10 succeeded, which registers the team on the service')
2567
+ : cred?.kind === 'refused'
2568
+ ? `project ${i.projectSlug} is in no compiled roster on ${rosterRef}, so the coordination service decides `
2569
+ + 'registration at the credential request, and it refused (row 10)'
2570
+ : `project ${i.projectSlug} is in no compiled roster on ${rosterRef}, so the coordination service decides `
2571
+ + 'registration at the credential request (row 10), which did not complete',
2572
+ required: true,
2573
+ });
2574
+ }
2575
+ else
2576
+ rows.push({
2577
+ n: 9,
2578
+ label: `coordination roster entry for ${i.slug}`,
2579
+ asserted: jsonRoster === 'present',
2580
+ // Partly asserted is its own state: the service would admit the team once
2581
+ // redeployed, and every CLI reading the generated file still refuses it.
2582
+ partlyAsserted: jsonRoster !== 'present' && sourceRoster === 'present',
2583
+ // Could-not-run is this row's own word too (#408). Without it the verdict
2584
+ // column printed `not asserted` on a ref this run could not read, while the
2585
+ // detail beside it said the roster is not established either way: the same
2586
+ // upstream cause row 10 already prints `could not run` for. The condition is
2587
+ // exactly the detail branch below that says "could not read", so the word
2588
+ // and the sentence cannot disagree.
2589
+ //
2590
+ // `sourceRoster === 'present'` is excluded because that is `partlyAsserted`,
2591
+ // a state where something DID hold: the source array on the ref names the
2592
+ // team. The renderer checks could-not-run first (`create.ts:3437-3441`), so
2593
+ // the two conditions are kept disjoint here rather than left to that order.
2594
+ couldNotRun: jsonRoster === 'unresolvable' && sourceRoster !== 'present',
2595
+ detail: jsonRoster === 'present'
2596
+ ? `token-eligible per PROVISIONED_ROSTERS on ${rosterRef}; this row cannot see whether the service was redeployed`
2597
+ : sourceRoster === 'present'
2598
+ ? `in rosters.ts on ${rosterRef}, generated JSON stale; run generate-rosters (step 6a): `
2599
+ + 'cd mx-agent-system/coordination-service && npm run build, then node dist/admin/generate-rosters.js > '
2600
+ + '../agent-config/coordination-rosters.generated.json'
2601
+ : jsonRoster === 'unresolvable'
2602
+ ? `could not read ${rosterRef}: the roster is not established either way`
2603
+ : `add ${i.slug} to the project's array in PROVISIONED_ROSTERS `
2604
+ + '(coordination-service/src/config/rosters.ts), regenerate '
2605
+ + 'mx-agent-system/agent-config/coordination-rosters.generated.json (cd '
2606
+ + 'mx-agent-system/coordination-service && npm run build, then node dist/admin/generate-rosters.js > '
2607
+ + `../agent-config/coordination-rosters.generated.json), and merge both in the step 6a PR; `
2608
+ + 'this row cannot see whether the service was redeployed',
2609
+ required: true,
2610
+ });
2568
2611
  // Row 10 asks the vault ONLY when row 9 says the team is token-eligible
2569
2612
  // (security review, Should Fix 1). Two reasons, both about projects that are
2570
2613
  // not this tenant. A project whose roster this vault does not serve would get
@@ -2589,7 +2632,9 @@ function checkCompletionRows(i) {
2589
2632
  // POST /admin/grant first. For every real team the row is unchanged: an
2590
2633
  // operator grant is what authorises it, and its absence is the same 403.
2591
2634
  if (usesCredentialEndpoint(i.projectSlug)) {
2592
- const cred = jsonRoster === 'present' ? i.credential : undefined;
2635
+ // A self-service project's request is not gated on row 9: that request is
2636
+ // what registers the team (#507).
2637
+ const cred = jsonRoster === 'present' || selfService ? i.credential : undefined;
2593
2638
  // #290 Should Fix 3: the row asserts on the CACHE, not only on the issue.
2594
2639
  //
2595
2640
  // The claim the label makes is that the new team's first session can read its
@@ -2603,7 +2648,7 @@ function checkCompletionRows(i) {
2603
2648
  // the check not completing, and the remedies are different.
2604
2649
  const credCouldNotRun = cred?.kind === 'could-not-run'
2605
2650
  || (cred?.kind === 'obtainable' && cred.mode !== 0o600)
2606
- || (cred === undefined && jsonRoster !== 'absent');
2651
+ || (cred === undefined && (jsonRoster !== 'absent' || selfService));
2607
2652
  // `--recheck` writes nothing, so it never asks the service. The row states
2608
2653
  // which question it actually answered, and names the command that mints
2609
2654
  // (#316 change D, red-team Major 6). Appended to whichever detail the row
@@ -2641,12 +2686,14 @@ function checkCompletionRows(i) {
2641
2686
  : `its mode is ${cred.mode.toString(8).padStart(4, '0')}, not 0600: every account on this host can read it. `
2642
2687
  + `Remove ${cred.cachePath} and re-run`)
2643
2688
  : cred?.kind === 'refused'
2644
- ? `${cred.detail} (step 6a2)`
2689
+ ? selfService && cred.reason === 'not-authorized'
2690
+ ? SELF_SERVICE_REFUSED_DETAIL
2691
+ : `${cred.detail} (step 6a2)`
2645
2692
  : cred?.kind === 'could-not-run'
2646
2693
  ? cred.detail
2647
2694
  : jsonRoster === 'unresolvable'
2648
2695
  ? `could not read ${rosterRef} (row 9), so credential eligibility is not established; no credential requested`
2649
- : jsonRoster === 'present'
2696
+ : jsonRoster === 'present' || selfService
2650
2697
  ? 'no credential was requested by this run, so nothing is established either way'
2651
2698
  : `not token-eligible until the roster entry is on ${rosterRef} (row 9); no credential requested`) + cacheOnlyNote,
2652
2699
  required: true,
@@ -2774,7 +2821,12 @@ function gitIdentityRow(worktreePath, slug) {
2774
2821
  n: 15,
2775
2822
  label,
2776
2823
  asserted: true,
2777
- detail: `${state.name} <${state.email}>, ${state.reason}`,
2824
+ // Sanitized for the terminal (#436, #460 plan #500 item 3). `reason` names
2825
+ // the config.worktree path git reported, and a path can hold U+2028,
2826
+ // U+2029 or U+202E, which break or reverse the printed row. `name` and
2827
+ // `email` equal the slug here and are covered by the same call. The cap is
2828
+ // PATH_MAX plus room for the identity, so no real path is truncated.
2829
+ detail: sanitizeForMessage(`${state.name} <${state.email}>, ${state.reason}`, 4400),
2778
2830
  required: false,
2779
2831
  };
2780
2832
  }
@@ -5132,7 +5184,10 @@ async function runProvisionSteps(ctx) {
5132
5184
  baseBranch: cfg.baseBranch,
5133
5185
  fetchOk,
5134
5186
  });
5135
- if (eligible === 'present') {
5187
+ // `project-absent` is a project the service creates on login (#507): this
5188
+ // request is what registers the team, so it is not gated on a compiled
5189
+ // roster the project will never appear in. The row reads the same answer.
5190
+ if (eligible === 'present' || eligible === 'project-absent') {
5136
5191
  // A credential fault point mints a real token and then fails the write
5137
5192
  // that keeps it, so it runs against a stub on this host or it does not run
5138
5193
  // (security review round 2, Should Fix 2). Refused BEFORE the request, not