@memnexus-ai/mx-agent-cli 0.1.296-next.5 → 0.1.296-next.7
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.
- package/dist/__tests__/catalog-origin-main.test.js +12 -3
- package/dist/__tests__/catalog-origin-main.test.js.map +1 -1
- package/dist/__tests__/init-coordination-url.test.js +108 -5
- package/dist/__tests__/init-coordination-url.test.js.map +1 -1
- package/dist/__tests__/new-project-first-team.test.js +182 -1
- package/dist/__tests__/new-project-first-team.test.js.map +1 -1
- package/dist/__tests__/provision-behavioral-contract.test.js +3 -1
- package/dist/__tests__/provision-behavioral-contract.test.js.map +1 -1
- package/dist/__tests__/provision-catalog-precondition.test.js +3 -1
- package/dist/__tests__/provision-catalog-precondition.test.js.map +1 -1
- package/dist/__tests__/provision-completion-rows.test.js +27 -6
- package/dist/__tests__/provision-completion-rows.test.js.map +1 -1
- package/dist/__tests__/provision-identity-gate.test.js +3 -1
- package/dist/__tests__/provision-identity-gate.test.js.map +1 -1
- package/dist/__tests__/provision-resume.test.js +35 -1
- package/dist/__tests__/provision-resume.test.js.map +1 -1
- package/dist/__tests__/provision-row12-stub-server.test.js +3 -1
- package/dist/__tests__/provision-row12-stub-server.test.js.map +1 -1
- package/dist/__tests__/provision-skeleton-fill.test.js +3 -1
- package/dist/__tests__/provision-skeleton-fill.test.js.map +1 -1
- package/dist/__tests__/provision-step8-commit.test.d.ts +40 -0
- package/dist/__tests__/provision-step8-commit.test.d.ts.map +1 -0
- package/dist/__tests__/provision-step8-commit.test.js +529 -0
- package/dist/__tests__/provision-step8-commit.test.js.map +1 -0
- package/dist/__tests__/provision-teambuilder-flow.test.js +3 -1
- package/dist/__tests__/provision-teambuilder-flow.test.js.map +1 -1
- package/dist/__tests__/rows-9-10-zero-remotes.test.d.ts +32 -0
- package/dist/__tests__/rows-9-10-zero-remotes.test.d.ts.map +1 -0
- package/dist/__tests__/rows-9-10-zero-remotes.test.js +203 -0
- package/dist/__tests__/rows-9-10-zero-remotes.test.js.map +1 -0
- package/dist/__tests__/template-sync.test.js +5 -1
- package/dist/__tests__/template-sync.test.js.map +1 -1
- package/dist/commands/create.d.ts +124 -0
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +319 -87
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/new.d.ts +38 -0
- package/dist/commands/new.d.ts.map +1 -1
- package/dist/commands/new.js +118 -7
- package/dist/commands/new.js.map +1 -1
- package/dist/lib/catalog-commit.d.ts +99 -0
- package/dist/lib/catalog-commit.d.ts.map +1 -0
- package/dist/lib/catalog-commit.js +315 -0
- package/dist/lib/catalog-commit.js.map +1 -0
- package/dist/lib/catalog.d.ts +16 -8
- package/dist/lib/catalog.d.ts.map +1 -1
- package/dist/lib/catalog.js +17 -9
- package/dist/lib/catalog.js.map +1 -1
- package/dist/lib/roster.d.ts +19 -0
- package/dist/lib/roster.d.ts.map +1 -1
- package/dist/lib/roster.js +18 -8
- package/dist/lib/roster.js.map +1 -1
- package/package.json +1 -1
package/dist/commands/create.js
CHANGED
|
@@ -10,7 +10,8 @@ import chalk from 'chalk';
|
|
|
10
10
|
import { findProjectRoot, findTeamWorktree, assignSlot, getCurrentBranch, fetchOrigin, createGitWorktree, addToGitSafeDirectory, createHuskySymlink, generateBranchName, generateWorktreeDirName, listRemotes, } from '../lib/worktree.js';
|
|
11
11
|
import { syncClaudeConfig, deployClaudeMd, writeClaudeLocal, readBehavioralPointer, logSuccess, logWarning, logDim } from '../lib/claude.js';
|
|
12
12
|
import { writeTeamCatalog, slugToDisplayName, getTeamCatalogPath, catalogEntryOnOriginMain, catalogEntryOnRef, roleguideOnOriginMain, isReadableRepoPath, listTeams, getTeam, serializeTeamEntry } from '../lib/catalog.js';
|
|
13
|
-
import { rosterEntryOnRef, rosterSourceHasSlug } from '../lib/roster.js';
|
|
13
|
+
import { rosterEntryOnRef, rosterSourceHasSlug, rosterRefFor } from '../lib/roster.js';
|
|
14
|
+
import { commitCatalogEntry } from '../lib/catalog-commit.js';
|
|
14
15
|
// The build boundary (#123). Its own module for the reason `lib/roster.ts` and
|
|
15
16
|
// `lib/vault.ts` are: the completion-row tests stub each boundary by module.
|
|
16
17
|
import { buildCliInWorktree, probeBuiltCli, REBUILD_REMEDY } from '../lib/cli-build.js';
|
|
@@ -2051,6 +2052,35 @@ function checkSeedShape(name, leaderState, requireProduct) {
|
|
|
2051
2052
|
}
|
|
2052
2053
|
/** Row 3 for the extras: they hang off row 3 and are told apart by the letter. */
|
|
2053
2054
|
const EXTRA_ANCHOR_ROW_N = 3;
|
|
2055
|
+
/**
|
|
2056
|
+
* The roster read rows 9 and 10 rest on, and the ref it read (#607).
|
|
2057
|
+
*
|
|
2058
|
+
* ONE helper for three callers: `checkCompletionRows` (rows 9 and 10), the
|
|
2059
|
+
* credential gate at step 8b of `runProvisionSteps`, and `--recheck`, which
|
|
2060
|
+
* reaches it through `checkCompletionRows`. Three copies could read three
|
|
2061
|
+
* different refs, and the row would then report about a ref the gate never
|
|
2062
|
+
* consulted.
|
|
2063
|
+
*
|
|
2064
|
+
* THE LOCAL READ is taken only when `remotes` is an empty list, which the caller
|
|
2065
|
+
* established with `git remote` itself (`remotes !== null && remotes.length ===
|
|
2066
|
+
* 0`). A freshly scaffolded project has no `origin/<base>`, and before this
|
|
2067
|
+
* every `new project` read could-not-run on row 9 and never asked for a
|
|
2068
|
+
* credential. Its base branch is local, so it reads `refs/heads/<base>`, the
|
|
2069
|
+
* full ref, never a bare branch name a tag of the same name could shadow.
|
|
2070
|
+
*
|
|
2071
|
+
* EVERYTHING ELSE IS UNCHANGED: a project with an `origin`, a `git remote` that
|
|
2072
|
+
* did not run (`null`), a caller that passed no list, and remotes without an
|
|
2073
|
+
* `origin` all read `origin/<base>` under the fetch gate exactly as before.
|
|
2074
|
+
*/
|
|
2075
|
+
function rosterReadForRows(i) {
|
|
2076
|
+
const localBase = Array.isArray(i.remotes) && i.remotes.length === 0;
|
|
2077
|
+
const readOpts = { baseBranch: i.baseBranch, fetchOk: i.fetchOk, localBase };
|
|
2078
|
+
const ref = rosterRefFor(readOpts);
|
|
2079
|
+
const entry = i.projectRoot
|
|
2080
|
+
? rosterEntryOnRef(i.projectRoot, i.slug, { project: i.projectSlug, ...readOpts })
|
|
2081
|
+
: 'unresolvable';
|
|
2082
|
+
return { entry, ref, readOpts };
|
|
2083
|
+
}
|
|
2054
2084
|
/** Row 12's label: exactly what the probe proves, and nothing it does not (#15). */
|
|
2055
2085
|
const ROW_12_LABEL = 'the new team\'s token authenticates to the coordination service (GET /obligations 200)';
|
|
2056
2086
|
/**
|
|
@@ -2546,10 +2576,20 @@ function checkCompletionRows(i) {
|
|
|
2546
2576
|
// Neither row writes anything. Row 9 reads two committed files on
|
|
2547
2577
|
// `origin/<base>`; row 10 asks the vault whether a secret of the team's name
|
|
2548
2578
|
// exists, and never for its value.
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2579
|
+
// THE SHARED READ (#607): the same helper step 8b gates the credential request
|
|
2580
|
+
// on and `--recheck` reaches through this function, so the three cannot read
|
|
2581
|
+
// different refs. `rosterRef` is the ref it actually read, and every detail
|
|
2582
|
+
// string below names that ref.
|
|
2583
|
+
const rosterRead = rosterReadForRows({
|
|
2584
|
+
projectRoot: i.projectRoot,
|
|
2585
|
+
slug: i.slug,
|
|
2586
|
+
projectSlug: i.projectSlug,
|
|
2587
|
+
baseBranch: i.baseBranch,
|
|
2588
|
+
fetchOk: i.fetchOk,
|
|
2589
|
+
remotes: i.remotes,
|
|
2590
|
+
});
|
|
2591
|
+
const rosterRef = rosterRead.ref;
|
|
2592
|
+
const rosterEntry = rosterRead.entry;
|
|
2553
2593
|
// A SELF-SERVICE PROJECT (#507): it takes the credential endpoint and the
|
|
2554
2594
|
// roster file on the ref keys no roster for it, so it is not compiled into
|
|
2555
2595
|
// the coordination service. The service is then the registry: the first
|
|
@@ -2564,7 +2604,7 @@ function checkCompletionRows(i) {
|
|
|
2564
2604
|
// and those have different remedies.
|
|
2565
2605
|
const sourceRoster = jsonRoster === 'present' || !i.projectRoot || selfService
|
|
2566
2606
|
? 'absent'
|
|
2567
|
-
: rosterSourceHasSlug(i.projectRoot, i.slug, i.projectSlug,
|
|
2607
|
+
: rosterSourceHasSlug(i.projectRoot, i.slug, i.projectSlug, rosterRead.readOpts);
|
|
2568
2608
|
if (selfService) {
|
|
2569
2609
|
const cred = i.credential;
|
|
2570
2610
|
const held = cred?.kind === 'obtainable' && cred.mode === 0o600;
|
|
@@ -2952,7 +2992,9 @@ function buildRow(build, slug) {
|
|
|
2952
2992
|
// The one branch that is not required. Row 0 uses the same shape for a
|
|
2953
2993
|
// project with no `projectSlug` (`create.ts:2561-2576`): a claim this project
|
|
2954
2994
|
// cannot make is not a claim it failed.
|
|
2955
|
-
|
|
2995
|
+
// The verdict column prints `not applicable` (#613 item 2), so the detail
|
|
2996
|
+
// states the reason without repeating the word.
|
|
2997
|
+
return { n: 14, label, asserted: false, detail: build.detail, required: false, notApplicable: true };
|
|
2956
2998
|
}
|
|
2957
2999
|
if (build.kind === 'not-reached') {
|
|
2958
3000
|
return { n: 14, label, asserted: false, detail: `not built: ${build.detail}`, required: true };
|
|
@@ -3048,19 +3090,24 @@ function printCompletionRows(rows) {
|
|
|
3048
3090
|
// not look has not had a part hold, so the two are not the same state and the
|
|
3049
3091
|
// yellow they share does not make them one (#290 Should Fix 4).
|
|
3050
3092
|
const couldNotRun = !row.asserted && row.couldNotRun === true;
|
|
3093
|
+
// Not applicable is its own word too (#613 item 2): a row whose claim this
|
|
3094
|
+
// project cannot make is not a step the command handed the operator.
|
|
3095
|
+
const notApplicable = !row.asserted && row.notApplicable === true;
|
|
3051
3096
|
const verdict = row.asserted
|
|
3052
3097
|
? row.stale === true
|
|
3053
3098
|
// Asserted, and not this run's content. Yellow, because the reader has
|
|
3054
3099
|
// something to look at even though nothing failed.
|
|
3055
3100
|
? chalk.yellow('asserted, stale ')
|
|
3056
3101
|
: chalk.green(row.shapeAsserted ? 'asserted (shape)' : 'asserted ')
|
|
3057
|
-
:
|
|
3058
|
-
? chalk.
|
|
3059
|
-
:
|
|
3060
|
-
? chalk.yellow('
|
|
3061
|
-
:
|
|
3062
|
-
? chalk.
|
|
3063
|
-
:
|
|
3102
|
+
: notApplicable
|
|
3103
|
+
? chalk.dim('not applicable ')
|
|
3104
|
+
: couldNotRun
|
|
3105
|
+
? chalk.yellow('could not run ')
|
|
3106
|
+
: partlyAsserted
|
|
3107
|
+
? chalk.yellow('partly asserted ')
|
|
3108
|
+
: row.required
|
|
3109
|
+
? chalk.red('not asserted ')
|
|
3110
|
+
: chalk.yellow('not asserted ');
|
|
3064
3111
|
const detail = row.detail;
|
|
3065
3112
|
// Printed for asserted rows too: when a row is green on the probe rather than
|
|
3066
3113
|
// on the id read, the reader is told which evidence held.
|
|
@@ -4154,6 +4201,7 @@ export async function runCreate(options) {
|
|
|
4154
4201
|
resuming,
|
|
4155
4202
|
fetchOk,
|
|
4156
4203
|
projectHasOrigin,
|
|
4204
|
+
remotes,
|
|
4157
4205
|
nameCheckSpecs,
|
|
4158
4206
|
});
|
|
4159
4207
|
}
|
|
@@ -4337,6 +4385,9 @@ async function runRecheck(i) {
|
|
|
4337
4385
|
projectRoot,
|
|
4338
4386
|
fetchOk,
|
|
4339
4387
|
hasOrigin: projectHasOrigin,
|
|
4388
|
+
// The same list the provisioning run reads, so a re-check of a project
|
|
4389
|
+
// with zero remotes reads rows 9 and 10 off the same local ref (#607).
|
|
4390
|
+
remotes,
|
|
4340
4391
|
catalogOnOriginMainPath: `${cfg.teamsDir}/${slug}.md`,
|
|
4341
4392
|
// Row 7 asks whether that same file is on the base branch. NOTHING IS COPIED
|
|
4342
4393
|
// on a re-check, so this is a reconstruction, not the destination a copy
|
|
@@ -4412,6 +4463,213 @@ function memoryOwnership(codeContext, teamSlug, projectSlug) {
|
|
|
4412
4463
|
? 'this-team'
|
|
4413
4464
|
: 'not-this-team';
|
|
4414
4465
|
}
|
|
4466
|
+
/**
|
|
4467
|
+
* Step 8 of provisioning: the catalog entry (#51, #607).
|
|
4468
|
+
*
|
|
4469
|
+
* WITH AN `origin`, unchanged: the entry is on the base branch already, asserted
|
|
4470
|
+
* at step 0c, and the new worktree holds it from its own checkout. Writing a
|
|
4471
|
+
* second copy relative to `projectRoot` is what produced the untracked file in
|
|
4472
|
+
* the main checkout, and `writeTeamCatalog` is an unconditional write, so that
|
|
4473
|
+
* copy would also replace a hand-curated entry with the placeholder version.
|
|
4474
|
+
*
|
|
4475
|
+
* WITH ZERO REMOTES (#607), the entry is written in the project root and then
|
|
4476
|
+
* COMMITTED there, on the base branch, and the team worktree is fast-forwarded
|
|
4477
|
+
* to that commit (`lib/catalog-commit.ts` states the order and why). No
|
|
4478
|
+
* untracked copy is written into the worktree. Before this, both trees held the
|
|
4479
|
+
* entry untracked, one `git add -A` away, and every later read of the base
|
|
4480
|
+
* branch missed it.
|
|
4481
|
+
*
|
|
4482
|
+
* WHEN THE COMMIT CANNOT BE MADE, the run falls back to what it did before:
|
|
4483
|
+
* the entry stays written and uncommitted, it is copied into the worktree, and a
|
|
4484
|
+
* named step states the cause and the exact commands that finish the job.
|
|
4485
|
+
* Provisioning does not fail on it: the team is provisioned, and only the commit
|
|
4486
|
+
* is left. A refused run writes and commits nothing, unchanged from v6.
|
|
4487
|
+
*
|
|
4488
|
+
* Exported through `__testing` so the commit half is asserted against real git
|
|
4489
|
+
* in a temporary repository rather than inferred from a mock.
|
|
4490
|
+
*/
|
|
4491
|
+
function catalogEntryStep(i) {
|
|
4492
|
+
const { projectRoot, worktreePath, slug, teamsDir } = i;
|
|
4493
|
+
let catalogState;
|
|
4494
|
+
let commit = { kind: 'not-attempted' };
|
|
4495
|
+
const relPath = `${teamsDir.split(sep).join('/').replace(/\/+$/, '')}/${slug}.md`;
|
|
4496
|
+
console.log();
|
|
4497
|
+
console.log(chalk.bold(' Catalog entry:'));
|
|
4498
|
+
try {
|
|
4499
|
+
if (i.refusedBy !== null && !i.projectHasOrigin) {
|
|
4500
|
+
// `writeTeamCatalog` is an unconditional write. On a refused run it would
|
|
4501
|
+
// put a placeholder entry into the project, and a second run would write
|
|
4502
|
+
// over whatever the operator edited in between. The v6 ruling holds: never
|
|
4503
|
+
// write into a file the operator may have edited.
|
|
4504
|
+
logWarning(i.refusedBy === 'row13'
|
|
4505
|
+
? 'skipped: the roleguide still has placeholders (row 13). Not written on a refused run.'
|
|
4506
|
+
: 'skipped: the roleguide\'s Named Memory Anchors table was refused (row 3a). Not written on a refused run.');
|
|
4507
|
+
}
|
|
4508
|
+
else if (i.projectHasOrigin) {
|
|
4509
|
+
logSuccess(`${teamsDir}/${slug}.md (on origin/${i.baseBranch}, written by team-builder step 5)`);
|
|
4510
|
+
}
|
|
4511
|
+
else if (i.resuming && existsSync(getTeamCatalogPath(projectRoot, slug, teamsDir))) {
|
|
4512
|
+
catalogState = catalogEntryState({
|
|
4513
|
+
path: getTeamCatalogPath(projectRoot, slug, teamsDir),
|
|
4514
|
+
expected: serializeTeamEntry(i.entry()),
|
|
4515
|
+
});
|
|
4516
|
+
// TERMINAL FOR ROW 2 (#316 change B, red-team finding 8). `writeTeamCatalog`
|
|
4517
|
+
// is an unconditional write, so a resume that called it would replace an
|
|
4518
|
+
// entry the operator edited between the two runs with the placeholder
|
|
4519
|
+
// version. An entry that is there is the row's claim met, whoever wrote it,
|
|
4520
|
+
// and row 2 now says whether its content is this run's. The commit below
|
|
4521
|
+
// takes the file AS IT IS, for the same reason: it writes nothing (#607).
|
|
4522
|
+
logSuccess(catalogState?.kind === 'present-stale'
|
|
4523
|
+
? `${teamsDir}/${slug}.md (already written and edited since; a resume leaves it byte for byte)`
|
|
4524
|
+
: `${teamsDir}/${slug}.md (already written; a resume leaves it byte for byte)`);
|
|
4525
|
+
}
|
|
4526
|
+
else {
|
|
4527
|
+
writeTeamCatalog(projectRoot, i.entry(), teamsDir);
|
|
4528
|
+
logSuccess(`mx-agent-system/teams/${slug}.md`);
|
|
4529
|
+
}
|
|
4530
|
+
// ── The commit, on a project with zero remotes only (#607) ──
|
|
4531
|
+
//
|
|
4532
|
+
// `remotes` is the list step 0c read, never null here. Remotes without an
|
|
4533
|
+
// `origin` were refused at step 0c, so an empty list is the only
|
|
4534
|
+
// origin-less state that reaches this line.
|
|
4535
|
+
const zeroRemotes = !i.projectHasOrigin && i.remotes.length === 0;
|
|
4536
|
+
if (zeroRemotes && i.refusedBy === null && existsSync(join(projectRoot, relPath))) {
|
|
4537
|
+
commit = commitCatalogEntry({
|
|
4538
|
+
projectRoot,
|
|
4539
|
+
worktreePath,
|
|
4540
|
+
baseBranch: i.baseBranch,
|
|
4541
|
+
relPath,
|
|
4542
|
+
message: `chore: add the ${slug} catalog entry`,
|
|
4543
|
+
env: i.env,
|
|
4544
|
+
});
|
|
4545
|
+
if (commit.kind === 'committed') {
|
|
4546
|
+
logSuccess(`${relPath} committed on ${i.baseBranch} (${commit.sha.slice(0, 7)}); the team worktree holds the same commit`);
|
|
4547
|
+
}
|
|
4548
|
+
else if (commit.kind === 'already-tracked') {
|
|
4549
|
+
logSuccess(commit.worktreeUpdated
|
|
4550
|
+
? `${relPath} was already committed on ${i.baseBranch}; the team worktree was fast-forwarded to it`
|
|
4551
|
+
: `${relPath} is already committed on ${i.baseBranch}, and the team worktree holds it; nothing committed`);
|
|
4552
|
+
}
|
|
4553
|
+
}
|
|
4554
|
+
// Also copy the catalog entry to the new worktree so it's visible there.
|
|
4555
|
+
//
|
|
4556
|
+
// NOT on the zero-remote path once the entry is on the base branch: the
|
|
4557
|
+
// worktree then holds it as a tracked file, or is one merge away from it,
|
|
4558
|
+
// and an untracked copy is exactly the stray path #607 removes. The copy
|
|
4559
|
+
// runs on every other path, which is the fallback included.
|
|
4560
|
+
//
|
|
4561
|
+
// FILESYSTEM SINK — same shape as 6b, same containment. Lower risk (the path
|
|
4562
|
+
// is built from in-repo reviewed config plus a slug already validated against
|
|
4563
|
+
// SLUG_RE), but identical in form, and a second uncontained copy is not left
|
|
4564
|
+
// behind just because its inputs look trustworthy today.
|
|
4565
|
+
// source root : projectRoot
|
|
4566
|
+
// source path : catalogInSource (projectRoot + configured teamsDir + validated slug)
|
|
4567
|
+
// destination : reanchorContained(...)
|
|
4568
|
+
// mode : 0644, fixed
|
|
4569
|
+
const skipCopy = commit.kind === 'committed' || commit.kind === 'already-tracked' || commit.kind === 'worktree-behind';
|
|
4570
|
+
const catalogInSource = join(projectRoot, teamsDir, `${slug}.md`);
|
|
4571
|
+
if (!skipCopy && existsSync(catalogInSource)) {
|
|
4572
|
+
const anchoredCatalog = reanchorContained(projectRoot, catalogInSource, worktreePath);
|
|
4573
|
+
if (!anchoredCatalog.ok) {
|
|
4574
|
+
logWarning(`Could not copy the catalog entry into the new worktree: ${anchoredCatalog.detail}`);
|
|
4575
|
+
}
|
|
4576
|
+
else if (!existsSync(anchoredCatalog.dest)) {
|
|
4577
|
+
const bytes = readFileSync(catalogInSource, 'utf-8');
|
|
4578
|
+
const written = writeContained(anchoredCatalog.dest, realpathSync(worktreePath), bytes);
|
|
4579
|
+
if (!written.ok) {
|
|
4580
|
+
logWarning(`Could not copy the catalog entry into the new worktree: ${written.detail}`);
|
|
4581
|
+
}
|
|
4582
|
+
}
|
|
4583
|
+
}
|
|
4584
|
+
}
|
|
4585
|
+
catch (err) {
|
|
4586
|
+
logWarning(`Could not write catalog entry: ${err instanceof Error ? err.message : String(err)}`);
|
|
4587
|
+
}
|
|
4588
|
+
// NAMED, never a bare warning (#607). Printed outside the try above, so the
|
|
4589
|
+
// catch cannot swallow it, and after the copy, so the commands it names match
|
|
4590
|
+
// the state the run leaves.
|
|
4591
|
+
for (const line of catalogCommitStepLines({
|
|
4592
|
+
commit,
|
|
4593
|
+
projectRoot,
|
|
4594
|
+
worktreePath,
|
|
4595
|
+
relPath,
|
|
4596
|
+
baseBranch: i.baseBranch,
|
|
4597
|
+
slug,
|
|
4598
|
+
})) {
|
|
4599
|
+
console.log(line);
|
|
4600
|
+
}
|
|
4601
|
+
return { catalogState, commit };
|
|
4602
|
+
}
|
|
4603
|
+
/**
|
|
4604
|
+
* The named step for a catalog entry step 8 did not commit, or committed and
|
|
4605
|
+
* could not bring the worktree up to (#607). Empty for every other outcome.
|
|
4606
|
+
*
|
|
4607
|
+
* Each line is printable as it stands. Every path is single-quoted, because
|
|
4608
|
+
* the lines are commands an operator pastes into a shell.
|
|
4609
|
+
*/
|
|
4610
|
+
function catalogCommitStepLines(i) {
|
|
4611
|
+
const q = shellSingleQuote;
|
|
4612
|
+
const root = q(i.projectRoot);
|
|
4613
|
+
const wt = q(i.worktreePath);
|
|
4614
|
+
// CWE-88. Every printed merge names the full ref: a short name can resolve to a
|
|
4615
|
+
// same-named tag, and a name beginning with `-` reads as an option. `switch`
|
|
4616
|
+
// refuses a full ref ("a branch is expected"), so it takes the short name after
|
|
4617
|
+
// `--`, which git reads as a branch name only.
|
|
4618
|
+
const base = q(i.baseBranch);
|
|
4619
|
+
const baseRef = q(`refs/heads/${i.baseBranch}`);
|
|
4620
|
+
const rel = q(i.relPath);
|
|
4621
|
+
if (i.commit.kind === 'worktree-behind') {
|
|
4622
|
+
return [
|
|
4623
|
+
'',
|
|
4624
|
+
chalk.yellow.bold(` Named step: the catalog entry is committed on ${i.baseBranch}, and the team worktree does not hold it yet.`),
|
|
4625
|
+
` Cause: ${i.commit.detail}`,
|
|
4626
|
+
chalk.dim(` The entry is committed on ${i.baseBranch}${i.commit.sha ? ` (${i.commit.sha.slice(0, 7)})` : ''}. The team worktree is one or more`),
|
|
4627
|
+
chalk.dim(` commits behind ${i.baseBranch}, and no copy of the entry was written into it. A dirty tracked file,`),
|
|
4628
|
+
chalk.dim(' or an untracked file at another path that the fast-forward would overwrite, stops the'),
|
|
4629
|
+
chalk.dim(' fast-forward. Provisioning is not failed by this. Before the team\'s first session, run:'),
|
|
4630
|
+
...(i.commit.worktreeHasOwnCommits
|
|
4631
|
+
? [
|
|
4632
|
+
chalk.dim(' The worktree branch has commits of its own, so a fast-forward is refused; merge instead:'),
|
|
4633
|
+
` ${chalk.cyan(`git -C ${wt} merge ${baseRef}`)}`,
|
|
4634
|
+
]
|
|
4635
|
+
: [` ${chalk.cyan(`git -C ${wt} merge --ff-only ${baseRef}`)}`]),
|
|
4636
|
+
'',
|
|
4637
|
+
];
|
|
4638
|
+
}
|
|
4639
|
+
if (i.commit.kind !== 'not-committed')
|
|
4640
|
+
return [];
|
|
4641
|
+
const cause = i.commit.cause;
|
|
4642
|
+
const worktreeCopy = join(i.worktreePath, i.relPath);
|
|
4643
|
+
const pre = [];
|
|
4644
|
+
if (cause === 'head-not-on-base') {
|
|
4645
|
+
pre.push(` ${chalk.cyan(`git -C ${root} switch -- ${base}`)}`);
|
|
4646
|
+
}
|
|
4647
|
+
if (cause === 'no-identity') {
|
|
4648
|
+
pre.push(chalk.dim(' Set a git identity first (this command never sets one for you), for example:'));
|
|
4649
|
+
pre.push(` ${chalk.cyan(`git -C ${root} config user.name '<your name>'`)}`);
|
|
4650
|
+
pre.push(` ${chalk.cyan(`git -C ${root} config user.email '<your email>'`)}`);
|
|
4651
|
+
}
|
|
4652
|
+
const removeCopy = cause === 'differing-copy'
|
|
4653
|
+
? [chalk.dim(` The file at ${worktreeCopy} is not this run's entry. Move it out of the way first.`)]
|
|
4654
|
+
: [` ${chalk.cyan(`rm -- ${q(worktreeCopy)}`)}${chalk.dim(' (the uncommitted copy this run wrote)')}`];
|
|
4655
|
+
const merge = cause === 'worktree-has-own-commits'
|
|
4656
|
+
? ` ${chalk.cyan(`git -C ${wt} merge ${baseRef}`)}${chalk.dim(' (the worktree branch has commits of its own)')}`
|
|
4657
|
+
: ` ${chalk.cyan(`git -C ${wt} merge --ff-only ${baseRef}`)}`;
|
|
4658
|
+
return [
|
|
4659
|
+
'',
|
|
4660
|
+
chalk.yellow.bold(' Named step: the catalog entry is written and NOT committed.'),
|
|
4661
|
+
` Cause: ${i.commit.detail}`,
|
|
4662
|
+
chalk.dim(` It is untracked in ${i.projectRoot} and in the team worktree. Provisioning is not failed`),
|
|
4663
|
+
chalk.dim(' by this: the team is provisioned and only the commit is left. Before the team\'s first'),
|
|
4664
|
+
chalk.dim(' session, run:'),
|
|
4665
|
+
...pre,
|
|
4666
|
+
` ${chalk.cyan(`git -C ${root} add -- ${rel}`)}`,
|
|
4667
|
+
` ${chalk.cyan(`git -C ${root} commit -m ${q(`chore: add the ${i.slug} catalog entry`)} -- ${rel}`)}`,
|
|
4668
|
+
...removeCopy,
|
|
4669
|
+
merge,
|
|
4670
|
+
'',
|
|
4671
|
+
];
|
|
4672
|
+
}
|
|
4415
4673
|
/**
|
|
4416
4674
|
* Everything from the first durable write to the completion verdict.
|
|
4417
4675
|
*
|
|
@@ -4421,7 +4679,7 @@ function memoryOwnership(codeContext, teamSlug, projectSlug) {
|
|
|
4421
4679
|
* precondition, decided whether this is a resume, and taken the lock.
|
|
4422
4680
|
*/
|
|
4423
4681
|
async function runProvisionSteps(ctx) {
|
|
4424
|
-
const { slug, displayName, projectRoot, cfg, roleguide, contract, worktreeDirName, worktreePath, resuming, fetchOk, projectHasOrigin, nameCheckSpecs, } = ctx;
|
|
4682
|
+
const { slug, displayName, projectRoot, cfg, roleguide, contract, worktreeDirName, worktreePath, resuming, fetchOk, projectHasOrigin, remotes, nameCheckSpecs, } = ctx;
|
|
4425
4683
|
/** Which point, if any, this run is cut at. Null in every build but a test build. */
|
|
4426
4684
|
const fault = faultInjectionStep();
|
|
4427
4685
|
// WHAT THE COMPLETION CHECK READS, declared here rather than where each step
|
|
@@ -4450,6 +4708,8 @@ async function runProvisionSteps(ctx) {
|
|
|
4450
4708
|
let extraCreations;
|
|
4451
4709
|
let memoryStates;
|
|
4452
4710
|
let catalogState;
|
|
4711
|
+
/** What step 8 did with the catalog entry on a project with zero remotes (#607). */
|
|
4712
|
+
let catalogCommit = { kind: 'not-attempted' };
|
|
4453
4713
|
let build;
|
|
4454
4714
|
let credential;
|
|
4455
4715
|
let coordinationUrlAtProvision = null;
|
|
@@ -4491,6 +4751,8 @@ async function runProvisionSteps(ctx) {
|
|
|
4491
4751
|
projectRoot,
|
|
4492
4752
|
fetchOk,
|
|
4493
4753
|
hasOrigin: projectHasOrigin,
|
|
4754
|
+
// Zero remotes moves rows 9 and 10 to the local base branch (#607).
|
|
4755
|
+
remotes,
|
|
4494
4756
|
catalogOnOriginMainPath: `${cfg.teamsDir}/${slug}.md`,
|
|
4495
4757
|
// Row 7 reads `origin/<base>` for the roleguide, on the fetch step 0c
|
|
4496
4758
|
// already ran, exactly as rows 2 and 9 do for their own artifacts. No new
|
|
@@ -5148,73 +5410,23 @@ async function runProvisionSteps(ctx) {
|
|
|
5148
5410
|
interaction: 'non-interactive',
|
|
5149
5411
|
});
|
|
5150
5412
|
//
|
|
5151
|
-
// Written here only when the project has no `origin` (#51)
|
|
5152
|
-
//
|
|
5153
|
-
//
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
}
|
|
5169
|
-
else if (projectHasOrigin) {
|
|
5170
|
-
logSuccess(`${cfg.teamsDir}/${slug}.md (on origin/${cfg.baseBranch}, written by team-builder step 5)`);
|
|
5171
|
-
}
|
|
5172
|
-
else if (resuming && existsSync(getTeamCatalogPath(projectRoot, slug, cfg.teamsDir))) {
|
|
5173
|
-
catalogState = catalogEntryState({
|
|
5174
|
-
path: getTeamCatalogPath(projectRoot, slug, cfg.teamsDir),
|
|
5175
|
-
expected: serializeTeamEntry(catalogEntryForThisRun()),
|
|
5176
|
-
});
|
|
5177
|
-
// TERMINAL FOR ROW 2 (#316 change B, red-team finding 8). `writeTeamCatalog`
|
|
5178
|
-
// is an unconditional write, so a resume that called it would replace an
|
|
5179
|
-
// entry the operator edited between the two runs with the placeholder
|
|
5180
|
-
// version. An entry that is there is the row's claim met, whoever wrote it,
|
|
5181
|
-
// and row 2 now says whether its content is this run's.
|
|
5182
|
-
logSuccess(catalogState?.kind === 'present-stale'
|
|
5183
|
-
? `${cfg.teamsDir}/${slug}.md (already written and edited since; a resume leaves it byte for byte)`
|
|
5184
|
-
: `${cfg.teamsDir}/${slug}.md (already written; a resume leaves it byte for byte)`);
|
|
5185
|
-
}
|
|
5186
|
-
else {
|
|
5187
|
-
writeTeamCatalog(projectRoot, catalogEntryForThisRun(), cfg.teamsDir);
|
|
5188
|
-
logSuccess(`mx-agent-system/teams/${slug}.md`);
|
|
5189
|
-
}
|
|
5190
|
-
// Also copy the catalog entry to the new worktree so it's visible there.
|
|
5191
|
-
//
|
|
5192
|
-
// FILESYSTEM SINK — same shape as 6b, same containment. Lower risk (the path
|
|
5193
|
-
// is built from in-repo reviewed config plus a slug already validated against
|
|
5194
|
-
// SLUG_RE), but identical in form, and a second uncontained copy is not left
|
|
5195
|
-
// behind just because its inputs look trustworthy today.
|
|
5196
|
-
// source root : projectRoot
|
|
5197
|
-
// source path : catalogInSource (projectRoot + configured teamsDir + validated slug)
|
|
5198
|
-
// destination : reanchorContained(...)
|
|
5199
|
-
// mode : 0644, fixed
|
|
5200
|
-
const catalogInSource = join(projectRoot, cfg.teamsDir, `${slug}.md`);
|
|
5201
|
-
if (existsSync(catalogInSource)) {
|
|
5202
|
-
const anchoredCatalog = reanchorContained(projectRoot, catalogInSource, worktreePath);
|
|
5203
|
-
if (!anchoredCatalog.ok) {
|
|
5204
|
-
logWarning(`Could not copy the catalog entry into the new worktree: ${anchoredCatalog.detail}`);
|
|
5205
|
-
}
|
|
5206
|
-
else if (!existsSync(anchoredCatalog.dest)) {
|
|
5207
|
-
const bytes = readFileSync(catalogInSource, 'utf-8');
|
|
5208
|
-
const written = writeContained(anchoredCatalog.dest, realpathSync(worktreePath), bytes);
|
|
5209
|
-
if (!written.ok) {
|
|
5210
|
-
logWarning(`Could not copy the catalog entry into the new worktree: ${written.detail}`);
|
|
5211
|
-
}
|
|
5212
|
-
}
|
|
5213
|
-
}
|
|
5214
|
-
}
|
|
5215
|
-
catch (err) {
|
|
5216
|
-
logWarning(`Could not write catalog entry: ${err instanceof Error ? err.message : String(err)}`);
|
|
5217
|
-
}
|
|
5413
|
+
// Written here only when the project has no `origin` (#51), and on a project
|
|
5414
|
+
// with zero remotes also committed there (#607). `catalogEntryStep` states
|
|
5415
|
+
// both paths and the fallback.
|
|
5416
|
+
const catalogStep = catalogEntryStep({
|
|
5417
|
+
projectRoot,
|
|
5418
|
+
worktreePath,
|
|
5419
|
+
slug,
|
|
5420
|
+
teamsDir: cfg.teamsDir,
|
|
5421
|
+
baseBranch: cfg.baseBranch,
|
|
5422
|
+
refusedBy: willRefuseAtRow13 ? 'row13' : anchorsRefused ? 'anchors' : null,
|
|
5423
|
+
projectHasOrigin,
|
|
5424
|
+
remotes,
|
|
5425
|
+
resuming,
|
|
5426
|
+
entry: catalogEntryForThisRun,
|
|
5427
|
+
});
|
|
5428
|
+
catalogState = catalogStep.catalogState ?? catalogState;
|
|
5429
|
+
catalogCommit = catalogStep.commit;
|
|
5218
5430
|
injectFault(fault, 'catalog');
|
|
5219
5431
|
// ── 8b. Completion check (#48) ─────────────────────────────────────
|
|
5220
5432
|
// After the last write, before any success message: read back what this
|
|
@@ -5226,16 +5438,19 @@ async function runProvisionSteps(ctx) {
|
|
|
5226
5438
|
// request and that function is synchronous, which is the same reason `build`,
|
|
5227
5439
|
// `creations` and `anchors` are pre-resolved and passed in.
|
|
5228
5440
|
//
|
|
5229
|
-
// GATED BEHIND ROW 9, exactly as the vault read is: `
|
|
5441
|
+
// GATED BEHIND ROW 9, exactly as the vault read is: `rosterReadForRows` is the
|
|
5230
5442
|
// same call with the same arguments row 9 makes, so the two cannot disagree,
|
|
5231
5443
|
// and a team that is not on the roster costs no request. `undefined` reaches
|
|
5232
5444
|
// the row as could-not-run.
|
|
5233
5445
|
if (usesCredentialEndpoint(cfg.projectSlug)) {
|
|
5234
|
-
const eligible =
|
|
5235
|
-
|
|
5446
|
+
const eligible = rosterReadForRows({
|
|
5447
|
+
projectRoot,
|
|
5448
|
+
slug,
|
|
5449
|
+
projectSlug: cfg.projectSlug,
|
|
5236
5450
|
baseBranch: cfg.baseBranch,
|
|
5237
5451
|
fetchOk,
|
|
5238
|
-
|
|
5452
|
+
remotes,
|
|
5453
|
+
}).entry;
|
|
5239
5454
|
// `project-absent` is a project the service creates on login (#507): this
|
|
5240
5455
|
// request is what registers the team, so it is not gated on a compiled
|
|
5241
5456
|
// roster the project will never appear in. The row reads the same answer.
|
|
@@ -5418,7 +5633,21 @@ async function runProvisionSteps(ctx) {
|
|
|
5418
5633
|
else {
|
|
5419
5634
|
console.log(chalk.yellow(` [⚠] Named memories: ${memoriesLabel} (create manually — see above)`));
|
|
5420
5635
|
}
|
|
5421
|
-
|
|
5636
|
+
// The commit state on a project with zero remotes (#607). A fallback is not a
|
|
5637
|
+
// failed row, so it reaches this checklist; the line says so and points at the
|
|
5638
|
+
// named step printed under "Catalog entry" above.
|
|
5639
|
+
if (catalogCommit.kind === 'not-committed') {
|
|
5640
|
+
console.log(chalk.yellow(` [⚠] Catalog entry: mx-agent-system/teams/${slug}.md (written, NOT committed; see the named step above)`));
|
|
5641
|
+
}
|
|
5642
|
+
else if (catalogCommit.kind === 'worktree-behind') {
|
|
5643
|
+
console.log(chalk.yellow(` [⚠] Catalog entry: mx-agent-system/teams/${slug}.md (committed on ${cfg.baseBranch}; the team worktree is not up to date, see the named step above)`));
|
|
5644
|
+
}
|
|
5645
|
+
else if (catalogCommit.kind === 'committed' || catalogCommit.kind === 'already-tracked') {
|
|
5646
|
+
console.log(chalk.green(` [✓] Catalog entry: mx-agent-system/teams/${slug}.md (committed on ${cfg.baseBranch})`));
|
|
5647
|
+
}
|
|
5648
|
+
else {
|
|
5649
|
+
console.log(chalk.green(` [✓] Catalog entry: mx-agent-system/teams/${slug}.md`));
|
|
5650
|
+
}
|
|
5422
5651
|
// Rows 9 and 10 by name, with the state each read (#77). A checklist that
|
|
5423
5652
|
// lists what this command wrote and stays silent about the registration is
|
|
5424
5653
|
// how a team reached its first session with no cross-team channel.
|
|
@@ -5482,6 +5711,9 @@ export const __testing = { catalogRemedyLines, reanchorContained, writeContained
|
|
|
5482
5711
|
// provisioning run's output.
|
|
5483
5712
|
checkResumeIdentity, readWorktreeIdentity, memoryPresenceState, claimProvisionLock, provisionLockPath,
|
|
5484
5713
|
faultInjectionStep, isLoopbackServiceUrl,
|
|
5714
|
+
// #607. Step 8 and the shared roster read, so the commit is asserted against
|
|
5715
|
+
// real git and rows 9 and 10 against a real local ref.
|
|
5716
|
+
catalogEntryStep, catalogCommitStepLines, rosterReadForRows,
|
|
5485
5717
|
// #440 part A. Row 15 is exported so one test can assert that it and the
|
|
5486
5718
|
// `## Git Identity` block in CLAUDE.local.md agree on the same worktree, which
|
|
5487
5719
|
// is the property the creation test found broken.
|