@mstar-harness/cli 3.11.0 → 3.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16518,8 +16518,8 @@ function reportedBranchesOf(row) {
16518
16518
  function snapshotPathOf(harnessRoot, workflowId) {
16519
16519
  return join202(resolveWorkflowDir2(harnessRoot, { harnessDir: harnessRoot }), workflowId, SNAPSHOT_FILE22);
16520
16520
  }
16521
- function sessionFilePath(harnessRoot, workflowId, sessionId) {
16522
- return join202(resolveWorkflowDir2(harnessRoot, { harnessDir: harnessRoot }), workflowId, SESSION_DIR, `${sessionId}.json`);
16521
+ function sessionFilePath(harnessRoot, workflowId, role, sessionId) {
16522
+ return join202(resolveWorkflowDir2(harnessRoot, { harnessDir: harnessRoot }), workflowId, SESSION_DIR, `${role}-${sessionId}.json`);
16523
16523
  }
16524
16524
  function localStore2(harnessRoot) {
16525
16525
  let store;
@@ -16680,6 +16680,22 @@ function safePlanId(planId, where) {
16680
16680
  }
16681
16681
  return planId;
16682
16682
  }
16683
+ var SESSION_ID_MAX_LENGTH = 128;
16684
+ function safeSessionId(value) {
16685
+ if (value === undefined)
16686
+ return;
16687
+ if (typeof value !== "string")
16688
+ throw invalidInput2("sessionId must be a string");
16689
+ if (value.length > SESSION_ID_MAX_LENGTH) {
16690
+ throw new CoordinationError2("coordination.invalid-session-id", `session id is longer than ${SESSION_ID_MAX_LENGTH} characters: ${JSON.stringify(value)}`, { session_id: value, max_length: SESSION_ID_MAX_LENGTH });
16691
+ }
16692
+ try {
16693
+ assertSafePathComponent2(value, "session id");
16694
+ } catch (error) {
16695
+ throw new CoordinationError2("coordination.invalid-session-id", `session id ${JSON.stringify(value)} is not a safe path component: ${errorMessage2(error)}`, { session_id: value });
16696
+ }
16697
+ return value;
16698
+ }
16683
16699
  function readSnapshot2(dir) {
16684
16700
  const snapshotPath = join202(dir, SNAPSHOT_FILE22);
16685
16701
  if (!existsSync152(snapshotPath)) {
@@ -16863,7 +16879,7 @@ function readSessionEnvelope2(sessionPath) {
16863
16879
  return session;
16864
16880
  }
16865
16881
  function createSessionEnvelope(session) {
16866
- const path2 = sessionFilePath(session.harness_root, session.workflow_id, session.session_id);
16882
+ const path2 = sessionFilePath(session.harness_root, session.workflow_id, session.role, session.session_id);
16867
16883
  mkdirSync92(dirname122(path2), { recursive: true });
16868
16884
  try {
16869
16885
  writeFileSync72(path2, `${JSON.stringify(session, null, 2)}
@@ -17168,7 +17184,7 @@ function assertCoordinatorResidency(cwd, snapshot) {
17168
17184
  }
17169
17185
  return main;
17170
17186
  }
17171
- async function bindCoordinatorSession(cwd, workflowId, harnessDir) {
17187
+ async function bindCoordinatorSession(cwd, workflowId, harnessDir, sessionId) {
17172
17188
  const harnessRoot = requireProcessRoot(cwd, harnessDir);
17173
17189
  safePlanId(workflowId, "workflowId");
17174
17190
  const snapshotPath = snapshotPathOf(harnessRoot, workflowId);
@@ -17177,7 +17193,7 @@ async function bindCoordinatorSession(cwd, workflowId, harnessDir) {
17177
17193
  const session = {
17178
17194
  schema_version: 1,
17179
17195
  role: "coordinator",
17180
- session_id: randomUUID22(),
17196
+ session_id: sessionId ?? randomUUID22(),
17181
17197
  workflow_id: workflowId,
17182
17198
  harness_root: harnessRoot
17183
17199
  };
@@ -17217,7 +17233,7 @@ function requireProcessRoot(cwd, harnessDir) {
17217
17233
  }
17218
17234
  return root;
17219
17235
  }
17220
- async function bindPlanSessionForPlan(scope) {
17236
+ async function bindPlanSessionForPlan(scope, sessionId) {
17221
17237
  const { harnessRoot, workflowId, planId } = scope;
17222
17238
  const snapshotPath = snapshotPathOf(harnessRoot, workflowId);
17223
17239
  assertSnapshotPath2(harnessRoot, workflowId, snapshotPath);
@@ -17240,7 +17256,7 @@ async function bindPlanSessionForPlan(scope) {
17240
17256
  const session = {
17241
17257
  schema_version: 1,
17242
17258
  role: "plan-pm",
17243
- session_id: randomUUID22(),
17259
+ session_id: sessionId ?? randomUUID22(),
17244
17260
  workflow_id: workflowId,
17245
17261
  plan_id: planId,
17246
17262
  harness_root: harnessRoot
@@ -17307,19 +17323,21 @@ async function bindPlanSession(input) {
17307
17323
  return resumeBoundSession(input.resumePath);
17308
17324
  }
17309
17325
  if ("coordinator" in input) {
17310
- assertExactKeys2(input, ["coordinator", "workflowId", "harnessDir", "cwd"], "bind coordinator input");
17326
+ assertExactKeys2(input, ["coordinator", "workflowId", "harnessDir", "cwd", "sessionId"], "bind coordinator input");
17311
17327
  if (input.coordinator !== true)
17312
17328
  throw invalidInput2("`coordinator` is only meaningful as true");
17313
17329
  if (!isNonEmptyString2(input.workflowId))
17314
17330
  throw invalidInput2("workflowId is required");
17315
17331
  requireCwd(input.cwd);
17316
- return bindCoordinatorSession(input.cwd, input.workflowId, input.harnessDir);
17332
+ const sessionId2 = safeSessionId(input.sessionId);
17333
+ return bindCoordinatorSession(input.cwd, input.workflowId, input.harnessDir, sessionId2);
17317
17334
  }
17318
- assertExactKeys2(input, ["scope", "cwd"], "bind plan input");
17335
+ assertExactKeys2(input, ["scope", "cwd", "sessionId"], "bind plan input");
17319
17336
  if (!isPlainObject22(input.scope))
17320
17337
  throw invalidInput2("a plan bind requires a scope");
17321
17338
  requireCwd(input.cwd);
17322
- return bindPlanSessionForPlan(await resolvePlanScope(input.scope, input.cwd));
17339
+ const sessionId = safeSessionId(input.sessionId);
17340
+ return bindPlanSessionForPlan(await resolvePlanScope(input.scope, input.cwd), sessionId);
17323
17341
  }
17324
17342
  function requireCwd(cwd) {
17325
17343
  if (!isNonEmptyString2(cwd) || !isAbsolute122(cwd))
@@ -21241,6 +21259,16 @@ function handoffMismatch(verb, planId, live, named) {
21241
21259
  details: { plan_id: planId, expected: live, actual: named }
21242
21260
  });
21243
21261
  }
21262
+ var SESSION_ID_ENV = "MSTAR_HOST_SESSION_ID";
21263
+ function sessionIdOf(options) {
21264
+ const flag = options.sessionId;
21265
+ if (flag !== undefined)
21266
+ return flag;
21267
+ const injected = process.env[SESSION_ID_ENV];
21268
+ if (injected === undefined || injected.trim() === "")
21269
+ return;
21270
+ return injected.trim();
21271
+ }
21244
21272
  function bindInputOf(options) {
21245
21273
  const coordinator = options.coordinator === true;
21246
21274
  const workflow = options.workflow;
@@ -21258,20 +21286,22 @@ function bindInputOf(options) {
21258
21286
  resume !== undefined
21259
21287
  ].filter(Boolean).length;
21260
21288
  if (families !== 1) {
21261
- throw new SddScriptError2(`usage: plan bind --coordinator --workflow <id> [--harness <absolute-path>] [--json]
21262
- ` + ` plan bind --assignment <absolute-md-path> [--json]
21263
- ` + ` plan bind --workflow <id> --plan <id> [--harness <absolute-path>] [--json]
21289
+ throw new SddScriptError2(`usage: plan bind --coordinator --workflow <id> [--harness <absolute-path>] [--session-id <id>] [--json]
21290
+ ` + ` plan bind --assignment <absolute-md-path> [--session-id <id>] [--json]
21291
+ ` + ` plan bind --workflow <id> --plan <id> [--harness <absolute-path>] [--session-id <id>] [--json]
21264
21292
  ` + " plan bind --resume <absolute-session-json-path> [--json]", 2);
21265
21293
  }
21266
21294
  const cwd = process.cwd();
21267
21295
  if (coordinator) {
21268
21296
  if (plan !== undefined || assignment !== undefined || resume !== undefined) {
21269
- throw new SddScriptError2("plan bind --coordinator accepts only --workflow (plus optional --harness)", 2);
21297
+ throw new SddScriptError2("plan bind --coordinator accepts only --workflow (plus optional --harness and --session-id)", 2);
21270
21298
  }
21299
+ const sessionId2 = sessionIdOf(options);
21271
21300
  return {
21272
21301
  coordinator: true,
21273
21302
  workflowId: requireFlag(workflow, "--workflow", "bind", "workflow-id"),
21274
21303
  ...harness !== undefined ? { harnessDir: harness } : {},
21304
+ ...sessionId2 !== undefined ? { sessionId: sessionId2 } : {},
21275
21305
  cwd
21276
21306
  };
21277
21307
  }
@@ -21279,23 +21309,33 @@ function bindInputOf(options) {
21279
21309
  if (workflow !== undefined || plan !== undefined || harness !== undefined) {
21280
21310
  throw new SddScriptError2("plan bind --assignment accepts no --workflow/--plan/--harness (the Assignment pins the workflow and harness)", 2);
21281
21311
  }
21282
- return { scope: { assignmentPath: requireAbsolutePath(assignment, "--assignment", "bind", "md-path") }, cwd };
21312
+ const sessionId2 = sessionIdOf(options);
21313
+ return {
21314
+ scope: { assignmentPath: requireAbsolutePath(assignment, "--assignment", "bind", "md-path") },
21315
+ ...sessionId2 !== undefined ? { sessionId: sessionId2 } : {},
21316
+ cwd
21317
+ };
21283
21318
  }
21284
21319
  if (resume !== undefined) {
21285
21320
  if (harness !== undefined) {
21286
21321
  throw new SddScriptError2("plan bind --resume accepts no --harness (the session envelope pins the harness root)", 2);
21287
21322
  }
21323
+ if (options.sessionId !== undefined) {
21324
+ throw new SddScriptError2("plan bind --resume accepts no --session-id (a resumed session never re-identifies)", 2);
21325
+ }
21288
21326
  return { resumePath: requireAbsolutePath(resume, "--resume", "bind", "session-json-path"), cwd };
21289
21327
  }
21290
21328
  if (workflow === undefined || plan === undefined) {
21291
21329
  throw new SddScriptError2("plan bind --workflow requires --plan <id> (the workflow+plan address form)", 2);
21292
21330
  }
21331
+ const sessionId = sessionIdOf(options);
21293
21332
  return {
21294
21333
  scope: {
21295
21334
  workflowId: requireFlag(workflow, "--workflow", "bind", "workflow-id"),
21296
21335
  planId: requireFlag(plan, "--plan", "bind", "plan-id"),
21297
21336
  ...harness !== undefined ? { harnessDir: harness } : {}
21298
21337
  },
21338
+ ...sessionId !== undefined ? { sessionId } : {},
21299
21339
  cwd
21300
21340
  };
21301
21341
  }
@@ -21308,7 +21348,7 @@ function harnessOverrideOf(input) {
21308
21348
  }
21309
21349
  function registerPlanCommands(program2) {
21310
21350
  const plan = program2.command("plan").description("Scoped plan coordination: bind a plan or coordinator session, read its view, and run the row transitions " + "(engine-backed; JSON on stdout with --json, diagnostics on stderr; exit 0 ok/no-op, 1 scope/ownership/" + "revision/state/Git refusal, 2 usage)").exitOverride();
21311
- plan.command("bind").description("Bind the scoped session for one plan \u2014 fresh `--workflow/--plan` or `--assignment` claim (both addresses resolve " + "the same prepared row), fresh `--coordinator` bootstrap, or explicit `--resume` of an existing session file " + "(read-only: no ownership change, no takeover)").option("--coordinator", "Trusted local coordinator bootstrap (requires --workflow; one per workflow)").option("--workflow <id>", "Workflow id").option("--plan <id>", "Plan id (workflow+plan address form)").option("--assignment <path>", "Absolute path of the pinned prepared Assignment").option("--resume <path>", "Absolute path of an existing session JSON envelope").option("--harness <path>", "Absolute harness dir override (default: resolved control root)").option("--json", "Machine-readable JSON on stdout").action(async (options) => runVerb("bind", options, { workflow_id: options.workflow, plan_id: options.plan }, async (json) => {
21351
+ plan.command("bind").description("Bind the scoped session for one plan \u2014 fresh `--workflow/--plan` or `--assignment` claim (both addresses resolve " + "the same prepared row), fresh `--coordinator` bootstrap, or explicit `--resume` of an existing session file " + "(read-only: no ownership change, no takeover). A fresh bind adopts `--session-id`, else the injected " + "MSTAR_HOST_SESSION_ID, else a generated id; `--resume` takes none").option("--coordinator", "Trusted local coordinator bootstrap (requires --workflow; one per workflow)").option("--workflow <id>", "Workflow id").option("--plan <id>", "Plan id (workflow+plan address form)").option("--assignment <path>", "Absolute path of the pinned prepared Assignment").option("--resume <path>", "Absolute path of an existing session JSON envelope").option("--harness <path>", "Absolute harness dir override (default: resolved control root)").option("--session-id <id>", `Session id the fresh bind adopts (default: $${SESSION_ID_ENV}, else generated)`).option("--json", "Machine-readable JSON on stdout").action(async (options) => runVerb("bind", options, { workflow_id: options.workflow, plan_id: options.plan }, async (json) => {
21312
21352
  const input = bindInputOf(options);
21313
21353
  pinProcessRoot(harnessOverrideOf(input));
21314
21354
  await printSuccess("bind", await bindPlanSession(input), json);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mstar-harness/cli",
3
- "version": "3.11.0",
3
+ "version": "3.11.2",
4
4
  "description": "Morning Star harness CLI — installer bootstrap + mstar workflow verbs (path/status/lease/sdd/iteration/dispatch/worktree/lint/design-md/audit/compound/host/skill).",
5
5
  "license": "MIT",
6
6
  "repository": {