@mstar-harness/cli 4.0.3 → 4.0.4
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/mstar-harness.js +244 -50
- package/package.json +1 -1
package/dist/mstar-harness.js
CHANGED
|
@@ -361,6 +361,7 @@ __export(exports_engine, {
|
|
|
361
361
|
resolveKnowledgeDir: () => resolveKnowledgeDir,
|
|
362
362
|
resolveMstarcEnforcement: () => resolveMstarcEnforcement,
|
|
363
363
|
resolvePlanDir: () => resolvePlanDir,
|
|
364
|
+
resolvePrReviewSettlement: () => resolvePrReviewSettlement,
|
|
364
365
|
resolvePrReviewTier: () => resolvePrReviewTier,
|
|
365
366
|
resolveProcessHarnessDir: () => resolveProcessHarnessDir,
|
|
366
367
|
resolveProjectDir: () => resolveProjectDir,
|
|
@@ -14829,8 +14830,13 @@ function resolveReviewRunDir(opts) {
|
|
|
14829
14830
|
const resolved = spec.kind === "codebase" ? { kind: "codebase", level: spec.level, round: spec.round ?? nextCodebaseRound(opts.reviewsDir, date, spec.level) } : spec;
|
|
14830
14831
|
return join12(opts.reviewsDir, reviewRunDirName(date, resolved));
|
|
14831
14832
|
}
|
|
14832
|
-
function resolveScaffoldDirs(root) {
|
|
14833
|
+
function resolveScaffoldDirs(root, options = {}) {
|
|
14833
14834
|
const start = resolve8(root);
|
|
14835
|
+
if (options.harnessDir !== undefined) {
|
|
14836
|
+
const harnessDir2 = options.harnessDir;
|
|
14837
|
+
const projectDir2 = mstarcDirOverride(harnessDir2, "projectDir") ?? join12(harnessDir2, "projects");
|
|
14838
|
+
return { harnessDir: harnessDir2, projectDir: projectDir2 };
|
|
14839
|
+
}
|
|
14834
14840
|
const boundary = resolve8(start, defaultWorkspaceRoot(start));
|
|
14835
14841
|
const rc = loadMstarc(start, boundary);
|
|
14836
14842
|
const explicit = process.env.MSTAR_HARNESS_DIR;
|
|
@@ -14839,8 +14845,8 @@ function resolveScaffoldDirs(root) {
|
|
|
14839
14845
|
const projectDir = declaredProjectDir !== null ? declaredProjectDir : join12(harnessDir, "projects");
|
|
14840
14846
|
return { harnessDir, projectDir };
|
|
14841
14847
|
}
|
|
14842
|
-
async function scaffoldHarness(root) {
|
|
14843
|
-
const { harnessDir, projectDir } = resolveScaffoldDirs(root);
|
|
14848
|
+
async function scaffoldHarness(root, options = {}) {
|
|
14849
|
+
const { harnessDir, projectDir } = resolveScaffoldDirs(root, options);
|
|
14844
14850
|
for (const dir of SCAFFOLD_DIRS)
|
|
14845
14851
|
mkdirSync4(join12(harnessDir, dir), { recursive: true });
|
|
14846
14852
|
const defaultProjectDir = join12(projectDir, _DEFAULT_PROJECT);
|
|
@@ -16755,6 +16761,9 @@ function resolveProcessHarnessDir(cwd = process.cwd(), harnessDir) {
|
|
|
16755
16761
|
throw error;
|
|
16756
16762
|
}
|
|
16757
16763
|
if (linked) {
|
|
16764
|
+
const envRoot = process.env.MSTAR_HARNESS_DIR;
|
|
16765
|
+
if (typeof envRoot === "string" && envRoot.trim() !== "")
|
|
16766
|
+
return resolveHarnessDir(start);
|
|
16758
16767
|
throw new CoordinationError("coordination.not-in-git", "The linked checkout's main worktree cannot be read. Run mstar status validate. Then inspect the main worktree at the control harness root.", { cwd: start, marker: join16(dir, ".git") });
|
|
16759
16768
|
}
|
|
16760
16769
|
const parent = dirname9(dir);
|
|
@@ -21794,7 +21803,7 @@ function detectHost(signals) {
|
|
|
21794
21803
|
return "opencode";
|
|
21795
21804
|
if (s.has("task_agent_batch") || s.has("ask") || s.has("hub"))
|
|
21796
21805
|
return "omp";
|
|
21797
|
-
if (s.has("subagent"))
|
|
21806
|
+
if (s.has("subagent") || s.has("spawn_teammate") || s.has("team_task_create"))
|
|
21798
21807
|
return "dsh";
|
|
21799
21808
|
if (s.has("AgentSwarm"))
|
|
21800
21809
|
return "kimi";
|
|
@@ -22009,6 +22018,56 @@ function checkProvidedTallyShape(tally, violations) {
|
|
|
22009
22018
|
violations.push(violation15("high", "review.incomplete-unexpected", `tally.incomplete is carried only by the "incomplete" tally verdict - tally.verdict is "${String(tally.verdict)}"`, "remove tally.incomplete, or set tally.verdict: incomplete"));
|
|
22010
22019
|
}
|
|
22011
22020
|
}
|
|
22021
|
+
function resolvePrReviewSettlement(facts) {
|
|
22022
|
+
if (facts === null || typeof facts !== "object") {
|
|
22023
|
+
throw new TypeError(`resolvePrReviewSettlement: run facts are required - got ${JSON.stringify(facts)}`);
|
|
22024
|
+
}
|
|
22025
|
+
if (facts.stopped !== undefined && !isSingleLineFact(facts.stopped)) {
|
|
22026
|
+
throw new TypeError(`resolvePrReviewSettlement: stopped must be a non-empty single-line string - got ${JSON.stringify(facts.stopped)}`);
|
|
22027
|
+
}
|
|
22028
|
+
const domainFields = [
|
|
22029
|
+
["requiredDomains", facts.requiredDomains],
|
|
22030
|
+
["openedDomains", facts.openedDomains]
|
|
22031
|
+
];
|
|
22032
|
+
for (const [field, value] of domainFields) {
|
|
22033
|
+
if (!Array.isArray(value) || !value.every(isSingleLineFact)) {
|
|
22034
|
+
throw new TypeError(`resolvePrReviewSettlement: ${field} must be an array of non-empty single-line strings - got ${JSON.stringify(value)}`);
|
|
22035
|
+
}
|
|
22036
|
+
}
|
|
22037
|
+
if (facts.requiredDomains.length === 0) {
|
|
22038
|
+
throw new TypeError("resolvePrReviewSettlement: requiredDomains must be an array of non-empty single-line strings and must not be empty - got []");
|
|
22039
|
+
}
|
|
22040
|
+
if (typeof facts.diffBasisReadable !== "boolean") {
|
|
22041
|
+
throw new TypeError(`resolvePrReviewSettlement: diffBasisReadable must be a boolean - got ${JSON.stringify(facts.diffBasisReadable)}`);
|
|
22042
|
+
}
|
|
22043
|
+
if (facts.partialSeatScopes !== undefined && (!Array.isArray(facts.partialSeatScopes) || !facts.partialSeatScopes.every(isSingleLineFact))) {
|
|
22044
|
+
throw new TypeError(`resolvePrReviewSettlement: partialSeatScopes must be an array of non-empty single-line strings - got ${JSON.stringify(facts.partialSeatScopes)}`);
|
|
22045
|
+
}
|
|
22046
|
+
const unconsumed = [...facts.openedDomains];
|
|
22047
|
+
const missing = facts.requiredDomains.filter((domain2) => {
|
|
22048
|
+
const at = unconsumed.indexOf(domain2);
|
|
22049
|
+
if (at < 0)
|
|
22050
|
+
return true;
|
|
22051
|
+
unconsumed.splice(at, 1);
|
|
22052
|
+
return false;
|
|
22053
|
+
});
|
|
22054
|
+
const unreadableBasis = !facts.diffBasisReadable;
|
|
22055
|
+
const unscanned = [...new Set([
|
|
22056
|
+
...missing,
|
|
22057
|
+
...unreadableBasis ? ["the resolved diff basis"] : [],
|
|
22058
|
+
...facts.partialSeatScopes ?? []
|
|
22059
|
+
])];
|
|
22060
|
+
if (facts.stopped !== undefined) {
|
|
22061
|
+
return { settled: false, incomplete: { reason: `the run stopped before synthesis \u2014 ${facts.stopped}`, unscanned } };
|
|
22062
|
+
}
|
|
22063
|
+
if (missing.length > 0) {
|
|
22064
|
+
return { settled: false, incomplete: { reason: `required domain seat(s) never opened: ${missing.join(", ")}`, unscanned } };
|
|
22065
|
+
}
|
|
22066
|
+
if (unreadableBasis) {
|
|
22067
|
+
return { settled: false, incomplete: { reason: "the resolved diff basis could not be read", unscanned } };
|
|
22068
|
+
}
|
|
22069
|
+
return { settled: true };
|
|
22070
|
+
}
|
|
22012
22071
|
function validateMstarReviewV1(doc) {
|
|
22013
22072
|
const violations = [];
|
|
22014
22073
|
if (!isPlainObject9(doc)) {
|
|
@@ -23172,8 +23231,8 @@ function readDshSessionBinding(context, sessionId, cwd) {
|
|
|
23172
23231
|
return withExecutionReadGuard(context, (db) => {
|
|
23173
23232
|
const row = db.prepare("select session_id, cwd, selected_workflow_id, execution_binding, excluded_before_seq, updated_at from dsh_session_bindings where session_id = ? and cwd = ?").get(sessionId, cwd);
|
|
23174
23233
|
if (!row) {
|
|
23175
|
-
const otherCwd = db.prepare("select
|
|
23176
|
-
return otherCwd ? { kind: "unavailable", reason: "cwd-mismatch" } : { kind: "ok" };
|
|
23234
|
+
const otherCwd = db.prepare("select cwd from dsh_session_bindings where session_id = ? limit 1").get(sessionId);
|
|
23235
|
+
return otherCwd ? { kind: "unavailable", reason: "cwd-mismatch", recordedCwd: otherCwd.cwd } : { kind: "ok" };
|
|
23177
23236
|
}
|
|
23178
23237
|
return {
|
|
23179
23238
|
kind: "ok",
|
|
@@ -36116,7 +36175,7 @@ import fs23 from "node:fs";
|
|
|
36116
36175
|
// package.json
|
|
36117
36176
|
var package_default = {
|
|
36118
36177
|
name: "@mstar-harness/cli",
|
|
36119
|
-
version: "4.0.
|
|
36178
|
+
version: "4.0.4",
|
|
36120
36179
|
description: "Morning Star harness CLI \u2014 installer bootstrap, canonical command adapter, and stdio MCP server.",
|
|
36121
36180
|
repository: {
|
|
36122
36181
|
type: "git",
|
|
@@ -36166,7 +36225,7 @@ var package_default = {
|
|
|
36166
36225
|
// ../engine/package.json
|
|
36167
36226
|
var package_default2 = {
|
|
36168
36227
|
name: "@mstar-harness/engine",
|
|
36169
|
-
version: "4.0.
|
|
36228
|
+
version: "4.0.4",
|
|
36170
36229
|
description: "Morning Star Harness Workflow Engine \u2014 deterministic workflow enforcement library (path, status, lease, dispatch, sdd, iteration, lint gates).",
|
|
36171
36230
|
license: "MIT",
|
|
36172
36231
|
repository: {
|
|
@@ -64018,8 +64077,11 @@ var inputSchema8 = exports_external.object({
|
|
|
64018
64077
|
unverified: exports_external.string().optional(),
|
|
64019
64078
|
unmetAcUnsafe: exports_external.string().optional(),
|
|
64020
64079
|
unmetAcSafe: exports_external.string().optional(),
|
|
64021
|
-
|
|
64022
|
-
|
|
64080
|
+
stopped: exports_external.string().optional(),
|
|
64081
|
+
requiredDomains: exports_external.string().optional(),
|
|
64082
|
+
openedDomains: exports_external.string().optional(),
|
|
64083
|
+
diffBasis: exports_external.string().optional(),
|
|
64084
|
+
partialScope: exports_external.array(exports_external.string()).optional(),
|
|
64023
64085
|
reviewsDir: exports_external.string().optional(),
|
|
64024
64086
|
target: exports_external.string().optional(),
|
|
64025
64087
|
stage: exports_external.string().optional(),
|
|
@@ -64047,7 +64109,7 @@ var inputSchema8 = exports_external.object({
|
|
|
64047
64109
|
remainingMinutes: exports_external.string().optional()
|
|
64048
64110
|
});
|
|
64049
64111
|
var contracts2 = {
|
|
64050
|
-
tally: { args: [], options: [{ key: "findings", flags: "--findings <file.json>", required: true }, { key: "unverified", flags: "--unverified <n>", required: false, defaultValue: "0" }, { key: "unmetAcUnsafe", flags: "--unmet-ac-unsafe <n>", required: false, defaultValue: "0" }, { key: "unmetAcSafe", flags: "--unmet-ac-safe <n>", required: false, defaultValue: "0" }, { key: "
|
|
64112
|
+
tally: { args: [], options: [{ key: "findings", flags: "--findings <file.json>", required: true, help: "Required; path to a JSON array of {mergeClass: must-fix | should-fix | nit}." }, { key: "unverified", flags: "--unverified <n>", required: false, defaultValue: "0", help: "Optional; non-negative integer no greater than 50; defaults to 0." }, { key: "unmetAcUnsafe", flags: "--unmet-ac-unsafe <n>", required: false, defaultValue: "0", help: "Optional; non-negative integer no greater than 50; defaults to 0." }, { key: "unmetAcSafe", flags: "--unmet-ac-safe <n>", required: false, defaultValue: "0", help: "Optional; non-negative integer no greater than 50; defaults to 0." }, { key: "stopped", flags: "--stopped <text>", required: false, help: "Optional; non-blank single line naming why the run stopped before synthesis; presence derives the incomplete verdict." }, { key: "requiredDomains", flags: "--required-domains <d,d,...>", required: false, help: "Required; comma-separated single-line domain names, one entry per required seat (a domain with two seats appears twice); at least one; omitted is refused, never inferred." }, { key: "openedDomains", flags: "--opened-domains <d,d,...>", required: false, help: "Required; comma-separated single-line domain names, one entry per seat that returned evidence (a domain with two seats needs two matching entries when both returned); an explicitly empty value means none, omission is refused." }, { key: "diffBasis", flags: "--diff-basis <readable|unreadable>", required: false, help: "Required; one of readable | unreadable; omitted is refused, never defaulted." }, { key: "partialScope", flags: "--partial-scope <scope...>", required: false, defaultValue: [], help: "Optional; repeat once per scope a seat declared as truncated coverage; when the run is unsettled these join the derived unscanned list, and when it settles they are echoed as declaredScopes." }], effects: ["read", "validate"], description: "Compute PR-review tally from a JSON array of {mergeClass: must-fix|should-fix|nit}; the incomplete verdict is derived from the run facts (--stopped, --required-domains/--opened-domains as one entry per seat, --diff-basis, and --partial-scope for scopes seats declared as truncated), never elapsed time; the three coverage/basis facts are required, so a run that does not report its coverage is refused; the count options default to zero and are limited to 0\u201350." },
|
|
64051
64113
|
"report-path": { args: [], options: [{ key: "reviewsDir", flags: "--reviews-dir <dir>", required: false, help: "Review root; defaults to {REVIEW_DIR} under the harness dir." }, { key: "target", flags: "--target <spec>", required: true }, { key: "stage", flags: "--stage <1|2>", required: false, help: "Optional, but if supplied it requires --slug; stage must be 1 or 2." }, { key: "slug", flags: "--slug <domain-seat>", required: false, help: "Optional, but if supplied it requires --stage." }, { key: "date", flags: "--date <YYYY-MM-DD>", required: false, help: "Defaults to the local calendar date; no report file is written or reserved." }], effects: ["read"], description: "Compute the report path inside the target's run directory under {REVIEW_DIR} from the PR/branch/diff target, optional paired stage/slug, and local-date default. This command does not write the report, inspect collision state, or add a revision suffix." },
|
|
64052
64114
|
"validate-report": { args: [{ key: "reportFile", required: true, variadic: false }], options: [], effects: ["read", "validate"], description: "Validate a saved PR-review report and return its structured violations." },
|
|
64053
64115
|
post: { args: [], options: [{ key: "pr", flags: "--pr <n>", required: true }, { key: "bodyFile", flags: "--body-file <path>", required: true }, { key: "findings", flags: "--findings <file.json>", required: false }], effects: ["read", "validate", "process", "service"], description: "Post a body and optional parsed inline findings to the requested PR's resolved current head. If GitHub returns 422 for inline comments, retry once with those comments folded into the review body. A failed final response has unknown outcome: inspect the PR before retrying." },
|
|
@@ -64164,18 +64226,35 @@ async function execute10(verb, input2, context2) {
|
|
|
64164
64226
|
});
|
|
64165
64227
|
}
|
|
64166
64228
|
}
|
|
64167
|
-
if (input2.
|
|
64168
|
-
diagnostics.push({
|
|
64169
|
-
path: input2.incompleteReason === undefined ? "incompleteReason" : "unscanned",
|
|
64170
|
-
code: "required",
|
|
64171
|
-
message: "--incomplete-reason and --unscanned go together"
|
|
64172
|
-
});
|
|
64229
|
+
if (input2.stopped !== undefined && (input2.stopped.trim() === "" || /[\r\n]/.test(input2.stopped))) {
|
|
64230
|
+
diagnostics.push({ path: "stopped", code: "invalid", message: "--stopped must be a single line of non-blank text" });
|
|
64173
64231
|
}
|
|
64174
|
-
|
|
64175
|
-
diagnostics.push({ path:
|
|
64232
|
+
const missing = (flag, path252) => {
|
|
64233
|
+
diagnostics.push({ path: path252, code: "required", message: `${flag} is required`, expected: "present", received: "undefined" });
|
|
64234
|
+
};
|
|
64235
|
+
const domains = (raw, path252, flag) => {
|
|
64236
|
+
if (raw === undefined) {
|
|
64237
|
+
missing(flag, path252);
|
|
64238
|
+
return [];
|
|
64239
|
+
}
|
|
64240
|
+
if (raw.trim() === "")
|
|
64241
|
+
return [];
|
|
64242
|
+
const entries = raw.split(",").map((entry) => entry.trim());
|
|
64243
|
+
if (entries.some((entry) => entry === "" || /[\r\n]/.test(entry))) {
|
|
64244
|
+
diagnostics.push({ path: path252, code: "invalid", message: `${flag} must be a comma-separated list of single-line non-blank entries` });
|
|
64245
|
+
return [];
|
|
64246
|
+
}
|
|
64247
|
+
return entries;
|
|
64248
|
+
};
|
|
64249
|
+
const requiredDomains = domains(input2.requiredDomains, "requiredDomains", "--required-domains");
|
|
64250
|
+
if (input2.requiredDomains !== undefined && input2.requiredDomains.trim() === "") {
|
|
64251
|
+
diagnostics.push({ path: "requiredDomains", code: "invalid", message: "--required-domains must name at least one domain" });
|
|
64176
64252
|
}
|
|
64177
|
-
|
|
64178
|
-
|
|
64253
|
+
const openedDomains = domains(input2.openedDomains, "openedDomains", "--opened-domains");
|
|
64254
|
+
if (input2.diffBasis === undefined)
|
|
64255
|
+
missing("--diff-basis", "diffBasis");
|
|
64256
|
+
else if (input2.diffBasis !== "readable" && input2.diffBasis !== "unreadable") {
|
|
64257
|
+
diagnostics.push({ path: "diffBasis", code: "invalid", message: "--diff-basis must be readable or unreadable" });
|
|
64179
64258
|
}
|
|
64180
64259
|
const count = (raw, label, path252) => {
|
|
64181
64260
|
if (raw === undefined)
|
|
@@ -64187,22 +64266,31 @@ async function execute10(verb, input2, context2) {
|
|
|
64187
64266
|
return Number(raw);
|
|
64188
64267
|
};
|
|
64189
64268
|
const unverifiedCount = count(input2.unverified, "--unverified", "unverified");
|
|
64269
|
+
const partialScope = (input2.partialScope ?? []).flatMap((entry) => {
|
|
64270
|
+
if (entry.trim() === "" || /[\r\n]/.test(entry)) {
|
|
64271
|
+
diagnostics.push({ path: "partialScope", code: "invalid", message: "--partial-scope entries must be single lines of non-blank text" });
|
|
64272
|
+
return [];
|
|
64273
|
+
}
|
|
64274
|
+
return [entry];
|
|
64275
|
+
});
|
|
64190
64276
|
const unmetAcUnsafe = count(input2.unmetAcUnsafe, "--unmet-ac-unsafe", "unmetAcUnsafe");
|
|
64191
64277
|
const unmetAcSafe = count(input2.unmetAcSafe, "--unmet-ac-safe", "unmetAcSafe");
|
|
64192
64278
|
if (diagnostics.length > 0)
|
|
64193
64279
|
throw new UsageError3(diagnostics[0].message, diagnostics);
|
|
64194
|
-
const
|
|
64195
|
-
|
|
64196
|
-
|
|
64197
|
-
|
|
64198
|
-
|
|
64280
|
+
const settlement = resolvePrReviewSettlement({
|
|
64281
|
+
...input2.stopped === undefined ? {} : { stopped: input2.stopped },
|
|
64282
|
+
requiredDomains,
|
|
64283
|
+
openedDomains,
|
|
64284
|
+
diffBasisReadable: input2.diffBasis === "readable",
|
|
64285
|
+
...partialScope.length === 0 ? {} : { partialSeatScopes: partialScope }
|
|
64286
|
+
});
|
|
64199
64287
|
const result = computePrTally({
|
|
64200
64288
|
findings,
|
|
64201
64289
|
unverifiedCount,
|
|
64202
64290
|
unmetAc: [...Array.from({ length: unmetAcUnsafe }, () => ({ unsafeToShip: true })), ...Array.from({ length: unmetAcSafe }, () => ({ unsafeToShip: false }))],
|
|
64203
|
-
...
|
|
64291
|
+
...settlement.settled ? {} : { incomplete: settlement.incomplete }
|
|
64204
64292
|
});
|
|
64205
|
-
return ok13(id, result);
|
|
64293
|
+
return ok13(id, settlement.settled && partialScope.length > 0 ? { ...result, declaredScopes: [...new Set(partialScope)] } : result);
|
|
64206
64294
|
}
|
|
64207
64295
|
if (verb === "report-path") {
|
|
64208
64296
|
const stage = input2.stage === undefined ? undefined : input2.stage === "1" ? 1 : input2.stage === "2" ? 2 : (() => {
|
|
@@ -64386,8 +64474,11 @@ function getPrReviewCommandDefinitions() {
|
|
|
64386
64474
|
...contract3.args.filter(({ required: required7 }) => required7).map(({ key }) => ({ name: key, ownership: "caller", route, required: true })),
|
|
64387
64475
|
...contract3.options.filter(({ required: required7 }) => required7).map(({ key }) => ({ name: key, ownership: "caller", route, required: true })),
|
|
64388
64476
|
...verb === "tally" ? [
|
|
64389
|
-
{ name: "
|
|
64390
|
-
{ name: "
|
|
64477
|
+
{ name: "stopped", ownership: "caller", route, required: false, constraint: "non-blank single line; presence derives the incomplete verdict" },
|
|
64478
|
+
{ name: "requiredDomains", ownership: "caller", route, required: false, constraint: "required at execution; comma-separated non-empty domain names, one entry per required seat - a domain with two seats appears twice; never inferred - an omission is refused beside the other field diagnostics" },
|
|
64479
|
+
{ name: "openedDomains", ownership: "caller", route, required: false, constraint: "required at execution; comma-separated domain names, one entry per seat that returned evidence - a domain with two seats appears twice, and both entries are needed when both returned; an empty list is legal, an omission is refused beside the other field diagnostics" },
|
|
64480
|
+
{ name: "diffBasis", ownership: "caller", route, required: false, constraint: "required at execution; one of readable | unreadable - an omission or an unaccepted value is refused beside the other field diagnostics" },
|
|
64481
|
+
{ name: "partialScope", ownership: "caller", route, required: false, constraint: "optional; repeat once per scope a seat declared as truncated coverage; each entry is a single line of non-blank text; the entries join the derived unscanned list when the run is unsettled and are echoed as declaredScopes when it settles" }
|
|
64391
64482
|
] : [],
|
|
64392
64483
|
...verb === "report-path" ? [
|
|
64393
64484
|
{ name: "reviewsDir", ownership: "derivable", route, required: false, constraint: "defaults to {REVIEW_DIR} under the harness dir" },
|
|
@@ -65382,6 +65473,9 @@ var hostSignals = [
|
|
|
65382
65473
|
"task_agent_batch",
|
|
65383
65474
|
"ask",
|
|
65384
65475
|
"hub",
|
|
65476
|
+
"subagent",
|
|
65477
|
+
"spawn_teammate",
|
|
65478
|
+
"team_task_create",
|
|
65385
65479
|
"Agent",
|
|
65386
65480
|
"AgentSwarm",
|
|
65387
65481
|
"AskUserQuestion",
|
|
@@ -65554,10 +65648,12 @@ function getLocalCommandDefinitions() {
|
|
|
65554
65648
|
input: exports_external.object({ path: exports_external.string().min(1).optional() }),
|
|
65555
65649
|
effects: ["write"],
|
|
65556
65650
|
description: "Create the harness directories and default project; then run mstar store init to activate execution authority.",
|
|
65557
|
-
async execute(input2) {
|
|
65558
|
-
const root = input2.path === undefined ?
|
|
65559
|
-
|
|
65560
|
-
const
|
|
65651
|
+
async execute(input2, context2) {
|
|
65652
|
+
const root = input2.path === undefined ? context2.cwd : path28.resolve(context2.cwd, input2.path);
|
|
65653
|
+
const harnessPin = input2.path === undefined ? context2.harnessPin : undefined;
|
|
65654
|
+
const scaffoldOptions = harnessPin === undefined ? {} : { harnessDir: harnessPin };
|
|
65655
|
+
setArtifactStore(createFsStore(resolveScaffoldDirs(root, scaffoldOptions).harnessDir));
|
|
65656
|
+
const harnessDir2 = await scaffoldHarness(root, scaffoldOptions);
|
|
65561
65657
|
const projectDir = resolveProjectDir(root, { harnessDir: harnessDir2 });
|
|
65562
65658
|
const created = [];
|
|
65563
65659
|
const skipped = [];
|
|
@@ -66296,6 +66392,7 @@ async function runAdmitted(bindings, context2) {
|
|
|
66296
66392
|
function admittedCommand(bindings) {
|
|
66297
66393
|
return Object.freeze({
|
|
66298
66394
|
...bindings.sessionId === undefined ? {} : { sessionId: bindings.sessionId },
|
|
66395
|
+
...bindings.harness === undefined ? {} : { harness: bindings.harness },
|
|
66299
66396
|
...bindings.stdinText === undefined ? {} : { stdinText: bindings.stdinText },
|
|
66300
66397
|
execute(context2) {
|
|
66301
66398
|
return runAdmitted(bindings, context2);
|
|
@@ -66409,6 +66506,7 @@ function admitCommandInput(definition22, input2, contract3, schema3 = definition
|
|
|
66409
66506
|
}
|
|
66410
66507
|
const parsedRecord = parsed.data !== null && typeof parsed.data === "object" ? parsed.data : {};
|
|
66411
66508
|
const stdinText = definition22.effects.includes("stdin") && typeof parsedRecord.input === "string" ? parsedRecord.input : undefined;
|
|
66509
|
+
const callHarness = parsedRecord.harness;
|
|
66412
66510
|
return {
|
|
66413
66511
|
success: true,
|
|
66414
66512
|
...admittedCommand({
|
|
@@ -66417,6 +66515,7 @@ function admitCommandInput(definition22, input2, contract3, schema3 = definition
|
|
|
66417
66515
|
data: shape(parsed.data),
|
|
66418
66516
|
required: required7,
|
|
66419
66517
|
...typeof selectorValue === "string" ? { sessionId: selectorValue } : {},
|
|
66518
|
+
...typeof callHarness === "string" && callHarness.trim() !== "" ? { harness: callHarness } : {},
|
|
66420
66519
|
...stdinText === undefined ? {} : { stdinText }
|
|
66421
66520
|
})
|
|
66422
66521
|
};
|
|
@@ -88120,7 +88219,15 @@ Recovery: ${recovery}`}`;
|
|
|
88120
88219
|
function mcpToolName(commandId) {
|
|
88121
88220
|
return `mstar_${commandId.replace(/[.-]/g, "_")}`;
|
|
88122
88221
|
}
|
|
88123
|
-
function
|
|
88222
|
+
function lockedDescriptor(descriptor, selectorKey) {
|
|
88223
|
+
return {
|
|
88224
|
+
...descriptor,
|
|
88225
|
+
required: descriptor.required.filter((field) => field !== selectorKey),
|
|
88226
|
+
requirements: descriptor.requirements.filter((entry) => entry.name !== selectorKey),
|
|
88227
|
+
cli: { ...descriptor.cli, options: descriptor.cli.options.filter((option) => option.key !== selectorKey) }
|
|
88228
|
+
};
|
|
88229
|
+
}
|
|
88230
|
+
function mcpInputContract(definition3, descriptor, identityLocked) {
|
|
88124
88231
|
const input2 = definition3.input;
|
|
88125
88232
|
const jsonSchema = descriptor.input;
|
|
88126
88233
|
if (!(input2 instanceof exports_external.ZodObject))
|
|
@@ -88144,7 +88251,7 @@ function mcpInputContract(definition3, descriptor) {
|
|
|
88144
88251
|
requiredShape[field] = declared.unwrap();
|
|
88145
88252
|
}
|
|
88146
88253
|
let schema3 = Object.keys(requiredShape).length === 0 ? extended2 : extended2.safeExtend(requiredShape);
|
|
88147
|
-
if (selector !== undefined) {
|
|
88254
|
+
if (selector !== undefined && !identityLocked) {
|
|
88148
88255
|
schema3 = schema3.safeExtend({ [selector.key]: exports_external.string().optional() });
|
|
88149
88256
|
properties[selector.key] = { type: "string" };
|
|
88150
88257
|
}
|
|
@@ -88189,6 +88296,20 @@ function normalizedBlankHarness(input2, defaultHarness) {
|
|
|
88189
88296
|
return input2;
|
|
88190
88297
|
return { ...record3, harness: defaultHarness };
|
|
88191
88298
|
}
|
|
88299
|
+
function strippedSessionInput(definition3, input2, locked) {
|
|
88300
|
+
if (!locked || input2 === null || typeof input2 !== "object" || Array.isArray(input2))
|
|
88301
|
+
return input2;
|
|
88302
|
+
const keys = definition3.cli.options.filter((option) => option.context === "sessionId").map((option) => option.key);
|
|
88303
|
+
if (keys.length === 0)
|
|
88304
|
+
return input2;
|
|
88305
|
+
const record3 = input2;
|
|
88306
|
+
if (!keys.some((key) => record3[key] !== undefined))
|
|
88307
|
+
return input2;
|
|
88308
|
+
const normalized = { ...record3 };
|
|
88309
|
+
for (const key of keys)
|
|
88310
|
+
delete normalized[key];
|
|
88311
|
+
return normalized;
|
|
88312
|
+
}
|
|
88192
88313
|
function registerMcpCommands(server, definitions2, resolveContext, services = [], onToolsRegistered) {
|
|
88193
88314
|
const connectionEffects = createMcpEffects(services);
|
|
88194
88315
|
const tools = definitions2.map((definition3) => ({ definition: definition3, name: mcpToolName(definition3.id) }));
|
|
@@ -88201,8 +88322,11 @@ function registerMcpCommands(server, definitions2, resolveContext, services = []
|
|
|
88201
88322
|
}
|
|
88202
88323
|
onToolsRegistered?.([...names]);
|
|
88203
88324
|
for (const { definition: definition3, name } of tools) {
|
|
88325
|
+
const identityLocked = resolveContext.identityLocked === true;
|
|
88204
88326
|
const descriptor = getCommandSchemas([definition3])[0];
|
|
88205
|
-
const
|
|
88327
|
+
const selector = definition3.cli.options.find((option) => option.context === "sessionId");
|
|
88328
|
+
const published = identityLocked && selector !== undefined ? lockedDescriptor(descriptor, selector.key) : descriptor;
|
|
88329
|
+
const contract3 = mcpInputContract(definition3, published, identityLocked);
|
|
88206
88330
|
const harnessDefault = declaresHarness(contract3);
|
|
88207
88331
|
const inputSchema10 = {
|
|
88208
88332
|
"~standard": {
|
|
@@ -88210,19 +88334,20 @@ function registerMcpCommands(server, definitions2, resolveContext, services = []
|
|
|
88210
88334
|
vendor: "mstar-harness",
|
|
88211
88335
|
jsonSchema: { input: () => contract3.jsonSchema, output: () => contract3.jsonSchema },
|
|
88212
88336
|
validate(input2) {
|
|
88337
|
+
const identityLocked2 = resolveContext.identityLocked === true;
|
|
88213
88338
|
const defaultSessionId = resolveContext.defaultSessionId;
|
|
88214
88339
|
const defaultHarness = harnessDefault ? resolveContext.defaultHarness : undefined;
|
|
88215
|
-
const admitted = admitCommandInput(definition3, normalizedBlankHarness(input2, defaultHarness), descriptor, contract3.schema, (data) => handlerInput(definition3, data, defaultHarness), defaultSessionId === undefined ? undefined : { sessionId: defaultSessionId });
|
|
88340
|
+
const admitted = admitCommandInput(definition3, normalizedBlankHarness(strippedSessionInput(definition3, input2, identityLocked2), defaultHarness), descriptor, contract3.schema, (data) => handlerInput(definition3, data, defaultHarness), defaultSessionId === undefined ? undefined : { sessionId: defaultSessionId });
|
|
88216
88341
|
return admitted.success ? { value: admitted } : { issues: [{ message: JSON.stringify(admitted.envelope) }] };
|
|
88217
88342
|
}
|
|
88218
88343
|
}
|
|
88219
88344
|
};
|
|
88220
88345
|
server.registerTool(name, {
|
|
88221
|
-
description: renderCommandContract(definition3, "mcp",
|
|
88346
|
+
description: renderCommandContract(definition3, "mcp", published),
|
|
88222
88347
|
inputSchema: inputSchema10,
|
|
88223
88348
|
outputSchema: definition3.output
|
|
88224
88349
|
}, async (admitted, extra) => {
|
|
88225
|
-
const resolved = await resolveContext(definition3, admitted.sessionId, extra.mcpReq.signal, services, connectionEffects);
|
|
88350
|
+
const resolved = await resolveContext(definition3, admitted.sessionId, extra.mcpReq.signal, services, connectionEffects, { harness: admitted.harness });
|
|
88226
88351
|
const sessionId = admitted.sessionId ?? resolved.sessionId;
|
|
88227
88352
|
const requestContext = Object.freeze({
|
|
88228
88353
|
...resolved,
|
|
@@ -88261,8 +88386,8 @@ function createMcpServer(resolveContext, definitions2 = getCommandDefinitions(),
|
|
|
88261
88386
|
server.server.onclose = () => {
|
|
88262
88387
|
closeServices();
|
|
88263
88388
|
};
|
|
88264
|
-
const createRequestContext = async (definition3, sessionId, signal, requestServices, effects) => {
|
|
88265
|
-
const context2 = await resolveContext(definition3, sessionId, signal, requestServices, effects);
|
|
88389
|
+
const createRequestContext = async (definition3, sessionId, signal, requestServices, effects, call) => {
|
|
88390
|
+
const context2 = await resolveContext(definition3, sessionId, signal, requestServices, effects, call);
|
|
88266
88391
|
const requestContext = Object.freeze({
|
|
88267
88392
|
...context2,
|
|
88268
88393
|
versions: Object.freeze({ ...context2.versions }),
|
|
@@ -88279,23 +88404,88 @@ function createMcpServer(resolveContext, definitions2 = getCommandDefinitions(),
|
|
|
88279
88404
|
get: () => resolveContext.defaultHarness,
|
|
88280
88405
|
enumerable: true
|
|
88281
88406
|
});
|
|
88407
|
+
Object.defineProperty(createRequestContext, "identityLocked", {
|
|
88408
|
+
get: () => resolveContext.identityLocked === true,
|
|
88409
|
+
enumerable: true
|
|
88410
|
+
});
|
|
88282
88411
|
registerMcpCommands(server, definitions2, createRequestContext, services, onToolsRegistered);
|
|
88283
88412
|
return server;
|
|
88284
88413
|
}
|
|
88285
88414
|
|
|
88286
88415
|
// src/mcp/stdio.ts
|
|
88287
|
-
|
|
88416
|
+
var NULL_ROOT_BOOTSTRAP_COMMANDS = new Set(["harness.scaffold"]);
|
|
88417
|
+
|
|
88418
|
+
class McpControlRootError extends Error {
|
|
88419
|
+
details;
|
|
88420
|
+
code = "mcp.control-root-unresolved";
|
|
88421
|
+
constructor(message, details) {
|
|
88422
|
+
super(message);
|
|
88423
|
+
this.details = details;
|
|
88424
|
+
this.name = "McpControlRootError";
|
|
88425
|
+
}
|
|
88426
|
+
}
|
|
88427
|
+
function probeUnpinnedControlRoot(cwd) {
|
|
88428
|
+
try {
|
|
88429
|
+
const root = resolveProcessHarnessDir(cwd);
|
|
88430
|
+
if (root !== null)
|
|
88431
|
+
return { root, cause: null };
|
|
88432
|
+
return { root: null, cause: "no harness directory found within the workspace boundary of the launch cwd" };
|
|
88433
|
+
} catch (error62) {
|
|
88434
|
+
return { root: null, cause: error62 instanceof Error ? error62.message : String(error62) };
|
|
88435
|
+
}
|
|
88436
|
+
}
|
|
88437
|
+
function unresolvedControlRootMessage(cwd, cause) {
|
|
88438
|
+
return `[mcp.control-root-unresolved] This MCP server was launched from ${cwd}, which resolves to no harness root (${cause}). ` + "The server cannot know which workspace a caller belongs to, so it refuses instead of probing a root the caller never named. " + "Recovery: launch the server with `mstar mcp --harness <absolute path>` (or set MSTAR_HARNESS_DIR for the server process) to pin the root, " + "or launch the host from the session workspace so the cwd probe resolves that workspace's root.";
|
|
88439
|
+
}
|
|
88440
|
+
function resolveDeclaredIdentity(identityEnv) {
|
|
88288
88441
|
if (identityEnv === undefined)
|
|
88289
|
-
return;
|
|
88442
|
+
return { sessionId: undefined, warning: null };
|
|
88290
88443
|
const value = process.env[identityEnv];
|
|
88291
|
-
|
|
88444
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
88445
|
+
return { sessionId: undefined, warning: unresolvedIdentityChannelWarning(identityEnv) };
|
|
88446
|
+
}
|
|
88447
|
+
try {
|
|
88448
|
+
assertSafeSessionId(value, `--identity-env ${identityEnv}`);
|
|
88449
|
+
} catch {
|
|
88450
|
+
return { sessionId: undefined, warning: unsafeIdentityChannelWarning(identityEnv) };
|
|
88451
|
+
}
|
|
88452
|
+
return { sessionId: value, warning: null };
|
|
88453
|
+
}
|
|
88454
|
+
function unsafeIdentityChannelWarning(identityEnv) {
|
|
88455
|
+
return `[mcp.identity-env-unsafe] --identity-env ${identityEnv} resolved to a value that is not a valid session id ` + `(the rule: one safe path component [A-Za-z0-9._-]+ of at most ${SESSION_ID_MAX_LENGTH} characters, ` + 'not "", ".", "..", or containing "/" or "\\"; the rejected value is not echoed), ' + "so this connection stays unlocked and the per-call sessionId selector remains the identity channel. " + `Recovery: correct ${identityEnv} to a valid session id, or drop --identity-env to declare a generic connection explicitly, then relaunch the server (the identity is a launch fact).`;
|
|
88456
|
+
}
|
|
88457
|
+
function unresolvedIdentityChannelWarning(identityEnv) {
|
|
88458
|
+
return `[mcp.identity-env-unresolved] --identity-env ${identityEnv} resolved to no session id (the variable is unset or blank), ` + "so this connection stays unlocked and the per-call sessionId selector remains the identity channel. " + `Recovery: set ${identityEnv} to the session id before launch, or drop --identity-env to declare a generic connection explicitly.`;
|
|
88292
88459
|
}
|
|
88293
88460
|
function createContextResolver(options2 = {}) {
|
|
88294
|
-
const
|
|
88295
|
-
|
|
88461
|
+
const declared = resolveDeclaredIdentity(options2.identityEnv);
|
|
88462
|
+
const declaredIdentity = declared.sessionId;
|
|
88463
|
+
const identityLocked = declaredIdentity !== undefined;
|
|
88464
|
+
if (declared.warning !== null)
|
|
88465
|
+
process.stderr.write(`${declared.warning}
|
|
88466
|
+
`);
|
|
88467
|
+
const resolver2 = (definition3, _sessionId, signal, _services, effects, call) => {
|
|
88468
|
+
const sessionId = declaredIdentity;
|
|
88469
|
+
const callHarness = call?.harness;
|
|
88470
|
+
let controlRoot;
|
|
88471
|
+
if (options2.harnessRoot === undefined) {
|
|
88472
|
+
const probe = probeUnpinnedControlRoot(process.cwd());
|
|
88473
|
+
if (probe.root === null && !NULL_ROOT_BOOTSTRAP_COMMANDS.has(definition3.id)) {
|
|
88474
|
+
if (callHarness === undefined) {
|
|
88475
|
+
const cwd = process.cwd();
|
|
88476
|
+
throw new McpControlRootError(unresolvedControlRootMessage(cwd, probe.cause), { cwd, cause: probe.cause });
|
|
88477
|
+
}
|
|
88478
|
+
controlRoot = callHarness;
|
|
88479
|
+
} else {
|
|
88480
|
+
controlRoot = probe.root;
|
|
88481
|
+
}
|
|
88482
|
+
} else {
|
|
88483
|
+
controlRoot = options2.harnessRoot;
|
|
88484
|
+
}
|
|
88296
88485
|
return {
|
|
88297
88486
|
cwd: options2.harnessRoot === undefined ? process.cwd() : dirname24(options2.harnessRoot),
|
|
88298
|
-
controlRoot
|
|
88487
|
+
controlRoot,
|
|
88488
|
+
...options2.harnessRoot === undefined ? {} : { harnessPin: options2.harnessRoot },
|
|
88299
88489
|
...sessionId === undefined ? {} : { sessionId },
|
|
88300
88490
|
versions: { engine: null, cli: null, plugin: null, host: null, platform: null },
|
|
88301
88491
|
signal,
|
|
@@ -88303,13 +88493,17 @@ function createContextResolver(options2 = {}) {
|
|
|
88303
88493
|
};
|
|
88304
88494
|
};
|
|
88305
88495
|
Object.defineProperty(resolver2, "defaultSessionId", {
|
|
88306
|
-
get: () =>
|
|
88496
|
+
get: () => declaredIdentity,
|
|
88307
88497
|
enumerable: true
|
|
88308
88498
|
});
|
|
88309
88499
|
Object.defineProperty(resolver2, "defaultHarness", {
|
|
88310
88500
|
get: () => options2.harnessRoot,
|
|
88311
88501
|
enumerable: true
|
|
88312
88502
|
});
|
|
88503
|
+
Object.defineProperty(resolver2, "identityLocked", {
|
|
88504
|
+
get: () => identityLocked,
|
|
88505
|
+
enumerable: true
|
|
88506
|
+
});
|
|
88313
88507
|
return resolver2;
|
|
88314
88508
|
}
|
|
88315
88509
|
var resolveContext = createContextResolver();
|
|
@@ -88334,7 +88528,7 @@ function absoluteHarness(value) {
|
|
|
88334
88528
|
return value;
|
|
88335
88529
|
}
|
|
88336
88530
|
function registerMcpCommand(program2) {
|
|
88337
|
-
program2.command("mcp").description("Run the Morning Star MCP server over stdio").option("--identity-env <NAME>", "read the default session id from environment variable NAME
|
|
88531
|
+
program2.command("mcp").description("Run the Morning Star MCP server over stdio").option("--identity-env <NAME>", "read the default session id from environment variable NAME and LOCK the connection identity to it when the variable resolves a usable id (one safe path component under the engine's safe-session-id rule): the tools publish no session selector and a caller-supplied sessionId is stripped before admission, so every call runs under the declared identity. An unset, blank or unsafe value keeps the connection generic and is warned about at launch, with the recovery to correct the variable or drop --identity-env and relaunch. Without it no ambient identity is read and a per-call sessionId selects the identity.").option("--harness <path>", "absolute harness root for every call; it also anchors the invocation workspace at its parent, so cwd-derived paths land under the pinned harness. Without it the server probes process.cwd() for one", absoluteHarness).action(async (options2) => {
|
|
88338
88532
|
await serveMcpStdio({ identityEnv: options2.identityEnv, harnessRoot: options2.harness });
|
|
88339
88533
|
});
|
|
88340
88534
|
}
|