@stalfh233/omc-cli 0.6.47 → 0.6.50
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/capability-overview.js +114 -1
- package/dist/cli-stdout.js +3 -0
- package/dist/cli.js +318 -62
- package/dist/closest-match.js +22 -3
- package/dist/command-transport.js +5 -1
- package/dist/discovery.js +193 -75
- package/dist/goal-plan.js +1296 -0
- package/dist/goal-routes.js +87 -5
- package/dist/graph.js +223 -34
- package/dist/intent/capabilities/field.js +24 -0
- package/dist/intent/plan-apply.js +10 -3
- package/dist/intent/schema.js +24 -1
- package/dist/lanes/app.js +4 -0
- package/dist/lanes/apply-changes.js +1 -0
- package/dist/lanes/b2-registration.js +24 -0
- package/dist/lanes/businessrule.js +14 -0
- package/dist/lanes/custom-page.js +8 -0
- package/dist/lanes/datarule.js +4 -0
- package/dist/lanes/dictionary.js +13 -0
- package/dist/lanes/environment.js +2 -0
- package/dist/lanes/field.js +5 -0
- package/dist/lanes/folder.js +4 -0
- package/dist/lanes/form.js +5 -0
- package/dist/lanes/list-view-contract.js +1 -1
- package/dist/lanes/list-view.js +5 -0
- package/dist/lanes/meta.js +5 -0
- package/dist/lanes/model.js +9 -0
- package/dist/lanes/online-js.js +2 -0
- package/dist/lanes/organization.js +20 -0
- package/dist/lanes/perm.js +5 -5
- package/dist/lanes/programming.js +6 -0
- package/dist/lanes/report.js +9 -0
- package/dist/lanes/rule-lifecycle.js +6 -0
- package/dist/lanes/rulelog.js +1 -0
- package/dist/lanes/runtime-data.js +39 -1
- package/dist/lanes/workflow.js +18 -0
- package/dist/mcp-graph.js +180 -41
- package/dist/package-tool.js +1 -0
- package/dist/recipes/workflow.js +1 -1
- package/dist/search-index.js +137 -0
- package/dist/tool-search.js +647 -0
- package/dist/tool-types.js +6 -0
- package/dist/tools.js +1 -0
- package/dist/write.js +2 -1
- package/docs/omc-introduction.md +5 -7
- package/package.json +6 -5
- package/skills/omc-business-configuration.md +2 -1
- package/skills/omc-capabilities.md +4 -2
- package/skills/omc-start-here.md +21 -7
- package/skills/omc-tool-selection.md +7 -15
- package/skills/omc-write-hazards.md +1 -1
package/dist/cli.js
CHANGED
|
@@ -26,6 +26,7 @@ import { artifactFetchHint, artifactRoot, boundResult, emitInvalid, emitResult,
|
|
|
26
26
|
import { CLI_DEFAULT_OUTPUT_BYTES, assertSafeOutputPath, pruneArtifacts } from "./artifacts.js";
|
|
27
27
|
import { artifactPathMissHint, nullProjectionHint, partialPathMissHint, projectJsonPath, projectJsonPathFanout, projectResultExtract } from "./path-projection.js";
|
|
28
28
|
import { basename, join, resolve } from "node:path";
|
|
29
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
29
30
|
import { buildToolRegistry } from "./tools.js";
|
|
30
31
|
import { acquireWriteLock, writeLockHeldFace } from "./write-lock.js";
|
|
31
32
|
import { cmdCompute } from "./compute.js";
|
|
@@ -43,20 +44,22 @@ if (process.argv.includes("--utf8"))
|
|
|
43
44
|
else if (process.env.OMC_ASCII_STDOUT !== "0" && process.argv.some((arg) => arg === "--help" || arg === "help")) {
|
|
44
45
|
process.env.OMC_UTF8_HINT = "1";
|
|
45
46
|
}
|
|
46
|
-
import {
|
|
47
|
+
import { SEARCH_MARGIN_THRESHOLD } from "./tool-search.js";
|
|
48
|
+
import { commandCapabilitySlice, commandIndex, commandInventory, describeContract, describeContractFull, describeContractTool, describeExample, describeParam, describeSchemaOnly, describeTool, describeToolFull, filterTools } from "./discovery.js";
|
|
47
49
|
import { closestMatches } from "./closest-match.js";
|
|
48
50
|
import { KEY_ALIAS_HINTS, inputAliasSynonymKeys } from "./tool-types.js";
|
|
49
51
|
import { repeatFullDescribe } from "./describe-cache.js";
|
|
50
|
-
import { buildCapabilityOverview, capabilityDetail, capabilityRouteIndex, compactCapabilities, executableCapabilityBundle, resolveCapabilityId, DISCOVERY_AUTHORITY } from "./capability-overview.js";
|
|
52
|
+
import { buildCapabilityOverview, capabilityCandidatesFor, capabilityDetail, capabilityRouteIndex, compactCapabilities, executableCapabilityBundle, resolveCapabilityId, DISCOVERY_AUTHORITY } from "./capability-overview.js";
|
|
51
53
|
import { goalRoute } from "./goal-routes.js";
|
|
52
54
|
import { absencePointer } from "./capability-absences.js";
|
|
53
55
|
import { intentConfigRoot, readIntentFile, validateIntentText } from "./intent/cli.js";
|
|
56
|
+
import { planGoal, planToNdjson, planToNdjsonSkipped } from "./goal-plan.js";
|
|
54
57
|
import { intentSchemaBlock, intentExample, intentExampleIds } from "./intent/schema.js";
|
|
55
58
|
import { planIntent, readbackIntent, applyIntent, intentWarnings } from "./intent/plan-apply.js";
|
|
56
59
|
import { listSkills, readSkill, readSkillOutline, readSkillSection, searchSkills, suggestHelpTopics } from "./skills.js";
|
|
57
60
|
import { parseToolInput, ToolInputError } from "./tool-types.js";
|
|
58
61
|
import { WireError, wireCall } from "./wire.js";
|
|
59
|
-
import { DEFAULT_PULL_CONCURRENCY,
|
|
62
|
+
import { DEFAULT_PULL_CONCURRENCY, GraphIndexAmbiguousError, GraphIndexError, GraphIndexUnreadableError, GraphPullLockHeldError, MAX_PULL_CONCURRENCY, graphDbPath, graphRoot, impactGraph, listGraphIndexes, publishGraphPull, queryGraphReferences, queryGraphReferencesBatch, queryGraphEdges, readGraphStatus, searchGraphRules, } from "./graph.js";
|
|
60
63
|
import { cmdResidue } from "./residue.js";
|
|
61
64
|
import { cmdTrack } from "./track.js";
|
|
62
65
|
import { ENDPOINTS } from "./endpoints.js";
|
|
@@ -1275,12 +1278,26 @@ function cmdDiscovery(kind, transport, value, options = {}) {
|
|
|
1275
1278
|
return emitTransportResult({ status: "ok", ...intentSchemaBlock() }, transport);
|
|
1276
1279
|
}
|
|
1277
1280
|
if (kind === "commands") {
|
|
1281
|
+
// r59 M2-1: one capability family as a bounded tool index. Resolved before
|
|
1282
|
+
// the scoped check so `--capability` never falls through to the full
|
|
1283
|
+
// catalogue; `--capability` and `--lane/--filter` are mutually exclusive.
|
|
1284
|
+
if (options.capability !== undefined) {
|
|
1285
|
+
if (options.filter !== undefined || options.lane !== undefined) {
|
|
1286
|
+
return emitInvalid(transport, { message: "--capability 与 --filter/--lane 互斥:先按能力取工具名,再用 --filter 在结果里找,或直接 --capability <id>" });
|
|
1287
|
+
}
|
|
1288
|
+
const slice = commandCapabilitySlice(registry, options.capability);
|
|
1289
|
+
if (!slice) {
|
|
1290
|
+
const available = capabilityRouteIndex(registry).routes.map((route) => route.id).join("、");
|
|
1291
|
+
return emitInvalid(transport, { message: `未知 capability "${options.capability}";合法取值:${available}(清单见 omc capabilities)` });
|
|
1292
|
+
}
|
|
1293
|
+
return emitProjectedResult({ status: "ok", ...slice }, transport, options.jq);
|
|
1294
|
+
}
|
|
1278
1295
|
const scoped = options.filter !== undefined || options.lane !== undefined;
|
|
1279
1296
|
// Bare `commands` is the bounded index (see commandIndex): the full 54 KB
|
|
1280
1297
|
// catalogue must be requested with `commands --json` (round-9 heavy-task: an
|
|
1281
1298
|
// agent paid 4×54 KB on the default face before any hint could land).
|
|
1282
1299
|
if (options.json !== true && options.compact !== true && !scoped) {
|
|
1283
|
-
result = commandIndex(registry);
|
|
1300
|
+
result = commandIndex(registry, { legacy: legacyDiscovery() });
|
|
1284
1301
|
return emitProjectedResult({ status: "ok", ...result }, transport, options.jq);
|
|
1285
1302
|
}
|
|
1286
1303
|
const inventory = commandInventory(registry, { compact: options.compact === true });
|
|
@@ -1303,7 +1320,11 @@ function cmdDiscovery(kind, transport, value, options = {}) {
|
|
|
1303
1320
|
// r19 ticket 05: semantic filter — capability language(聚合/字典/业务集成)
|
|
1304
1321
|
// must locate tools, not dead-end on a name-substring miss.
|
|
1305
1322
|
const semantic = options.filter !== undefined ? filterTools(registry, options.filter) : undefined;
|
|
1306
|
-
|
|
1323
|
+
// r59 v3: keep the multi-signal score. It used to be dropped here
|
|
1324
|
+
// (`hit.via` only), so grouping fell back to tool COUNT and 「报表」
|
|
1325
|
+
// listed app.delete first.
|
|
1326
|
+
const semanticByName = semantic ? new Map(semantic.map((hit) => [hit.name, hit])) : undefined;
|
|
1327
|
+
const scoreOf = (name) => semanticByName?.get(name)?.score ?? Number.NEGATIVE_INFINITY;
|
|
1307
1328
|
const matched = tools.filter((tool) => {
|
|
1308
1329
|
if (options.lane !== undefined && tool.lane !== options.lane)
|
|
1309
1330
|
return false;
|
|
@@ -1311,11 +1332,26 @@ function cmdDiscovery(kind, transport, value, options = {}) {
|
|
|
1311
1332
|
return true;
|
|
1312
1333
|
return semanticByName.has(String(tool.name));
|
|
1313
1334
|
});
|
|
1335
|
+
// Rows follow match quality (score desc, then name), so the first row is
|
|
1336
|
+
// the best answer, not registry order. Only when a FILTER supplied scores
|
|
1337
|
+
// — `--lane` alone keeps registry order (the golden master pins that shape).
|
|
1338
|
+
if (semanticByName !== undefined) {
|
|
1339
|
+
matched.sort((left, right) => scoreOf(String(right.name)) - scoreOf(String(left.name)) || String(left.name).localeCompare(String(right.name)));
|
|
1340
|
+
}
|
|
1314
1341
|
inventory.filtered = { filter: options.filter ?? null, lane: options.lane ?? null, matched: matched.length, total: tools.length };
|
|
1342
|
+
// r59 v3 (margin): when the head of the ranking is a near-tie, say so —
|
|
1343
|
+
// the caller should weigh top options (or ask) instead of trusting top1.
|
|
1344
|
+
// 评审 P1-1:margin/top 必须基于 **lane 过滤后** 的排名——`--filter 加字段 --lane b2`
|
|
1345
|
+
// 时全局 top1/2 都在别的 lane,拿全局算会把单结果误标 ambiguous、把别的 lane
|
|
1346
|
+
// 的工具列进 top。
|
|
1347
|
+
const scoped = semantic === undefined ? [] : semantic.filter((hit) => matched.some((tool) => String(tool.name) === hit.name));
|
|
1348
|
+
if (scoped.length >= 2 && scoped[0].score - scoped[1].score < SEARCH_MARGIN_THRESHOLD) {
|
|
1349
|
+
inventory.filtered.ambiguous = true;
|
|
1350
|
+
}
|
|
1315
1351
|
inventory.tools = matched;
|
|
1316
1352
|
if (semanticByName !== undefined)
|
|
1317
1353
|
for (const tool of inventory.tools)
|
|
1318
|
-
tool.matchedVia = semanticByName.get(String(tool.name));
|
|
1354
|
+
tool.matchedVia = semanticByName.get(String(tool.name))?.via;
|
|
1319
1355
|
// A filtered query wants tool rows, not the whole catalogue's discovery,
|
|
1320
1356
|
// skills, and intent prose. Keep only the authoritative route pointer.
|
|
1321
1357
|
delete inventory.skills;
|
|
@@ -1328,8 +1364,11 @@ function cmdDiscovery(kind, transport, value, options = {}) {
|
|
|
1328
1364
|
// match plus governance prose pushed the agent back to the 20 KB face).
|
|
1329
1365
|
if (matched.length === 0 && semantic !== undefined) {
|
|
1330
1366
|
delete inventory.governance;
|
|
1331
|
-
|
|
1332
|
-
|
|
1367
|
+
// r59 Step 1: candidates are CAPABILITIES, not tool names. The old
|
|
1368
|
+
// closest match over tool names answered an unmet business ask with
|
|
1369
|
+
// app.create/app.delete/app.list — names that share no intent with it.
|
|
1370
|
+
inventory.filtered.candidates = capabilityCandidatesFor(registry, options.filter ?? "", 3);
|
|
1371
|
+
inventory.note = "零命中:没有能力短语匹配这个问法;候选是能力(不是工具名),先按 id 展开该能力的工具,或换能力词(如 聚合/子表/字典/报表/业务集成/定时任务),或 omc next \"<目标>\" 按任务路由;全量目录仍走 commands --json";
|
|
1333
1372
|
}
|
|
1334
1373
|
else if (matched.length > BROAD_FILTER_TOOL_THRESHOLD && !isCapabilityIdQuery(registry, options.filter ?? "")) {
|
|
1335
1374
|
// A broad word("数据" 39 hits / 8 KB)is half a catalogue: keep every
|
|
@@ -1341,15 +1380,25 @@ function cmdDiscovery(kind, transport, value, options = {}) {
|
|
|
1341
1380
|
const groups = new Map();
|
|
1342
1381
|
for (const tool of matched) {
|
|
1343
1382
|
const key = String(tool.capability ?? tool.lane ?? "other");
|
|
1344
|
-
|
|
1383
|
+
// `matched` is already score-ordered, so a group's tool list inherits it.
|
|
1384
|
+
const entry = groups.get(key) ?? { capability: key, lane: tool.lane ?? null, tools: [], score: Number.NEGATIVE_INFINITY };
|
|
1385
|
+
entry.score = Math.max(entry.score, scoreOf(String(tool.name)));
|
|
1345
1386
|
entry.tools.push(String(tool.name));
|
|
1346
1387
|
groups.set(key, entry);
|
|
1347
1388
|
}
|
|
1348
1389
|
inventory.filtered.matchedAll = matched.length;
|
|
1349
1390
|
inventory.filtered.grouped = true;
|
|
1391
|
+
// r59 v3: grouped mode hides rows, so name the head of the ranking —
|
|
1392
|
+
// an intent query like 「配审批流」 still gets its best tools up front.
|
|
1393
|
+
inventory.filtered.top = scoped.slice(0, 3).map((hit) => hit.name);
|
|
1350
1394
|
inventory.tools = [];
|
|
1351
|
-
|
|
1352
|
-
|
|
1395
|
+
// r59: order groups by their BEST match, not by tool count — a 6-tool
|
|
1396
|
+
// `workflow` group used to outrank the 5-tool `field` group that
|
|
1397
|
+
// actually matched the word. Count is only a tie-break.
|
|
1398
|
+
inventory.groups = [...groups.values()]
|
|
1399
|
+
.sort((left, right) => right.score - left.score || right.tools.length - left.tools.length || left.capability.localeCompare(right.capability))
|
|
1400
|
+
.map(({ score: _score, ...group }) => group);
|
|
1401
|
+
inventory.note = `命中 ${matched.length} 个工具(宽词):已按能力分组只列名字(top3 已单列);加更具体的词或 --lane <lane> 取完整行(含 requiredArgs/recipes)`;
|
|
1353
1402
|
}
|
|
1354
1403
|
}
|
|
1355
1404
|
result = inventory;
|
|
@@ -1396,7 +1445,7 @@ function cmdDiscovery(kind, transport, value, options = {}) {
|
|
|
1396
1445
|
}
|
|
1397
1446
|
}
|
|
1398
1447
|
else {
|
|
1399
|
-
result = describeTool(registry, value ?? "");
|
|
1448
|
+
result = describeTool(registry, value ?? "", { legacy: legacyDiscovery() });
|
|
1400
1449
|
// r28b 账本(2026-10-28):describe rule.save×11 / form.publish×9——firstCall 教学后
|
|
1401
1450
|
// 仍反复全量 describe。同参数近期已 ok 时附降载提示,引导 --param/--example 精准取。
|
|
1402
1451
|
// 无项目 ledger(golden/repo 测试/一次性运行)时 priorIdenticalSuccess 返回
|
|
@@ -1463,15 +1512,137 @@ function cmdNext(goal, transport) {
|
|
|
1463
1512
|
const result = goalRoute(buildToolRegistry(), goal);
|
|
1464
1513
|
return emitTransportResult(result, transport);
|
|
1465
1514
|
}
|
|
1515
|
+
/**
|
|
1516
|
+
* r59 M3 — `omc plan "<目标>" --env <env>`.
|
|
1517
|
+
*
|
|
1518
|
+
* Read-only by construction: this handler only runs the probes `planGoal` asks
|
|
1519
|
+
* for (`model.list` today), and `planGoal` never emits a write step when a probe
|
|
1520
|
+
* is uncertain. `--ndjson` deliberately breaks the single-envelope contract the
|
|
1521
|
+
* same way `omc script` does (it produces the input that command consumes);
|
|
1522
|
+
* every other shape stays one envelope.
|
|
1523
|
+
*/
|
|
1524
|
+
async function cmdPlan(goal, options, transport) {
|
|
1525
|
+
// r60c-F4(真机复现):`call`/`doctor` 都能从 .omc-env 自解环境,唯独 plan 缺
|
|
1526
|
+
// --env 直接报错——同项目内一次纯粹的错误往返。缺省时按**项目绑定面**解析
|
|
1527
|
+
// (OMC_ENV > cwd 的 .omc-env);刻意不落全局 default——plan 会解析平台 id,
|
|
1528
|
+
// 对错环境规划比多问一次 --env 更糟(沙盒纪律是 .omc-env 作用域)。
|
|
1529
|
+
let environmentSource;
|
|
1530
|
+
let environment;
|
|
1531
|
+
if (options.env === undefined || options.env.trim() === "") {
|
|
1532
|
+
const bound = process.env.OMC_ENV?.trim() || (() => {
|
|
1533
|
+
try {
|
|
1534
|
+
const path = defaultPaths().projectEnvPath;
|
|
1535
|
+
return existsSync(path) ? readFileSync(path, "utf8").trim() : "";
|
|
1536
|
+
}
|
|
1537
|
+
catch {
|
|
1538
|
+
return "";
|
|
1539
|
+
}
|
|
1540
|
+
})();
|
|
1541
|
+
if (!bound) {
|
|
1542
|
+
return emitInvalid(transport, {
|
|
1543
|
+
message: "`omc plan` 必须指定 --env <环境>:规划要读平台解析 schemaCode/字段 code,没有环境只能给路线(那正是 omc next)。本目录没有可用的 .omc-env/OMC_ENV 绑定(刻意不落全局 default——对错环境规划更糟)。离线形状用 --env <env> --offline(零 wire)",
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
environment = bound;
|
|
1547
|
+
environmentSource = process.env.OMC_ENV ? "OMC_ENV" : ".omc-env";
|
|
1548
|
+
// 与 call 同一道治理:显式名过 known/scope 校验(unknown environment 在这里
|
|
1549
|
+
// 就拒,而不是等探针阶段回 uncertain)。
|
|
1550
|
+
try {
|
|
1551
|
+
new ConfigStore(defaultPaths()).resolveEnvironment(bound);
|
|
1552
|
+
}
|
|
1553
|
+
catch (error) {
|
|
1554
|
+
return emitInvalid(transport, { message: error instanceof Error ? error.message : String(error) });
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
else {
|
|
1558
|
+
environment = options.env;
|
|
1559
|
+
}
|
|
1560
|
+
if (options.planOut !== undefined) {
|
|
1561
|
+
try {
|
|
1562
|
+
assertSafeOutputPath(intentConfigRoot(), options.planOut, "plan output file");
|
|
1563
|
+
}
|
|
1564
|
+
catch (error) {
|
|
1565
|
+
return emitInvalid(transport, { message: error instanceof Error ? error.message : String(error) });
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
let target;
|
|
1569
|
+
if (options.recipe !== undefined) {
|
|
1570
|
+
const [toolName, recipeId, ...rest] = options.recipe.split("/");
|
|
1571
|
+
if (toolName === undefined || recipeId === undefined || rest.length > 0) {
|
|
1572
|
+
return emitInvalid(transport, { message: "--recipe 的形状是 <tool>/<recipe>(如 field.create/field-serial-number);配方 id 见 omc describe <tool>" });
|
|
1573
|
+
}
|
|
1574
|
+
target = { tool: toolName, recipe: recipeId };
|
|
1575
|
+
}
|
|
1576
|
+
const plan = await planGoal(buildToolRegistry(), goal, {
|
|
1577
|
+
environment,
|
|
1578
|
+
...(target !== undefined ? { target } : {}),
|
|
1579
|
+
...(options.offline === true ? { offline: true } : {}),
|
|
1580
|
+
...(options.offline === true
|
|
1581
|
+
? {}
|
|
1582
|
+
: {
|
|
1583
|
+
probe: async (tool, args) => {
|
|
1584
|
+
// Lazy import: the registry→session stack is heavy and only the probe
|
|
1585
|
+
// path needs it (offline planning must stay instant).
|
|
1586
|
+
const { runToolCall } = await import("./call.js");
|
|
1587
|
+
const outcome = await runToolCall(tool, { args, environment, print: () => { } });
|
|
1588
|
+
const status = String(outcome.result.status ?? "");
|
|
1589
|
+
const ok = outcome.exitCode === 0 && status !== "uncertain" && status !== "error" && status !== "refused";
|
|
1590
|
+
return {
|
|
1591
|
+
ok,
|
|
1592
|
+
result: outcome.result,
|
|
1593
|
+
...(ok ? {} : { error: String(outcome.result.blocker ?? outcome.result.message ?? status) }),
|
|
1594
|
+
};
|
|
1595
|
+
},
|
|
1596
|
+
}),
|
|
1597
|
+
});
|
|
1598
|
+
if (options.planOut !== undefined) {
|
|
1599
|
+
const path = assertSafeOutputPath(intentConfigRoot(), options.planOut, "plan output file");
|
|
1600
|
+
writeFileSync(path, `${JSON.stringify(plan, null, 2)}\n`, { mode: 0o600 });
|
|
1601
|
+
}
|
|
1602
|
+
if (options.ndjson === true) {
|
|
1603
|
+
const lines = planToNdjson(plan);
|
|
1604
|
+
// M4-5: steps that need an earlier step's readback cannot be expressed in
|
|
1605
|
+
// NDJSON (the script runner does no variable interpolation). Name them on
|
|
1606
|
+
// stderr — silently dropping steps is how a chain looks complete but isn't.
|
|
1607
|
+
const skipped = planToNdjsonSkipped(plan);
|
|
1608
|
+
if (skipped.length > 0) {
|
|
1609
|
+
process.stderr.write(`plan: ${skipped.length} 步未进 NDJSON(NDJSON 不做变量插值):\n`);
|
|
1610
|
+
for (const entry of skipped)
|
|
1611
|
+
process.stderr.write(` ${entry.id} ${entry.tool} — ${entry.reason}\n`);
|
|
1612
|
+
process.stderr.write("先把这些步骤按 plan 的 dependsOn 手工串起来,或用 --plan-out 交给编排器\n");
|
|
1613
|
+
}
|
|
1614
|
+
if (lines.length === 0) {
|
|
1615
|
+
// Nothing executable: say why on stderr and keep stdout empty for the
|
|
1616
|
+
// consumer (a `jq`-less pipe must not receive a prose paragraph).
|
|
1617
|
+
process.stderr.write(`plan: 0 个可执行步骤(level=${plan.level} ready=${String(plan.ready)});见 --plan-out 或去掉 --ndjson 看结构化阻塞\n`);
|
|
1618
|
+
return plan.ready ? 0 : CLI_EXIT_CODES.invalidInput;
|
|
1619
|
+
}
|
|
1620
|
+
for (const line of lines)
|
|
1621
|
+
console.log(line);
|
|
1622
|
+
return 0;
|
|
1623
|
+
}
|
|
1624
|
+
return emitResult({ ...plan, ...(environmentSource !== undefined ? { environmentSource } : {}) }, transport);
|
|
1625
|
+
}
|
|
1466
1626
|
/**
|
|
1467
1627
|
* Ticket 125 — `omc capabilities` / `omc capability <id>`: the Configuration
|
|
1468
1628
|
* capability overview. Read-only, zero environment contact; a projection of
|
|
1469
1629
|
* the tool registry, the coverage manifest, and the intent capability registry.
|
|
1470
1630
|
*/
|
|
1471
|
-
function cmdCapabilities(transport,
|
|
1472
|
-
const result = compactCapabilities(buildToolRegistry(), {
|
|
1631
|
+
function cmdCapabilities(transport, options = {}, jq) {
|
|
1632
|
+
const result = compactCapabilities(buildToolRegistry(), { ...options, legacy: legacyDiscovery() });
|
|
1473
1633
|
return emitProjectedResult({ status: "ok", ...result }, transport, jq);
|
|
1474
1634
|
}
|
|
1635
|
+
/**
|
|
1636
|
+
* `OMC_LEGACY_DISCOVERY=1` — the 0.6.48 rollback switch (EXECUTION-PLAN §十).
|
|
1637
|
+
*
|
|
1638
|
+
* It restores the pre-M2 default faces byte-for-byte: bare `commands` with all
|
|
1639
|
+
* rows, `capabilities` with the full projection, and the wide `describe`. The
|
|
1640
|
+
* explicit flags (`--json`, `--full`, `--capability`) are unaffected — only the
|
|
1641
|
+
* defaults move, so a caller that names what it wants never sees a difference.
|
|
1642
|
+
*/
|
|
1643
|
+
function legacyDiscovery() {
|
|
1644
|
+
return process.env.OMC_LEGACY_DISCOVERY === "1";
|
|
1645
|
+
}
|
|
1475
1646
|
function cmdCapability(id, transport, executable = false, jq) {
|
|
1476
1647
|
const registry = buildToolRegistry();
|
|
1477
1648
|
const resolved = resolveCapabilityId(id);
|
|
@@ -1675,9 +1846,12 @@ async function cmdGraphPull(environment, concurrency, transport, path, applicati
|
|
|
1675
1846
|
...(data.gaps.length > 0 ? { gaps: { count: data.gaps.length, byKind: gapsByKind } } : {}),
|
|
1676
1847
|
dbBytes: data.dbBytes,
|
|
1677
1848
|
timings: data.timings,
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1849
|
+
// One project can hold several environment indexes: the file name IS the
|
|
1850
|
+
// environment, so echo both the target file and the owning project root.
|
|
1851
|
+
dbPath: graphDbPath(path, data.meta.environmentName),
|
|
1852
|
+
projectPath: graphRoot(path),
|
|
1853
|
+
mcpHint: `MCP 面:注册一次 --path ${graphRoot(path)},再用 env 参数(或 omc_graph_projects 列可用索引)选环境;多项目时把各自的 --path 都注册上。`,
|
|
1854
|
+
nextCommand: `omc graph references <kind> <code> --env ${data.meta.environmentName}`,
|
|
1681
1855
|
}, transport);
|
|
1682
1856
|
}
|
|
1683
1857
|
catch (error) {
|
|
@@ -1688,15 +1862,26 @@ async function cmdGraphPull(environment, concurrency, transport, path, applicati
|
|
|
1688
1862
|
return emitThrown(error, transport);
|
|
1689
1863
|
}
|
|
1690
1864
|
}
|
|
1691
|
-
|
|
1865
|
+
/** Shared refusal for "the index cannot answer": absent and ambiguous are different facts. */
|
|
1866
|
+
function graphIndexRefusal(error, selector, transport) {
|
|
1867
|
+
const ambiguous = error instanceof GraphIndexAmbiguousError;
|
|
1868
|
+
const unreadable = error instanceof GraphIndexUnreadableError;
|
|
1869
|
+
const pathHint = selector.root ? `--path ${selector.root}` : "";
|
|
1870
|
+
return emitResult({
|
|
1871
|
+
status: "refused",
|
|
1872
|
+
blocker: ambiguous ? "graph-index-ambiguous" : unreadable ? "graph-index-unreadable" : "graph-index-absent",
|
|
1873
|
+
message: `${error.message}${ambiguous ? "" : " 只读清点(不写索引):omc graph indexes;MCP 面读的可能是另一个项目根,比对 dbId/projectPath。"}`,
|
|
1874
|
+
...(selector.env ? { environment: selector.env } : {}),
|
|
1875
|
+
nextCommand: ambiguous ? `omc graph indexes ${pathHint}`.trim() : `omc graph pull --env ${selector.env ?? "<env>"} ${pathHint}`.trim(),
|
|
1876
|
+
}, transport);
|
|
1877
|
+
}
|
|
1878
|
+
function cmdGraphReferences(kind, code, transport, selector = {}) {
|
|
1692
1879
|
if (kind !== undefined && !["service", "model", "field"].includes(kind))
|
|
1693
1880
|
return emitInvalid(transport, { message: "kind 必须是 service / model / field" });
|
|
1694
1881
|
try {
|
|
1695
1882
|
const kinds = kind === undefined ? ["service", "model", "field"] : [kind];
|
|
1696
|
-
const results = kinds.map((one) => queryGraphReferences(one, code));
|
|
1883
|
+
const results = kinds.map((one) => queryGraphReferences(one, code, selector));
|
|
1697
1884
|
const result = results[0];
|
|
1698
|
-
if (requestedEnvironment !== undefined && requestedEnvironment !== result.index.environmentName)
|
|
1699
|
-
return emitResult({ status: "refused", blocker: "graph-environment-mismatch", message: `索引已绑定环境 ${result.index.environmentName},不是 ${requestedEnvironment};请先 omc graph pull --env ${requestedEnvironment}`, index: result.index }, transport);
|
|
1700
1885
|
if (kind === undefined)
|
|
1701
1886
|
return emitResult({ status: "ok", code, index: result.index, references: Object.fromEntries(results.map((item) => [item.kind, { matches: item.matches, ...(item.coverage !== undefined ? { coverage: item.coverage } : {}), ...(item.note !== undefined ? { note: item.note } : {}) }])) }, transport);
|
|
1702
1887
|
return emitResult({
|
|
@@ -1717,23 +1902,25 @@ function cmdGraphReferences(kind, code, transport, requestedEnvironment) {
|
|
|
1717
1902
|
}, transport);
|
|
1718
1903
|
}
|
|
1719
1904
|
catch (error) {
|
|
1720
|
-
if (error instanceof
|
|
1721
|
-
return
|
|
1905
|
+
if (error instanceof GraphIndexError)
|
|
1906
|
+
return graphIndexRefusal(error, selector, transport);
|
|
1722
1907
|
return emitThrown(error, transport);
|
|
1723
1908
|
}
|
|
1724
1909
|
}
|
|
1725
|
-
function cmdGraphReferencesBatch(kind, codeList, transport) {
|
|
1910
|
+
function cmdGraphReferencesBatch(kind, codeList, transport, selector = {}) {
|
|
1726
1911
|
if (!["service", "model", "field"].includes(kind))
|
|
1727
1912
|
return emitInvalid(transport, { message: "kind 必须是 service / model / field" });
|
|
1728
1913
|
try {
|
|
1729
|
-
const result = queryGraphReferencesBatch(kind, codeList.split(",").map((code) => code.trim()));
|
|
1914
|
+
const result = queryGraphReferencesBatch(kind, codeList.split(",").map((code) => code.trim()), selector);
|
|
1730
1915
|
return emitResult({ status: "ok", ...result }, transport);
|
|
1731
1916
|
}
|
|
1732
1917
|
catch (error) {
|
|
1918
|
+
if (error instanceof GraphIndexError)
|
|
1919
|
+
return graphIndexRefusal(error, selector, transport);
|
|
1733
1920
|
return emitThrown(error, transport);
|
|
1734
1921
|
}
|
|
1735
1922
|
}
|
|
1736
|
-
function cmdGraphEdges(fromSchema, toSchema, kind, offset, limit,
|
|
1923
|
+
function cmdGraphEdges(fromSchema, toSchema, kind, offset, limit, transport, selector = {}) {
|
|
1737
1924
|
try {
|
|
1738
1925
|
if (kind !== undefined && !["service", "model", "field"].includes(kind))
|
|
1739
1926
|
return emitInvalid(transport, { message: "kind 必须是 service / model / field" });
|
|
@@ -1741,52 +1928,67 @@ function cmdGraphEdges(fromSchema, toSchema, kind, offset, limit, requestedEnvir
|
|
|
1741
1928
|
const pageLimit = limit ?? 50;
|
|
1742
1929
|
if (!Number.isSafeInteger(pageOffset) || pageOffset < 0 || !Number.isSafeInteger(pageLimit) || pageLimit < 1)
|
|
1743
1930
|
return emitInvalid(transport, { message: "offset 必须是非负整数,limit 必须是正整数" });
|
|
1744
|
-
const result = queryGraphEdges(fromSchema, toSchema, kind, pageOffset, pageLimit);
|
|
1745
|
-
if (requestedEnvironment !== undefined && requestedEnvironment !== result.index.environmentName)
|
|
1746
|
-
return emitResult({ status: "refused", blocker: "graph-environment-mismatch", message: `索引已绑定环境 ${result.index.environmentName},不是 ${requestedEnvironment};请先 omc graph pull --env ${requestedEnvironment}`, index: result.index }, transport);
|
|
1931
|
+
const result = queryGraphEdges(fromSchema, toSchema, kind, pageOffset, pageLimit, selector);
|
|
1747
1932
|
return emitResult({ status: "ok", ...result }, transport);
|
|
1748
1933
|
}
|
|
1749
1934
|
catch (error) {
|
|
1935
|
+
if (error instanceof GraphIndexError)
|
|
1936
|
+
return graphIndexRefusal(error, selector, transport);
|
|
1750
1937
|
return emitThrown(error, transport);
|
|
1751
1938
|
}
|
|
1752
1939
|
}
|
|
1753
|
-
function cmdGraphStatus(
|
|
1940
|
+
function cmdGraphStatus(transport, selector = {}) {
|
|
1754
1941
|
try {
|
|
1755
|
-
const status = readGraphStatus();
|
|
1756
|
-
if (requestedEnvironment !== undefined && requestedEnvironment !== status.index.environmentName)
|
|
1757
|
-
return emitResult({ status: "refused", blocker: "graph-environment-mismatch", message: `索引已绑定环境 ${status.index.environmentName},不是 ${requestedEnvironment}`, index: status.index }, transport);
|
|
1942
|
+
const status = readGraphStatus(selector);
|
|
1758
1943
|
// r31a-F16:这里是**第四个**白名单式重建(前三次:compact() 投影、references
|
|
1759
1944
|
// 覆盖声明、mcp-graph 的 explore)。白名单每漏一个键就等于没修,且不会被任何
|
|
1760
1945
|
// 单测发现——所以改成展开,新增字段自动透传。
|
|
1761
1946
|
return emitResult({ status: "ok", ...status }, transport);
|
|
1762
1947
|
}
|
|
1763
1948
|
catch (error) {
|
|
1764
|
-
if (error instanceof
|
|
1765
|
-
return
|
|
1949
|
+
if (error instanceof GraphIndexError)
|
|
1950
|
+
return graphIndexRefusal(error, selector, transport);
|
|
1766
1951
|
return emitThrown(error, transport);
|
|
1767
1952
|
}
|
|
1768
1953
|
}
|
|
1769
|
-
function cmdGraphImpact(kind, code, transport) {
|
|
1954
|
+
function cmdGraphImpact(kind, code, transport, selector = {}) {
|
|
1770
1955
|
if (!["service", "model", "field"].includes(kind))
|
|
1771
1956
|
return emitInvalid(transport, { message: "kind 必须是 service / model / field(同 rule.references 第一版边界)" });
|
|
1772
1957
|
try {
|
|
1773
|
-
const result = impactGraph(kind, code);
|
|
1958
|
+
const result = impactGraph(kind, code, selector);
|
|
1774
1959
|
return emitResult({ status: "ok", ...result }, transport);
|
|
1775
1960
|
}
|
|
1776
1961
|
catch (error) {
|
|
1777
|
-
if (error instanceof
|
|
1778
|
-
return
|
|
1962
|
+
if (error instanceof GraphIndexError)
|
|
1963
|
+
return graphIndexRefusal(error, selector, transport);
|
|
1779
1964
|
return emitThrown(error, transport);
|
|
1780
1965
|
}
|
|
1781
1966
|
}
|
|
1782
|
-
function cmdGraphSearch(term, transport) {
|
|
1967
|
+
function cmdGraphSearch(term, transport, selector = {}) {
|
|
1783
1968
|
try {
|
|
1784
|
-
const result = searchGraphRules(term);
|
|
1969
|
+
const result = searchGraphRules(term, 20, 0, selector);
|
|
1785
1970
|
return emitResult({ status: "ok", ...result }, transport);
|
|
1786
1971
|
}
|
|
1787
1972
|
catch (error) {
|
|
1788
|
-
if (error instanceof
|
|
1789
|
-
return
|
|
1973
|
+
if (error instanceof GraphIndexError)
|
|
1974
|
+
return graphIndexRefusal(error, selector, transport);
|
|
1975
|
+
return emitThrown(error, transport);
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
/** `omc graph indexes` — every local index under one project root (read-only). */
|
|
1979
|
+
function cmdGraphIndexes(path, transport) {
|
|
1980
|
+
try {
|
|
1981
|
+
const indexes = listGraphIndexes(path);
|
|
1982
|
+
return emitResult({
|
|
1983
|
+
status: "ok",
|
|
1984
|
+
projectPath: graphRoot(path),
|
|
1985
|
+
count: indexes.length,
|
|
1986
|
+
indexes,
|
|
1987
|
+
...(indexes.length === 0 ? { nextCommand: `omc graph pull --path ${graphRoot(path)} --env <env>` } : {}),
|
|
1988
|
+
...(indexes.length > 1 ? { note: "该项目根下有多份索引(多环境):读命令必须用 --env 指定;MCP 面用 env 参数。" } : {}),
|
|
1989
|
+
}, transport);
|
|
1990
|
+
}
|
|
1991
|
+
catch (error) {
|
|
1790
1992
|
return emitThrown(error, transport);
|
|
1791
1993
|
}
|
|
1792
1994
|
}
|
|
@@ -2092,7 +2294,7 @@ function onboardingHelp() {
|
|
|
2092
2294
|
// 结果三次都是全量,还去 describe 找 dedupe 参数(多花 3 轮)。读面确实不做跨调用
|
|
2093
2295
|
// 结果去重——**明说**比留白强,省掉一次探索。
|
|
2094
2296
|
"读面不做跨调用结果去重:同一读面同参数连跑 N 次就是 N 次真实读(不会回 unchanged,也没有 dedupe 开关)。要省就 --jq 定向取值或把结果落到自己的变量里复用;`unchanged:true` 只出现在写面回读缓存那一条路径。",
|
|
2095
|
-
"工具发现:omc commands --
|
|
2297
|
+
"工具发现:omc commands(路由索引)→ omc commands --capability <id>(工具名+brief+recipe)→ omc describe <tool>(参数/必填/firstCall)→ --example/--full;omc commands --json 是全量目录(回退面)。能力面:omc capabilities(id+工具数)· omc capabilities --full(id/lane/aliases/tools/依赖顺序)· omc capability <id> --executable(单能力完整执行包)。应用参数矩阵:omc help app-scope。",
|
|
2096
2298
|
"单工具/契约:omc describe <tool>(schema+recipe+能力路由)· omc contract <lane>(wire 契约+能力路由);环境就绪:omc call discover_environment --env <env> --args '{}'。",
|
|
2097
2299
|
"写入两道门:对话层草稿确认(omc help omc-config-draft-review)+ 环境 writable 开关;生产环境每笔写需在 args 里带 confirmProduction:true。",
|
|
2098
2300
|
].join("\n");
|
|
@@ -2132,6 +2334,8 @@ function joinSplitFlagValues(raw, flags) {
|
|
|
2132
2334
|
}
|
|
2133
2335
|
return out;
|
|
2134
2336
|
}
|
|
2337
|
+
/** r60b-F7:最近一次 commander 帮助输出(configureOutput 的写通道暂存)。 */
|
|
2338
|
+
let lastHelpChunk = "";
|
|
2135
2339
|
async function main() {
|
|
2136
2340
|
let commandExitCode = 0;
|
|
2137
2341
|
// stderr is the diagnostics stream: apply the same Windows code-page policy
|
|
@@ -2139,6 +2343,13 @@ async function main() {
|
|
|
2139
2343
|
installCodePageSafeStderr();
|
|
2140
2344
|
beginUsage(argv);
|
|
2141
2345
|
const command = new Command();
|
|
2346
|
+
// r60b-F7:helpDisplayed 不区分「根帮助」与「子命令帮助」——两者都走同一个
|
|
2347
|
+
// exitOverride 回调。暂存**累计**帮助输出(addHelpText 的 after 块晚于主帮助
|
|
2348
|
+
// 块单独写出,覆盖式暂存会把含 Usage 行的主块冲掉),用 Usage 行区分:
|
|
2349
|
+
// 子命令帮助的 Usage 是 `omc <子命令> …`,根帮助是 `omc [options] [command]`。
|
|
2350
|
+
const stashHelp = (text) => {
|
|
2351
|
+
lastHelpChunk = (lastHelpChunk + text).slice(-8000);
|
|
2352
|
+
};
|
|
2142
2353
|
const ownPackageVersion = () => {
|
|
2143
2354
|
try {
|
|
2144
2355
|
// ESM 下读自身包根的 package.json(安装形态与源码形态都成立)
|
|
@@ -2157,7 +2368,7 @@ async function main() {
|
|
|
2157
2368
|
return CLI_EXIT_CODES.invalidInput;
|
|
2158
2369
|
}
|
|
2159
2370
|
command.exitOverride();
|
|
2160
|
-
command.configureOutput({ writeOut: (text) => process.stderr.write(text), writeErr: (text) => process.stderr.write(text) });
|
|
2371
|
+
command.configureOutput({ writeOut: (text) => { stashHelp(text); process.stderr.write(text); }, writeErr: (text) => { stashHelp(text); process.stderr.write(text); } });
|
|
2161
2372
|
command.name("omc").showHelpAfterError().showSuggestionAfterError(true);
|
|
2162
2373
|
// --version 短路:commander 的 version 走 process.exit,会被 exitOverride 包成
|
|
2163
2374
|
// invalid-input 信封(exit 10);cpdocs --omc-global 的探测要干净的 exit 0。
|
|
@@ -2614,20 +2825,26 @@ async function main() {
|
|
|
2614
2825
|
command.command("residue <prefix>").description("跨面前缀残留扫描(model 全租户/folder/custompage;默认 deep 再查命中模型的 rule/datarule/onlinejs)——收尾「删净」一次证明,clean:true 即零残留。清理入口:omc model-purge --code <schemaCode>(按依赖倒序,默认 dry-run)。只读零写入;report 面暂停维护未扫描").option("--env <environment>", "环境名(默认按 cwd 的 .omc-env 解析)").option("--apps <codes>", "all(默认,全租户)或逗号分隔应用码").option("--no-deep", "只扫 model/folder/custompage,不深查命中模型").option("--all-faces", "列出全部应用×面(含 count:0;默认只回非零面+byFace/userResidues 紧凑形)").option("--max-output-bytes <bytes>").addOption(new Option("--jq [path]", "--jq 不是 jq,仅路径选择器(与 call --jq 同 DSL;可逗号多路径;裸 --jq 列顶层键)").argParser((value, previous = []) => [...previous, value]).default([])).action(async (prefix, options) => { commandExitCode = await withTransport(options, request, (transport) => cmdResidue(prefix, { env: options.env, apps: options.apps, ...(options.deep === false ? { noDeep: true } : {}), ...(options.allFaces ? { allFaces: true } : {}), ...(options.jq !== undefined ? { jq: options.jq } : {}) }, transport)); });
|
|
2615
2826
|
command.command("track <schemaCode> <bizObjectId>").description("读取单条业务数据的行级变更留痕(只读;平台来源枚举含 BUSINESS_RULE 时原样回传)").option("--env <environment>").option("--property-code <code>").option("--max-output-bytes <bytes>").action(async (schemaCode, bizObjectId, options) => { commandExitCode = await withTransport(options, request, (transport) => cmdTrack(schemaCode, bizObjectId, { env: options.env, propertyCode: options.propertyCode }, transport)); });
|
|
2616
2827
|
const jqOption = () => new Option("--jq [path]", "--jq 不是 jq,仅路径选择器(与 call --jq 同 DSL;可逗号多路径;裸 --jq 列顶层键)").argParser((value, previous = []) => [...previous, value]).default([]);
|
|
2617
|
-
command.command("commands").option("--json").option("--compact").option("--filter <keyword>").option("--lane <id>").option("--max-output-bytes <bytes>").addOption(jqOption()).action(async (options) => { commandExitCode = await withTransport(options, request, (transport) => cmdDiscovery("commands", transport, undefined, { json: options.json === true, compact: options.compact === true, ...(options.filter ? { filter: options.filter } : {}), ...(options.lane ? { lane: options.lane } : {}), ...(options.jq !== undefined ? { jq: options.jq } : {}) })); });
|
|
2828
|
+
command.command("commands").option("--json").option("--compact").option("--filter <keyword>").option("--capability <id>").option("--lane <id>").option("--max-output-bytes <bytes>").addOption(jqOption()).action(async (options) => { commandExitCode = await withTransport(options, request, (transport) => cmdDiscovery("commands", transport, undefined, { json: options.json === true, compact: options.compact === true, ...(options.filter ? { filter: options.filter } : {}), ...(options.capability ? { capability: options.capability } : {}), ...(options.lane ? { lane: options.lane } : {}), ...(options.jq !== undefined ? { jq: options.jq } : {}) })); });
|
|
2618
2829
|
command.command("describe <tool>").option("--full").option("--cache-ok", "允许 --full 在同会话重复读时短路为 artifact 指针(默认每次回全文)").option("--schema-only").option("--param <name>").option("--example [id]").option("--max-output-bytes <bytes>").addOption(jqOption()).action(async (tool, options) => {
|
|
2619
2830
|
commandExitCode = await withTransport(options, request, (transport) => cmdDiscovery("describe", transport, tool, { full: options.full === true, cacheOk: options.cacheOk === true, schemaOnly: options.schemaOnly === true, ...(options.param ? { param: options.param } : {}), ...(options.example ? { example: options.example } : {}), ...(options.jq !== undefined ? { jq: options.jq } : {}) }));
|
|
2620
2831
|
});
|
|
2621
2832
|
command.command("contract <lane>").option("--full").option("--tool <name>").option("--max-output-bytes <bytes>").addOption(jqOption()).action(async (lane, options) => { commandExitCode = await withTransport(options, request, (transport) => cmdDiscovery("contract", transport, lane, { full: options.full === true, ...(options.tool ? { tool: options.tool } : {}), ...(options.jq !== undefined ? { jq: options.jq } : {}) })); });
|
|
2622
2833
|
// 2026-11-05 用户实测:`commands --json` 存在,于是大家自然写 `capabilities --json`
|
|
2623
2834
|
// ——旧实现报 `unknown option`(退出码 10)。输出本来就是 JSON 信封,接受它做兼容别名。
|
|
2624
|
-
command.command("capabilities").option("--compact").option("--json", "兼容别名:输出本就是 JSON 信封(与 commands --json 对齐)").option("--max-output-bytes <bytes>").addOption(jqOption()).action(async (options) => { commandExitCode = await withTransport(options, request, (transport) => cmdCapabilities(transport, options.compact === true, options.jq)); });
|
|
2835
|
+
command.command("capabilities").option("--compact").option("--full", "完整投影(id/标题/别名/工具/依赖)——默认只是能力索引").option("--json", "兼容别名:输出本就是 JSON 信封(与 commands --json 对齐)").option("--max-output-bytes <bytes>").addOption(jqOption()).action(async (options) => { commandExitCode = await withTransport(options, request, (transport) => cmdCapabilities(transport, { compact: options.compact === true, full: options.full === true }, options.jq)); });
|
|
2625
2836
|
// `--env` is accepted but ignored: `next` is a zero-environment-contact route
|
|
2626
2837
|
// solver, and a caller who reflexively passes `--env` should not be refused
|
|
2627
2838
|
// (round 15 dogfood: `next "<goal>" --env local` → unknown option, one round).
|
|
2628
2839
|
command.command("next <goal>").option("--env <environment>").option("--max-output-bytes <bytes>").action(async (goal, options) => {
|
|
2629
2840
|
commandExitCode = await withTransport(options, request, (transport) => cmdNext(goal, transport));
|
|
2630
2841
|
});
|
|
2842
|
+
// r59 M3 — `omc plan "<目标>" --env <env>`: READ-ONLY probing + a compiled plan.
|
|
2843
|
+
// Distinct from `next` (a route) and from `omc intent plan` (a declarative file):
|
|
2844
|
+
// this answers "what exactly would I run, and what is still missing?".
|
|
2845
|
+
command.command("plan <goal>").option("--env <environment>").option("--environment <environment>").option("--offline", "不接触环境:只报告需要哪些探测(Level 3 形状),零 wire").option("--ndjson", "把可执行步骤按 omc script 的 NDJSON 逐行输出(stdout 因此不是单信封,与 omc script 同类)").option("--recipe <tool/recipe>", "直接规划指定配方(跳过路由),如 field.create/field-serial-number").option("--plan-out <file>", "把完整 plan JSON 写到配置根内文件(供复核/重放)").option("--max-output-bytes <bytes>").addHelpText("after", "\n只读规划:搜索→配方→解析平台 id→本地 schema 校验→ready/missing/ambiguities/blockers。\n`ready=true` 要求:无未解析参数、无歧义、无待设计载荷、每步过 schema、探测无 uncertain。\n探测失败(uncertain)时**不生成任何写步骤**。\n整包需求走 Level 5(指 intent plan),不是原子 call 链。\n").action(async (goal, options) => {
|
|
2846
|
+
commandExitCode = await withTransport(options, request, (transport) => cmdPlan(goal, { env: options.environment ?? options.env, offline: options.offline === true, ndjson: options.ndjson === true, planOut: options.planOut, recipe: options.recipe }, transport));
|
|
2847
|
+
});
|
|
2631
2848
|
command.command("usage").option("--records").option("--top <n>").option("--max-output-bytes <bytes>").addHelpText("after", "\n用量账本(.omc/usage.jsonl):默认只回汇总(调用数/字节/重复浪费/按工具 Top N);--records 才回原始记录。\n").action(async (options) => {
|
|
2632
2849
|
const parsedTop = options.top === undefined ? undefined : Number.parseInt(String(options.top), 10);
|
|
2633
2850
|
commandExitCode = await withTransport(options, request, (transport) => cmdUsage(transport, {
|
|
@@ -2685,7 +2902,12 @@ async function main() {
|
|
|
2685
2902
|
const codes = options.applicationCodes ? String(options.applicationCodes).split(",").map((code) => code.trim()).filter(Boolean) : undefined;
|
|
2686
2903
|
commandExitCode = await withTransport(options, request, (transport) => cmdGraphPull(options.environment ?? options.env, parsed, transport, options.path, codes, options.allApplications === true));
|
|
2687
2904
|
});
|
|
2688
|
-
|
|
2905
|
+
// Read-side selection is symmetric with `pull` (2026-11-13): every offline
|
|
2906
|
+
// subcommand takes --path (which project root) and --env (which environment's
|
|
2907
|
+
// index). One project can hold several environment indexes, and one
|
|
2908
|
+
// environment can be indexed by several projects — the pair is the identity.
|
|
2909
|
+
const withIndexSelector = (options) => ({ root: options.path, env: (options.environment ?? options.env) });
|
|
2910
|
+
graphCommand.command("references [kind] [code]").option("--batch <codes>").option("--env <environment>", "选哪一份索引(同项目可有多环境);省略则要求该项目根下只有一份").option("--path <dir>", "项目根目录(定位 <dir>/.omc/graph/<env>.db)").option("--max-output-bytes <bytes>").addHelpText("after", "\n离线查询(零 wire):省略 kind 时=service|model|field 三类全查;支持 --batch code1,code2(例如 --batch svc_a,svc_b)。\n").action(async (kind, code, options) => {
|
|
2689
2911
|
// r42b 接线(2026-11-08,r42a-F8):commander 把首个位置参数绑给 [kind],
|
|
2690
2912
|
// 「references <code>」这种最自然写法会把 code 当 kind 拒掉,而
|
|
2691
2913
|
// cmdGraphReferences 的三类全查分支只认 kind===undefined——help 承诺的
|
|
@@ -2697,22 +2919,28 @@ async function main() {
|
|
|
2697
2919
|
boundKind = undefined;
|
|
2698
2920
|
boundCode = kind;
|
|
2699
2921
|
}
|
|
2700
|
-
|
|
2922
|
+
const selector = withIndexSelector(options);
|
|
2923
|
+
commandExitCode = await withTransport(options, request, (transport) => options.batch ? cmdGraphReferencesBatch(boundKind ?? "model", options.batch, transport, selector) : cmdGraphReferences(boundKind, boundCode ?? "", transport, selector));
|
|
2924
|
+
});
|
|
2925
|
+
graphCommand.command("references-batch <kind> <code>").option("--env <environment>").option("--path <dir>").option("--max-output-bytes <bytes>").action(async (kind, code, options) => {
|
|
2926
|
+
commandExitCode = await withTransport(options, request, (transport) => cmdGraphReferencesBatch(kind, code, transport, withIndexSelector(options)));
|
|
2701
2927
|
});
|
|
2702
|
-
graphCommand.command("
|
|
2703
|
-
commandExitCode = await withTransport(options, request, (transport) =>
|
|
2928
|
+
graphCommand.command("edges").option("--env <environment>", "选哪一份索引;省略则要求该项目根下只有一份").option("--path <dir>", "项目根目录").option("--from-schema <code>").option("--to-schema <code>").option("--kind <kind>").option("--offset <n>").option("--limit <n>").option("--max-output-bytes <bytes>").addHelpText("after", "\n离线全图边清单(零 wire);支持 --kind model|field|service 与 --offset/--limit 分页。\n").action(async (options) => {
|
|
2929
|
+
commandExitCode = await withTransport(options, request, (transport) => cmdGraphEdges(options.fromSchema, options.toSchema, options.kind, options.offset === undefined ? undefined : Number(options.offset), options.limit === undefined ? undefined : Number(options.limit), transport, withIndexSelector(options)));
|
|
2704
2930
|
});
|
|
2705
|
-
graphCommand.command("
|
|
2706
|
-
commandExitCode = await withTransport(options, request, (transport) =>
|
|
2931
|
+
graphCommand.command("impact <kind> <code>").option("--env <environment>").option("--path <dir>").option("--max-output-bytes <bytes>").addHelpText("after", "\n影响面(离线):跳1=引用该编码的规则(同 references),跳2=这些规则还读写哪些 service/model/field——改前看爆炸半径。截断上限 50 规则×每类 20 码。\n").action(async (kind, code, options) => {
|
|
2932
|
+
commandExitCode = await withTransport(options, request, (transport) => cmdGraphImpact(kind, code, transport, withIndexSelector(options)));
|
|
2707
2933
|
});
|
|
2708
|
-
graphCommand.command("
|
|
2709
|
-
commandExitCode = await withTransport(options, request, (transport) =>
|
|
2934
|
+
graphCommand.command("search <term...>").option("--env <environment>").option("--path <dir>").option("--max-output-bytes <bytes>").addHelpText("after", "\n检索规则的 code+name(FTS5,末词前缀匹配;**不含规则体/配置内容**)。找到\"关于 X 的规则\"拿 code,再走 references/impact。中文必须是全词或词首通配(如 报名* / 增加预算*)——子串不命中:FTS5 把「增加预算」当一个 token,搜「预算」为 0。\n").action(async (term, options) => {
|
|
2935
|
+
commandExitCode = await withTransport(options, request, (transport) => cmdGraphSearch(term.join(" "), transport, withIndexSelector(options)));
|
|
2710
2936
|
});
|
|
2711
|
-
graphCommand.command("
|
|
2712
|
-
commandExitCode = await withTransport(options, request, (transport) =>
|
|
2937
|
+
graphCommand.command("status").option("--env <environment>", "选哪一份索引;省略则要求该项目根下只有一份").option("--environment <environment>").option("--path <dir>", "项目根目录").option("--max-output-bytes <bytes>").action(async (options) => {
|
|
2938
|
+
commandExitCode = await withTransport(options, request, (transport) => cmdGraphStatus(transport, withIndexSelector(options)));
|
|
2713
2939
|
});
|
|
2714
|
-
|
|
2715
|
-
|
|
2940
|
+
// Which indexes exist here? The discovery face for multi-project /
|
|
2941
|
+
// multi-environment setups (CLI twin of the MCP `omc_graph_projects`).
|
|
2942
|
+
graphCommand.command("indexes").option("--path <dir>", "项目根目录(省略=当前配置根)").option("--max-output-bytes <bytes>").addHelpText("after", "\n只读清点:列出该根下所有 <env>.db(环境名/项目路径/新鲜度/规模)。多环境或多项目时先用它决定 --env。\n").action(async (options) => {
|
|
2943
|
+
commandExitCode = await withTransport(options, request, (transport) => cmdGraphIndexes(options.path, transport));
|
|
2716
2944
|
});
|
|
2717
2945
|
// MCP stdio server (host registration: cpdocs installer's omc-graph entry;
|
|
2718
2946
|
// top-level verb like `codegraph serve --mcp`, not a graph subcommand).
|
|
@@ -2720,8 +2948,9 @@ async function main() {
|
|
|
2720
2948
|
// may reach stdout from here; envelopes/banners never do.
|
|
2721
2949
|
command
|
|
2722
2950
|
.command("mcp-graph", { hidden: true })
|
|
2723
|
-
.description("以 MCP stdio 服务器运行规则图检索(工具:omc_graph_explore / omc_graph_status)")
|
|
2724
|
-
|
|
2951
|
+
.description("以 MCP stdio 服务器运行规则图检索(工具:omc_graph_projects / omc_graph_explore / omc_graph_status)")
|
|
2952
|
+
// Repeatable: one server can serve every project on the machine.
|
|
2953
|
+
.option("--path <dir>", "项目根目录,可重复(定位 <dir>/.omc/graph/<env>.db;MCP 注册时传绝对路径,不信任宿主 cwd)。注册一处工作区根即可覆盖其一级子项目", (value, previous = []) => [...previous, value], [])
|
|
2725
2954
|
.action(async (options) => {
|
|
2726
2955
|
const { runMcpGraphServer } = await import("./mcp-graph.js");
|
|
2727
2956
|
commandExitCode = await runMcpGraphServer(options.path);
|
|
@@ -2771,7 +3000,34 @@ main().then((code) => {
|
|
|
2771
3000
|
}, (error) => {
|
|
2772
3001
|
// commander prints `--help` / `-h` usage to stderr and signals success with
|
|
2773
3002
|
// this code; it is not an error and must not grow a spurious error envelope.
|
|
2774
|
-
|
|
3003
|
+
// `commander.help`(commander 14):showHelpAfterError 的错误上下文路径——
|
|
3004
|
+
// 未知命令 + `--help` 时 unknownCommand 错误被帮助输出替换成这个 code,
|
|
3005
|
+
// 原有 unknownCommand 分支因此永远接不到(r60b-F7 真机)。
|
|
3006
|
+
if (error instanceof CommanderError && (error.code === "commander.helpDisplayed" || error.code === "commander.help")) {
|
|
3007
|
+
// r60b-F7(真机复现):`omc configure_workflow --help` 里 commander 先短路
|
|
3008
|
+
// --help、后校验子命令,未知命令吃到了根帮助 + exit 0——探针一度以为
|
|
3009
|
+
// 命令存在只是参数没显示。根帮助(Usage: omc [options] [command])+ 非
|
|
3010
|
+
// help 的位置参数 = 未知命令;子命令帮助(Usage: omc <子命令>)正常 exit 0。
|
|
3011
|
+
const usageLine = (/^Usage:\s*omc[^\n]*/m.exec(lastHelpChunk) ?? [""])[0];
|
|
3012
|
+
const isRootHelp = /^Usage:\s*omc\s+\[options\]\s*\[command\]/.test(usageLine);
|
|
3013
|
+
const positional = argv.slice(2).filter((entry) => entry !== "--").find((entry) => !entry.startsWith("-"));
|
|
3014
|
+
if (isRootHelp && positional !== undefined && positional !== "help") {
|
|
3015
|
+
let isTool = false;
|
|
3016
|
+
try {
|
|
3017
|
+
isTool = buildToolRegistry().some((tool) => tool.name === positional);
|
|
3018
|
+
}
|
|
3019
|
+
catch {
|
|
3020
|
+
isTool = false;
|
|
3021
|
+
}
|
|
3022
|
+
const message = isTool
|
|
3023
|
+
? `未知顶层命令 "${positional}"——它是工具名不是 CLI 子命令:形状用 omc describe ${positional}(含可运行示例),执行用 omc call ${positional} --env <env> --args '<json>'(顶层命令见 omc help commands)`
|
|
3024
|
+
: `未知顶层命令 "${positional}"(顶层命令见 omc help commands;工具清单 omc commands;工具形状 omc describe <tool>)`;
|
|
3025
|
+
const parsed = errorEnvelope(new Error(message), "invalid-input", CLI_EXIT_CODES.invalidInput, request);
|
|
3026
|
+
writeEnvelope(parsed.envelope);
|
|
3027
|
+
completeUsage(parsed.exitCode);
|
|
3028
|
+
finish(parsed.exitCode);
|
|
3029
|
+
return;
|
|
3030
|
+
}
|
|
2775
3031
|
completeUsage(0);
|
|
2776
3032
|
finish(0);
|
|
2777
3033
|
return;
|