@memnexus-ai/mx-agent-cli 0.1.296-next.4 → 0.1.296-next.6
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__/new-project-first-team.test.js +149 -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 +10 -1
- 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 +213 -3
- package/dist/__tests__/template-sync.test.js.map +1 -1
- package/dist/commands/create.d.ts +116 -0
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +304 -79
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/new.d.ts +27 -0
- package/dist/commands/new.d.ts.map +1 -1
- package/dist/commands/new.js +92 -4
- 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/dist/lib/templates.d.ts.map +1 -1
- package/dist/lib/templates.js +32 -0
- package/dist/lib/templates.js.map +1 -1
- package/dist/standards/decision-request.md +8 -0
- package/dist/standards/rulings.md +104 -0
- 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;
|
|
@@ -4154,6 +4194,7 @@ export async function runCreate(options) {
|
|
|
4154
4194
|
resuming,
|
|
4155
4195
|
fetchOk,
|
|
4156
4196
|
projectHasOrigin,
|
|
4197
|
+
remotes,
|
|
4157
4198
|
nameCheckSpecs,
|
|
4158
4199
|
});
|
|
4159
4200
|
}
|
|
@@ -4337,6 +4378,9 @@ async function runRecheck(i) {
|
|
|
4337
4378
|
projectRoot,
|
|
4338
4379
|
fetchOk,
|
|
4339
4380
|
hasOrigin: projectHasOrigin,
|
|
4381
|
+
// The same list the provisioning run reads, so a re-check of a project
|
|
4382
|
+
// with zero remotes reads rows 9 and 10 off the same local ref (#607).
|
|
4383
|
+
remotes,
|
|
4340
4384
|
catalogOnOriginMainPath: `${cfg.teamsDir}/${slug}.md`,
|
|
4341
4385
|
// Row 7 asks whether that same file is on the base branch. NOTHING IS COPIED
|
|
4342
4386
|
// on a re-check, so this is a reconstruction, not the destination a copy
|
|
@@ -4412,6 +4456,213 @@ function memoryOwnership(codeContext, teamSlug, projectSlug) {
|
|
|
4412
4456
|
? 'this-team'
|
|
4413
4457
|
: 'not-this-team';
|
|
4414
4458
|
}
|
|
4459
|
+
/**
|
|
4460
|
+
* Step 8 of provisioning: the catalog entry (#51, #607).
|
|
4461
|
+
*
|
|
4462
|
+
* WITH AN `origin`, unchanged: the entry is on the base branch already, asserted
|
|
4463
|
+
* at step 0c, and the new worktree holds it from its own checkout. Writing a
|
|
4464
|
+
* second copy relative to `projectRoot` is what produced the untracked file in
|
|
4465
|
+
* the main checkout, and `writeTeamCatalog` is an unconditional write, so that
|
|
4466
|
+
* copy would also replace a hand-curated entry with the placeholder version.
|
|
4467
|
+
*
|
|
4468
|
+
* WITH ZERO REMOTES (#607), the entry is written in the project root and then
|
|
4469
|
+
* COMMITTED there, on the base branch, and the team worktree is fast-forwarded
|
|
4470
|
+
* to that commit (`lib/catalog-commit.ts` states the order and why). No
|
|
4471
|
+
* untracked copy is written into the worktree. Before this, both trees held the
|
|
4472
|
+
* entry untracked, one `git add -A` away, and every later read of the base
|
|
4473
|
+
* branch missed it.
|
|
4474
|
+
*
|
|
4475
|
+
* WHEN THE COMMIT CANNOT BE MADE, the run falls back to what it did before:
|
|
4476
|
+
* the entry stays written and uncommitted, it is copied into the worktree, and a
|
|
4477
|
+
* named step states the cause and the exact commands that finish the job.
|
|
4478
|
+
* Provisioning does not fail on it: the team is provisioned, and only the commit
|
|
4479
|
+
* is left. A refused run writes and commits nothing, unchanged from v6.
|
|
4480
|
+
*
|
|
4481
|
+
* Exported through `__testing` so the commit half is asserted against real git
|
|
4482
|
+
* in a temporary repository rather than inferred from a mock.
|
|
4483
|
+
*/
|
|
4484
|
+
function catalogEntryStep(i) {
|
|
4485
|
+
const { projectRoot, worktreePath, slug, teamsDir } = i;
|
|
4486
|
+
let catalogState;
|
|
4487
|
+
let commit = { kind: 'not-attempted' };
|
|
4488
|
+
const relPath = `${teamsDir.split(sep).join('/').replace(/\/+$/, '')}/${slug}.md`;
|
|
4489
|
+
console.log();
|
|
4490
|
+
console.log(chalk.bold(' Catalog entry:'));
|
|
4491
|
+
try {
|
|
4492
|
+
if (i.refusedBy !== null && !i.projectHasOrigin) {
|
|
4493
|
+
// `writeTeamCatalog` is an unconditional write. On a refused run it would
|
|
4494
|
+
// put a placeholder entry into the project, and a second run would write
|
|
4495
|
+
// over whatever the operator edited in between. The v6 ruling holds: never
|
|
4496
|
+
// write into a file the operator may have edited.
|
|
4497
|
+
logWarning(i.refusedBy === 'row13'
|
|
4498
|
+
? 'skipped: the roleguide still has placeholders (row 13). Not written on a refused run.'
|
|
4499
|
+
: 'skipped: the roleguide\'s Named Memory Anchors table was refused (row 3a). Not written on a refused run.');
|
|
4500
|
+
}
|
|
4501
|
+
else if (i.projectHasOrigin) {
|
|
4502
|
+
logSuccess(`${teamsDir}/${slug}.md (on origin/${i.baseBranch}, written by team-builder step 5)`);
|
|
4503
|
+
}
|
|
4504
|
+
else if (i.resuming && existsSync(getTeamCatalogPath(projectRoot, slug, teamsDir))) {
|
|
4505
|
+
catalogState = catalogEntryState({
|
|
4506
|
+
path: getTeamCatalogPath(projectRoot, slug, teamsDir),
|
|
4507
|
+
expected: serializeTeamEntry(i.entry()),
|
|
4508
|
+
});
|
|
4509
|
+
// TERMINAL FOR ROW 2 (#316 change B, red-team finding 8). `writeTeamCatalog`
|
|
4510
|
+
// is an unconditional write, so a resume that called it would replace an
|
|
4511
|
+
// entry the operator edited between the two runs with the placeholder
|
|
4512
|
+
// version. An entry that is there is the row's claim met, whoever wrote it,
|
|
4513
|
+
// and row 2 now says whether its content is this run's. The commit below
|
|
4514
|
+
// takes the file AS IT IS, for the same reason: it writes nothing (#607).
|
|
4515
|
+
logSuccess(catalogState?.kind === 'present-stale'
|
|
4516
|
+
? `${teamsDir}/${slug}.md (already written and edited since; a resume leaves it byte for byte)`
|
|
4517
|
+
: `${teamsDir}/${slug}.md (already written; a resume leaves it byte for byte)`);
|
|
4518
|
+
}
|
|
4519
|
+
else {
|
|
4520
|
+
writeTeamCatalog(projectRoot, i.entry(), teamsDir);
|
|
4521
|
+
logSuccess(`mx-agent-system/teams/${slug}.md`);
|
|
4522
|
+
}
|
|
4523
|
+
// ── The commit, on a project with zero remotes only (#607) ──
|
|
4524
|
+
//
|
|
4525
|
+
// `remotes` is the list step 0c read, never null here. Remotes without an
|
|
4526
|
+
// `origin` were refused at step 0c, so an empty list is the only
|
|
4527
|
+
// origin-less state that reaches this line.
|
|
4528
|
+
const zeroRemotes = !i.projectHasOrigin && i.remotes.length === 0;
|
|
4529
|
+
if (zeroRemotes && i.refusedBy === null && existsSync(join(projectRoot, relPath))) {
|
|
4530
|
+
commit = commitCatalogEntry({
|
|
4531
|
+
projectRoot,
|
|
4532
|
+
worktreePath,
|
|
4533
|
+
baseBranch: i.baseBranch,
|
|
4534
|
+
relPath,
|
|
4535
|
+
message: `chore: add the ${slug} catalog entry`,
|
|
4536
|
+
env: i.env,
|
|
4537
|
+
});
|
|
4538
|
+
if (commit.kind === 'committed') {
|
|
4539
|
+
logSuccess(`${relPath} committed on ${i.baseBranch} (${commit.sha.slice(0, 7)}); the team worktree holds the same commit`);
|
|
4540
|
+
}
|
|
4541
|
+
else if (commit.kind === 'already-tracked') {
|
|
4542
|
+
logSuccess(commit.worktreeUpdated
|
|
4543
|
+
? `${relPath} was already committed on ${i.baseBranch}; the team worktree was fast-forwarded to it`
|
|
4544
|
+
: `${relPath} is already committed on ${i.baseBranch}, and the team worktree holds it; nothing committed`);
|
|
4545
|
+
}
|
|
4546
|
+
}
|
|
4547
|
+
// Also copy the catalog entry to the new worktree so it's visible there.
|
|
4548
|
+
//
|
|
4549
|
+
// NOT on the zero-remote path once the entry is on the base branch: the
|
|
4550
|
+
// worktree then holds it as a tracked file, or is one merge away from it,
|
|
4551
|
+
// and an untracked copy is exactly the stray path #607 removes. The copy
|
|
4552
|
+
// runs on every other path, which is the fallback included.
|
|
4553
|
+
//
|
|
4554
|
+
// FILESYSTEM SINK — same shape as 6b, same containment. Lower risk (the path
|
|
4555
|
+
// is built from in-repo reviewed config plus a slug already validated against
|
|
4556
|
+
// SLUG_RE), but identical in form, and a second uncontained copy is not left
|
|
4557
|
+
// behind just because its inputs look trustworthy today.
|
|
4558
|
+
// source root : projectRoot
|
|
4559
|
+
// source path : catalogInSource (projectRoot + configured teamsDir + validated slug)
|
|
4560
|
+
// destination : reanchorContained(...)
|
|
4561
|
+
// mode : 0644, fixed
|
|
4562
|
+
const skipCopy = commit.kind === 'committed' || commit.kind === 'already-tracked' || commit.kind === 'worktree-behind';
|
|
4563
|
+
const catalogInSource = join(projectRoot, teamsDir, `${slug}.md`);
|
|
4564
|
+
if (!skipCopy && existsSync(catalogInSource)) {
|
|
4565
|
+
const anchoredCatalog = reanchorContained(projectRoot, catalogInSource, worktreePath);
|
|
4566
|
+
if (!anchoredCatalog.ok) {
|
|
4567
|
+
logWarning(`Could not copy the catalog entry into the new worktree: ${anchoredCatalog.detail}`);
|
|
4568
|
+
}
|
|
4569
|
+
else if (!existsSync(anchoredCatalog.dest)) {
|
|
4570
|
+
const bytes = readFileSync(catalogInSource, 'utf-8');
|
|
4571
|
+
const written = writeContained(anchoredCatalog.dest, realpathSync(worktreePath), bytes);
|
|
4572
|
+
if (!written.ok) {
|
|
4573
|
+
logWarning(`Could not copy the catalog entry into the new worktree: ${written.detail}`);
|
|
4574
|
+
}
|
|
4575
|
+
}
|
|
4576
|
+
}
|
|
4577
|
+
}
|
|
4578
|
+
catch (err) {
|
|
4579
|
+
logWarning(`Could not write catalog entry: ${err instanceof Error ? err.message : String(err)}`);
|
|
4580
|
+
}
|
|
4581
|
+
// NAMED, never a bare warning (#607). Printed outside the try above, so the
|
|
4582
|
+
// catch cannot swallow it, and after the copy, so the commands it names match
|
|
4583
|
+
// the state the run leaves.
|
|
4584
|
+
for (const line of catalogCommitStepLines({
|
|
4585
|
+
commit,
|
|
4586
|
+
projectRoot,
|
|
4587
|
+
worktreePath,
|
|
4588
|
+
relPath,
|
|
4589
|
+
baseBranch: i.baseBranch,
|
|
4590
|
+
slug,
|
|
4591
|
+
})) {
|
|
4592
|
+
console.log(line);
|
|
4593
|
+
}
|
|
4594
|
+
return { catalogState, commit };
|
|
4595
|
+
}
|
|
4596
|
+
/**
|
|
4597
|
+
* The named step for a catalog entry step 8 did not commit, or committed and
|
|
4598
|
+
* could not bring the worktree up to (#607). Empty for every other outcome.
|
|
4599
|
+
*
|
|
4600
|
+
* Each line is printable as it stands. Every path is single-quoted, because
|
|
4601
|
+
* the lines are commands an operator pastes into a shell.
|
|
4602
|
+
*/
|
|
4603
|
+
function catalogCommitStepLines(i) {
|
|
4604
|
+
const q = shellSingleQuote;
|
|
4605
|
+
const root = q(i.projectRoot);
|
|
4606
|
+
const wt = q(i.worktreePath);
|
|
4607
|
+
// CWE-88. Every printed merge names the full ref: a short name can resolve to a
|
|
4608
|
+
// same-named tag, and a name beginning with `-` reads as an option. `switch`
|
|
4609
|
+
// refuses a full ref ("a branch is expected"), so it takes the short name after
|
|
4610
|
+
// `--`, which git reads as a branch name only.
|
|
4611
|
+
const base = q(i.baseBranch);
|
|
4612
|
+
const baseRef = q(`refs/heads/${i.baseBranch}`);
|
|
4613
|
+
const rel = q(i.relPath);
|
|
4614
|
+
if (i.commit.kind === 'worktree-behind') {
|
|
4615
|
+
return [
|
|
4616
|
+
'',
|
|
4617
|
+
chalk.yellow.bold(` Named step: the catalog entry is committed on ${i.baseBranch}, and the team worktree does not hold it yet.`),
|
|
4618
|
+
` Cause: ${i.commit.detail}`,
|
|
4619
|
+
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`),
|
|
4620
|
+
chalk.dim(` commits behind ${i.baseBranch}, and no copy of the entry was written into it. A dirty tracked file,`),
|
|
4621
|
+
chalk.dim(' or an untracked file at another path that the fast-forward would overwrite, stops the'),
|
|
4622
|
+
chalk.dim(' fast-forward. Provisioning is not failed by this. Before the team\'s first session, run:'),
|
|
4623
|
+
...(i.commit.worktreeHasOwnCommits
|
|
4624
|
+
? [
|
|
4625
|
+
chalk.dim(' The worktree branch has commits of its own, so a fast-forward is refused; merge instead:'),
|
|
4626
|
+
` ${chalk.cyan(`git -C ${wt} merge ${baseRef}`)}`,
|
|
4627
|
+
]
|
|
4628
|
+
: [` ${chalk.cyan(`git -C ${wt} merge --ff-only ${baseRef}`)}`]),
|
|
4629
|
+
'',
|
|
4630
|
+
];
|
|
4631
|
+
}
|
|
4632
|
+
if (i.commit.kind !== 'not-committed')
|
|
4633
|
+
return [];
|
|
4634
|
+
const cause = i.commit.cause;
|
|
4635
|
+
const worktreeCopy = join(i.worktreePath, i.relPath);
|
|
4636
|
+
const pre = [];
|
|
4637
|
+
if (cause === 'head-not-on-base') {
|
|
4638
|
+
pre.push(` ${chalk.cyan(`git -C ${root} switch -- ${base}`)}`);
|
|
4639
|
+
}
|
|
4640
|
+
if (cause === 'no-identity') {
|
|
4641
|
+
pre.push(chalk.dim(' Set a git identity first (this command never sets one for you), for example:'));
|
|
4642
|
+
pre.push(` ${chalk.cyan(`git -C ${root} config user.name '<your name>'`)}`);
|
|
4643
|
+
pre.push(` ${chalk.cyan(`git -C ${root} config user.email '<your email>'`)}`);
|
|
4644
|
+
}
|
|
4645
|
+
const removeCopy = cause === 'differing-copy'
|
|
4646
|
+
? [chalk.dim(` The file at ${worktreeCopy} is not this run's entry. Move it out of the way first.`)]
|
|
4647
|
+
: [` ${chalk.cyan(`rm -- ${q(worktreeCopy)}`)}${chalk.dim(' (the uncommitted copy this run wrote)')}`];
|
|
4648
|
+
const merge = cause === 'worktree-has-own-commits'
|
|
4649
|
+
? ` ${chalk.cyan(`git -C ${wt} merge ${baseRef}`)}${chalk.dim(' (the worktree branch has commits of its own)')}`
|
|
4650
|
+
: ` ${chalk.cyan(`git -C ${wt} merge --ff-only ${baseRef}`)}`;
|
|
4651
|
+
return [
|
|
4652
|
+
'',
|
|
4653
|
+
chalk.yellow.bold(' Named step: the catalog entry is written and NOT committed.'),
|
|
4654
|
+
` Cause: ${i.commit.detail}`,
|
|
4655
|
+
chalk.dim(` It is untracked in ${i.projectRoot} and in the team worktree. Provisioning is not failed`),
|
|
4656
|
+
chalk.dim(' by this: the team is provisioned and only the commit is left. Before the team\'s first'),
|
|
4657
|
+
chalk.dim(' session, run:'),
|
|
4658
|
+
...pre,
|
|
4659
|
+
` ${chalk.cyan(`git -C ${root} add -- ${rel}`)}`,
|
|
4660
|
+
` ${chalk.cyan(`git -C ${root} commit -m ${q(`chore: add the ${i.slug} catalog entry`)} -- ${rel}`)}`,
|
|
4661
|
+
...removeCopy,
|
|
4662
|
+
merge,
|
|
4663
|
+
'',
|
|
4664
|
+
];
|
|
4665
|
+
}
|
|
4415
4666
|
/**
|
|
4416
4667
|
* Everything from the first durable write to the completion verdict.
|
|
4417
4668
|
*
|
|
@@ -4421,7 +4672,7 @@ function memoryOwnership(codeContext, teamSlug, projectSlug) {
|
|
|
4421
4672
|
* precondition, decided whether this is a resume, and taken the lock.
|
|
4422
4673
|
*/
|
|
4423
4674
|
async function runProvisionSteps(ctx) {
|
|
4424
|
-
const { slug, displayName, projectRoot, cfg, roleguide, contract, worktreeDirName, worktreePath, resuming, fetchOk, projectHasOrigin, nameCheckSpecs, } = ctx;
|
|
4675
|
+
const { slug, displayName, projectRoot, cfg, roleguide, contract, worktreeDirName, worktreePath, resuming, fetchOk, projectHasOrigin, remotes, nameCheckSpecs, } = ctx;
|
|
4425
4676
|
/** Which point, if any, this run is cut at. Null in every build but a test build. */
|
|
4426
4677
|
const fault = faultInjectionStep();
|
|
4427
4678
|
// WHAT THE COMPLETION CHECK READS, declared here rather than where each step
|
|
@@ -4450,6 +4701,8 @@ async function runProvisionSteps(ctx) {
|
|
|
4450
4701
|
let extraCreations;
|
|
4451
4702
|
let memoryStates;
|
|
4452
4703
|
let catalogState;
|
|
4704
|
+
/** What step 8 did with the catalog entry on a project with zero remotes (#607). */
|
|
4705
|
+
let catalogCommit = { kind: 'not-attempted' };
|
|
4453
4706
|
let build;
|
|
4454
4707
|
let credential;
|
|
4455
4708
|
let coordinationUrlAtProvision = null;
|
|
@@ -4491,6 +4744,8 @@ async function runProvisionSteps(ctx) {
|
|
|
4491
4744
|
projectRoot,
|
|
4492
4745
|
fetchOk,
|
|
4493
4746
|
hasOrigin: projectHasOrigin,
|
|
4747
|
+
// Zero remotes moves rows 9 and 10 to the local base branch (#607).
|
|
4748
|
+
remotes,
|
|
4494
4749
|
catalogOnOriginMainPath: `${cfg.teamsDir}/${slug}.md`,
|
|
4495
4750
|
// Row 7 reads `origin/<base>` for the roleguide, on the fetch step 0c
|
|
4496
4751
|
// already ran, exactly as rows 2 and 9 do for their own artifacts. No new
|
|
@@ -5148,73 +5403,23 @@ async function runProvisionSteps(ctx) {
|
|
|
5148
5403
|
interaction: 'non-interactive',
|
|
5149
5404
|
});
|
|
5150
5405
|
//
|
|
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
|
-
}
|
|
5406
|
+
// Written here only when the project has no `origin` (#51), and on a project
|
|
5407
|
+
// with zero remotes also committed there (#607). `catalogEntryStep` states
|
|
5408
|
+
// both paths and the fallback.
|
|
5409
|
+
const catalogStep = catalogEntryStep({
|
|
5410
|
+
projectRoot,
|
|
5411
|
+
worktreePath,
|
|
5412
|
+
slug,
|
|
5413
|
+
teamsDir: cfg.teamsDir,
|
|
5414
|
+
baseBranch: cfg.baseBranch,
|
|
5415
|
+
refusedBy: willRefuseAtRow13 ? 'row13' : anchorsRefused ? 'anchors' : null,
|
|
5416
|
+
projectHasOrigin,
|
|
5417
|
+
remotes,
|
|
5418
|
+
resuming,
|
|
5419
|
+
entry: catalogEntryForThisRun,
|
|
5420
|
+
});
|
|
5421
|
+
catalogState = catalogStep.catalogState ?? catalogState;
|
|
5422
|
+
catalogCommit = catalogStep.commit;
|
|
5218
5423
|
injectFault(fault, 'catalog');
|
|
5219
5424
|
// ── 8b. Completion check (#48) ─────────────────────────────────────
|
|
5220
5425
|
// After the last write, before any success message: read back what this
|
|
@@ -5226,16 +5431,19 @@ async function runProvisionSteps(ctx) {
|
|
|
5226
5431
|
// request and that function is synchronous, which is the same reason `build`,
|
|
5227
5432
|
// `creations` and `anchors` are pre-resolved and passed in.
|
|
5228
5433
|
//
|
|
5229
|
-
// GATED BEHIND ROW 9, exactly as the vault read is: `
|
|
5434
|
+
// GATED BEHIND ROW 9, exactly as the vault read is: `rosterReadForRows` is the
|
|
5230
5435
|
// same call with the same arguments row 9 makes, so the two cannot disagree,
|
|
5231
5436
|
// and a team that is not on the roster costs no request. `undefined` reaches
|
|
5232
5437
|
// the row as could-not-run.
|
|
5233
5438
|
if (usesCredentialEndpoint(cfg.projectSlug)) {
|
|
5234
|
-
const eligible =
|
|
5235
|
-
|
|
5439
|
+
const eligible = rosterReadForRows({
|
|
5440
|
+
projectRoot,
|
|
5441
|
+
slug,
|
|
5442
|
+
projectSlug: cfg.projectSlug,
|
|
5236
5443
|
baseBranch: cfg.baseBranch,
|
|
5237
5444
|
fetchOk,
|
|
5238
|
-
|
|
5445
|
+
remotes,
|
|
5446
|
+
}).entry;
|
|
5239
5447
|
// `project-absent` is a project the service creates on login (#507): this
|
|
5240
5448
|
// request is what registers the team, so it is not gated on a compiled
|
|
5241
5449
|
// roster the project will never appear in. The row reads the same answer.
|
|
@@ -5418,7 +5626,21 @@ async function runProvisionSteps(ctx) {
|
|
|
5418
5626
|
else {
|
|
5419
5627
|
console.log(chalk.yellow(` [⚠] Named memories: ${memoriesLabel} (create manually — see above)`));
|
|
5420
5628
|
}
|
|
5421
|
-
|
|
5629
|
+
// The commit state on a project with zero remotes (#607). A fallback is not a
|
|
5630
|
+
// failed row, so it reaches this checklist; the line says so and points at the
|
|
5631
|
+
// named step printed under "Catalog entry" above.
|
|
5632
|
+
if (catalogCommit.kind === 'not-committed') {
|
|
5633
|
+
console.log(chalk.yellow(` [⚠] Catalog entry: mx-agent-system/teams/${slug}.md (written, NOT committed; see the named step above)`));
|
|
5634
|
+
}
|
|
5635
|
+
else if (catalogCommit.kind === 'worktree-behind') {
|
|
5636
|
+
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)`));
|
|
5637
|
+
}
|
|
5638
|
+
else if (catalogCommit.kind === 'committed' || catalogCommit.kind === 'already-tracked') {
|
|
5639
|
+
console.log(chalk.green(` [✓] Catalog entry: mx-agent-system/teams/${slug}.md (committed on ${cfg.baseBranch})`));
|
|
5640
|
+
}
|
|
5641
|
+
else {
|
|
5642
|
+
console.log(chalk.green(` [✓] Catalog entry: mx-agent-system/teams/${slug}.md`));
|
|
5643
|
+
}
|
|
5422
5644
|
// Rows 9 and 10 by name, with the state each read (#77). A checklist that
|
|
5423
5645
|
// lists what this command wrote and stays silent about the registration is
|
|
5424
5646
|
// how a team reached its first session with no cross-team channel.
|
|
@@ -5482,6 +5704,9 @@ export const __testing = { catalogRemedyLines, reanchorContained, writeContained
|
|
|
5482
5704
|
// provisioning run's output.
|
|
5483
5705
|
checkResumeIdentity, readWorktreeIdentity, memoryPresenceState, claimProvisionLock, provisionLockPath,
|
|
5484
5706
|
faultInjectionStep, isLoopbackServiceUrl,
|
|
5707
|
+
// #607. Step 8 and the shared roster read, so the commit is asserted against
|
|
5708
|
+
// real git and rows 9 and 10 against a real local ref.
|
|
5709
|
+
catalogEntryStep, catalogCommitStepLines, rosterReadForRows,
|
|
5485
5710
|
// #440 part A. Row 15 is exported so one test can assert that it and the
|
|
5486
5711
|
// `## Git Identity` block in CLAUDE.local.md agree on the same worktree, which
|
|
5487
5712
|
// is the property the creation test found broken.
|