@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.
Files changed (51) hide show
  1. package/dist/capability-overview.js +114 -1
  2. package/dist/cli-stdout.js +3 -0
  3. package/dist/cli.js +318 -62
  4. package/dist/closest-match.js +22 -3
  5. package/dist/command-transport.js +5 -1
  6. package/dist/discovery.js +193 -75
  7. package/dist/goal-plan.js +1296 -0
  8. package/dist/goal-routes.js +87 -5
  9. package/dist/graph.js +223 -34
  10. package/dist/intent/capabilities/field.js +24 -0
  11. package/dist/intent/plan-apply.js +10 -3
  12. package/dist/intent/schema.js +24 -1
  13. package/dist/lanes/app.js +4 -0
  14. package/dist/lanes/apply-changes.js +1 -0
  15. package/dist/lanes/b2-registration.js +24 -0
  16. package/dist/lanes/businessrule.js +14 -0
  17. package/dist/lanes/custom-page.js +8 -0
  18. package/dist/lanes/datarule.js +4 -0
  19. package/dist/lanes/dictionary.js +13 -0
  20. package/dist/lanes/environment.js +2 -0
  21. package/dist/lanes/field.js +5 -0
  22. package/dist/lanes/folder.js +4 -0
  23. package/dist/lanes/form.js +5 -0
  24. package/dist/lanes/list-view-contract.js +1 -1
  25. package/dist/lanes/list-view.js +5 -0
  26. package/dist/lanes/meta.js +5 -0
  27. package/dist/lanes/model.js +9 -0
  28. package/dist/lanes/online-js.js +2 -0
  29. package/dist/lanes/organization.js +20 -0
  30. package/dist/lanes/perm.js +5 -5
  31. package/dist/lanes/programming.js +6 -0
  32. package/dist/lanes/report.js +9 -0
  33. package/dist/lanes/rule-lifecycle.js +6 -0
  34. package/dist/lanes/rulelog.js +1 -0
  35. package/dist/lanes/runtime-data.js +39 -1
  36. package/dist/lanes/workflow.js +18 -0
  37. package/dist/mcp-graph.js +180 -41
  38. package/dist/package-tool.js +1 -0
  39. package/dist/recipes/workflow.js +1 -1
  40. package/dist/search-index.js +137 -0
  41. package/dist/tool-search.js +647 -0
  42. package/dist/tool-types.js +6 -0
  43. package/dist/tools.js +1 -0
  44. package/dist/write.js +2 -1
  45. package/docs/omc-introduction.md +5 -7
  46. package/package.json +6 -5
  47. package/skills/omc-business-configuration.md +2 -1
  48. package/skills/omc-capabilities.md +4 -2
  49. package/skills/omc-start-here.md +21 -7
  50. package/skills/omc-tool-selection.md +7 -15
  51. package/skills/omc-write-hazards.md +1 -1
@@ -11,20 +11,39 @@ export function closestMatch(input, candidates) {
11
11
  const wanted = input.toUpperCase().replace(/[\s_-]/g, "");
12
12
  if (wanted.length < 2)
13
13
  return undefined;
14
+ // r60c-F6(真机复现):`contract_amount` 拼错时建议了 `contract_name`(比例距离
15
+ // 达标)而真目标是 `amount`——它是输入的**尾部 token**,三个接受形都不认。
16
+ // 加第四形:分隔符 token 相等(≥4 字符)按强信号计(距离 0),并补后缀包含。
17
+ // r60c-F6(真机复现):`contract_amount` 拼错时建议了 `contract_name`(比例距离
18
+ // 达标)而真目标是 `amount`——它是输入的**尾部 token**,三个接受形都不认。
19
+ // 加 token 覆盖形:候选的 token 全部被输入 token 解释(amount ⊆ contract_amount)
20
+ // 按强信号计(距离 0)。**只对 ≥2 个 token 的输入启用**——TEXT/DATETIME 这类
21
+ // 单 token 短输入的歧义语义(故意不猜、DATETIME→DATE 而非 TIME)保持不变。
22
+ const inputTokens = input.toUpperCase().split(/[\s_-]+/u).filter((token) => token.length >= 4);
23
+ const wantedTokens = new Set(inputTokens);
24
+ const multiTokenInput = inputTokens.length >= 2;
14
25
  let best;
15
26
  for (const name of candidates) {
16
27
  const candidate = name.toUpperCase().replace(/[\s_-]/g, "");
17
28
  // 1. prefix containment (STAFF→STAFF_SELECTOR, DATETIME→DATE)
18
29
  const contained = (candidate.startsWith(wanted) || wanted.startsWith(candidate)) && Math.min(wanted.length, candidate.length) >= 4;
30
+ // token 覆盖:候选的 token(≥4 字)全部出现在输入 token 里。部分命中
31
+ // (contract_name 只共享 CONTRACT)弱于全覆盖——平局会让先出现的候选赢。
32
+ const candidateTokens = name.toUpperCase().split(/[\s_-]+/u).filter((token) => token.length >= 4);
33
+ const matchedTokens = candidateTokens.filter((token) => wantedTokens.has(token));
34
+ const fullTokenCoverage = multiTokenInput && candidateTokens.length > 0 && matchedTokens.length === candidateTokens.length;
35
+ const partialTokenHit = multiTokenInput && matchedTokens.length > 0;
19
36
  // 2. small edit distance (NUMERIC→NUMERICAL, SHORTTEXT→SHORT_TEXT)
20
37
  const distance = editDistance(wanted, candidate);
21
38
  const nearMiss = distance <= 2;
22
39
  // 3. shared prefix + proportional distance (NUMBER→NUMERICAL, the live-measured case)
23
40
  const sharedPrefix = commonPrefixLength(wanted, candidate);
24
41
  const proportional = sharedPrefix >= 3 && wanted.length >= 5 && distance / Math.max(wanted.length, candidate.length) <= 0.58;
25
- const accepted = contained || nearMiss || proportional;
26
- if (accepted && (!best || distance < best.distance))
27
- best = { name, distance };
42
+ // 全 token 覆盖 0 < 部分 token 2 < 常规距离。
43
+ const effectiveDistance = fullTokenCoverage ? 0 : partialTokenHit ? 2 : distance;
44
+ const accepted = contained || fullTokenCoverage || partialTokenHit || nearMiss || proportional;
45
+ if (accepted && (!best || effectiveDistance < best.distance))
46
+ best = { name, distance: effectiveDistance };
28
47
  }
29
48
  return best?.name;
30
49
  }
@@ -125,7 +125,11 @@ function sanitizePaths(value) {
125
125
  // 脱成 [local-path-redacted] 后两面无法比对(探针正是靠比对 dbPath 才发现
126
126
  // 「MCP 读的是 ext-mcc 目录的旧库」);graph-index-absent 的拒绝消息也在叫用户
127
127
  // 「比对 dbId/dbPath」。仅豁免这一个键,其余路径照脱敏不放松。
128
- if (key === "dbPath" && typeof entry === "string") {
128
+ // 2026-11-13:projectPath 同理——多项目/多环境并存时,回执要靠它自证
129
+ // 「这是哪个项目的库」,脱敏后这条信息直接消失(MCP 面本就明文)。
130
+ // 按名豁免的含义:该字段名被约定为「graph 索引归属自证」专用;新命令
131
+ // 若要回显本地路径,走 dbPath/projectPath 之外的键(会被正常脱敏)。
132
+ if ((key === "dbPath" || key === "projectPath") && typeof entry === "string") {
129
133
  output[key] = entry;
130
134
  continue;
131
135
  }
package/dist/discovery.js CHANGED
@@ -6,7 +6,9 @@ import { z } from "zod";
6
6
  import { LANE_CONTRACTS } from "./contract-resources.js";
7
7
  import { intentCapabilityBlock } from "./intent/cli.js";
8
8
  import { listSkills } from "./skills.js";
9
- import { capabilityRouteForTool, capabilityRouteForLane, capabilityRouteIndex, DISCOVERY_AUTHORITY } from "./capability-overview.js";
9
+ import { capabilityRouteForTool, capabilityRouteForLane, capabilityRouteIndex, resolveCapabilityId, DISCOVERY_AUTHORITY } from "./capability-overview.js";
10
+ import { scoreTools } from "./tool-search.js";
11
+ export { toolSearchMetaReport } from "./tool-search.js";
10
12
  import { readShapeFor } from "./read-shapes.js";
11
13
  /**
12
14
  * `commands --json` — the tool catalogue.
@@ -89,69 +91,110 @@ export function commandInventory(registry, options = {}) {
89
91
  };
90
92
  }
91
93
  /**
92
- * r19 ticket 05 — semantic `commands --filter`.
94
+ * r59 v3 — semantic `commands --filter` (SEARCH-V3-PLAN).
93
95
  *
94
- * The old filter matched only `name + lane + capability id` substrings, so an
95
- * agent asking in capability language(「聚合」「字典」「业务集成」)got an
96
- * empty list plus the full governance prose and had to re-read the 20 KB
97
- * catalogue. The semantic face matches, in authority order: tool name →
98
- * capability aliases/title/id → recipe id/title/aliases → tool description,
99
- * with case and separator (`.`/`-`/`_`/space) normalization on both sides.
100
- * Deterministic: hits sort by matched-field authority, then name.
96
+ * History: r19 made the filter match capability language at all; v1 (r59) added
97
+ * controlled reverse matching but hung scenario phrases on EVERY tool of a
98
+ * capability, so one phrase matched 24 tools with identical rank — four
99
+ * different asks returned the same list. v2 was rejected in review (three P0s,
100
+ * all reproduced): empty-object queries degraded to "match everything", the
101
+ * derivable-rate was 46% not 86%, and a capability hard filter drops tools
102
+ * (「发布」 spans workflow/form/onlinejs).
103
+ *
104
+ * v3 scores ALL 168 tools every time (full recall, no hard filter), with
105
+ * capability reduced to a +6 prior. Object matching is a bonus, never a gate;
106
+ * read/delete intent alignment and the destructive penalty are mandatory; and
107
+ * negated clauses (「不要新建服务,只给已有服务加方法」) contribute no phrases.
108
+ * The scoring table lives in `tool-search.ts`(weights in one place, tuned
109
+ * against `scripts/run-search-eval.ts`).
101
110
  */
102
111
  export function filterTools(registry, query) {
103
- const rawQuery = query.trim().toLowerCase();
104
- if (rawQuery.length === 0)
105
- return [];
106
- const normalizedQuery = normalizeFaceText(query);
107
- const routeByLane = capabilityRouteIndex(registry).routeByLane;
108
- const hits = [];
109
- for (const tool of registry) {
110
- const capability = tool.lane ? routeByLane.get(tool.lane) : undefined;
111
- const fields = [
112
- { label: "工具名", text: tool.name },
113
- ...(capability ? [
114
- { label: `能力 ${capability.id} 别名`, text: capability.aliases.join(" ") },
115
- { label: `能力 ${capability.id} 标题`, text: capability.title },
116
- { label: "能力 id", text: capability.id },
117
- ] : []),
118
- ...(tool.executionMetadata?.recipes ?? []).flatMap((recipe) => [
119
- { label: `配方 ${recipe.id} 标题`, text: recipe.title },
120
- { label: "配方 id", text: recipe.id },
121
- { label: `配方 ${recipe.id} 别名`, text: (recipe.aliases ?? []).join(" ") },
122
- ]),
123
- { label: "工具摘要", text: tool.description },
124
- ];
125
- let via;
126
- let rank = 0;
127
- for (const field of fields) {
128
- const lower = field.text.toLowerCase();
129
- if (lower.includes(rawQuery) || normalizeFaceText(field.text).includes(normalizedQuery)) {
130
- via = `${field.label}含 "${query.trim()}"`;
131
- break;
132
- }
133
- rank += 1;
134
- }
135
- if (via !== undefined)
136
- hits.push({ name: tool.name, via, rank });
137
- }
138
- return hits.sort((left, right) => left.rank - right.rank || left.name.localeCompare(right.name)).map(({ name, via }) => ({ name, via }));
112
+ return scoreTools(registry, query).map(({ name, via, score }) => ({ name, via, score }));
139
113
  }
140
- function normalizeFaceText(text) {
141
- return text.toLowerCase().replace(/[._\s-]/g, "");
142
- }
143
- export function commandIndex(registry) {
114
+ export function commandIndex(registry, options = {}) {
144
115
  const byLane = new Map();
145
116
  for (const tool of registry) {
146
117
  const lane = tool.lane ?? "(unbound)";
147
118
  byLane.set(lane, (byLane.get(lane) ?? 0) + 1);
148
119
  }
120
+ const lanes = [...byLane.entries()].sort((left, right) => left[0].localeCompare(right[0]));
121
+ // `OMC_LEGACY_DISCOVERY=1` restores the pre-M2 face byte-for-byte (patch
122
+ // rollback for 0.6.48, removed in 0.6.50 — EXECUTION-PLAN §十).
123
+ if (options.legacy === true) {
124
+ return {
125
+ discovery: { authoritative: DISCOVERY_AUTHORITY.authoritative, route: DISCOVERY_AUTHORITY.route },
126
+ toolCount: registry.length,
127
+ lanes: lanes.map(([lane, tools]) => ({ lane, tools })),
128
+ tools: registry.map((tool) => ({ name: tool.name, lane: tool.lane ?? null, kind: tool.kind })),
129
+ hint: "裸 `commands` 是有界索引(name/lane/kind)。全量行用 `omc commands --json`;单能力用 `omc commands --json --compact --lane <lane>`;关键词用 `--filter <word>`;目标→路线优先 `omc next \"<目标>\"`。",
130
+ };
131
+ }
132
+ const routeCount = capabilityRouteIndex(registry).routes.length;
149
133
  return {
150
134
  discovery: { authoritative: DISCOVERY_AUTHORITY.authoritative, route: DISCOVERY_AUTHORITY.route },
151
135
  toolCount: registry.length,
152
- lanes: [...byLane.entries()].map(([lane, tools]) => ({ lane, tools })).sort((left, right) => left.lane.localeCompare(right.lane)),
153
- tools: registry.map((tool) => ({ name: tool.name, lane: tool.lane ?? null, kind: tool.kind })),
154
- hint: "裸 `commands` 是有界索引(name/lane/kind)。全量行用 `omc commands --json`;单能力用 `omc commands --json --compact --lane <lane>`;关键词用 `--filter <word>`;目标→路线优先 `omc next \"<目标>\"`。",
136
+ capabilityCount: routeCount,
137
+ // A single string, not 19 objects: the counts are all a router needs. One
138
+ // line per face used to be ~780 B of `{"lane":..,"tools":..}` overhead.
139
+ lanes: lanes.map(([lane, tools]) => `${lane}:${tools}`).join(" "),
140
+ expand: {
141
+ capability: "omc commands --capability <id>(工具名+brief+recipe id,~1–3KB)",
142
+ filter: "omc commands --filter <词>(语义检索)",
143
+ catalogue: "omc commands --json(全量目录 ~30KB)",
144
+ capabilities: "omc capabilities(能力索引)",
145
+ route: "omc next \"<目标>\"(目标→路线)",
146
+ },
147
+ hint: "裸 commands 是路由索引,不是目录:先按能力展开,别直接拉 --json。",
148
+ };
149
+ }
150
+ /**
151
+ * `omc commands --capability <id>` (r59 M2-1): one capability family, as a
152
+ * bounded tool index — name + one-line brief + recipe ids.
153
+ *
154
+ * Why this face exists: the old ladder was `commands --json --compact --lane
155
+ * <lane>` (3–22 KB) or `commands --json` (30 KB), because a capability id is not
156
+ * a lane and the caller had to know both. This slice resolves id/alias → route →
157
+ * lane → tools, so "which tools does 数据/流程/权限 have, and what do they do"
158
+ * costs ~1–3 KB instead of the catalogue.
159
+ */
160
+ export function commandCapabilitySlice(registry, capabilityId) {
161
+ const resolved = resolveCapabilityId(capabilityId);
162
+ const index = capabilityRouteIndex(registry);
163
+ const route = resolved === undefined ? undefined : index.routes.find((entry) => entry.id === resolved);
164
+ if (route === undefined)
165
+ return undefined;
166
+ const tools = registry.filter((tool) => (tool.lane ?? null) === route.lane);
167
+ // Briefs are the point of this face, but a 38-tool family would pay ~4 KB
168
+ // just for prose. Above this width the names+recipes still let the caller pick
169
+ // and `describe <tool>` is the one deliberate step for the rest.
170
+ const BRIEF_TOOL_LIMIT = 24;
171
+ const withBrief = tools.length <= BRIEF_TOOL_LIMIT;
172
+ return {
173
+ capability: {
174
+ id: route.id,
175
+ title: route.title,
176
+ lane: route.lane,
177
+ ...(route.aliases.length > 0 ? { aliases: route.aliases } : {}),
178
+ toolCount: tools.length,
179
+ ...(index.nodeById.get(route.id)?.intent.level !== undefined && index.nodeById.get(route.id)?.intent.level !== "none"
180
+ ? { intent: index.nodeById.get(route.id)?.intent.level }
181
+ : {}),
182
+ },
183
+ ...(withBrief ? {} : { briefsOmitted: `该能力族 ${tools.length} 个工具超过 ${BRIEF_TOOL_LIMIT},只列名字+recipe;单个用途用 omc describe <tool>` }),
184
+ tools: tools.map((tool) => {
185
+ const recipes = (tool.executionMetadata?.recipes ?? []).map((recipe) => recipe.id);
186
+ return {
187
+ name: tool.name,
188
+ kind: tool.kind,
189
+ ...(withBrief ? { brief: summarizeDescription(tool.description) } : {}),
190
+ ...(recipes.length > 0 ? { recipes } : {}),
191
+ };
192
+ }),
193
+ next: {
194
+ detail: "omc describe <tool>(参数/必填/firstCall)",
195
+ executable: `omc capability ${route.id} --executable`,
196
+ contract: `omc contract ${route.lane}`,
197
+ },
155
198
  };
156
199
  }
157
200
  const convertToJsonSchema = zodToJsonSchema;
@@ -449,54 +492,129 @@ const DATA_PARAMETER_NAMES = [
449
492
  { concept: "记录标识", parameters: "data.load / data.delete / data.submit = bizObjectId" },
450
493
  { concept: "流程三件套", parameters: "data.submit 专用:bizObjectId + workItemId + workflowInstanceId" },
451
494
  ];
452
- /** Default `omc describe`: the compact contract projection. */
453
- export function describeTool(registry, name) {
495
+ /**
496
+ * Default `omc describe`: the compact contract projection.
497
+ *
498
+ * r59 M2-4 — this face was 1.4 KB average and 4.4 KB worst (rule.save): the
499
+ * `firstCall` inlined a full recipe (nodeGraph included), `examples` repeated
500
+ * every recipe title, and `paramDocs.available` re-listed the param names the
501
+ * `params` map already carries. Median is now ~0.8 KB and the worst ~1.6 KB.
502
+ *
503
+ * What moved, not what vanished: recipe titles beyond four, the inlined
504
+ * `firstCall.args` above 260 B, per-placeholder `requiredValues` prose, and the
505
+ * `parameterNames` concepts are all reachable at `--example <id>` (1–2 KB, the
506
+ * authoritative runnable shape) or `--full`. `params` stays inline on purpose:
507
+ * a missing param NAME costs an invalid_input round, and the R2 gate says bytes
508
+ * must never be bought with rounds.
509
+ */
510
+ export function describeTool(registry, name, options = {}) {
454
511
  const tool = registry.find((entry) => entry.name === name);
455
512
  if (!tool)
456
513
  return undefined;
457
514
  const schema = jsonSchemaFor(tool.inputSchema);
458
515
  const { required, params } = compactParams(schema);
459
- const examples = exampleList(tool);
460
516
  const hasRecipe = (tool.executionMetadata?.recipes.length ?? 0) > 0;
461
517
  const firstCall = firstCallFor(tool);
518
+ if (options.legacy === true)
519
+ return legacyDescribeTool(tool, required, params, hasRecipe, firstCall);
520
+ const recipes = tool.executionMetadata?.recipes ?? [];
521
+ // Titles are how a caller picks among recipes; keep them while the list is
522
+ // short, because above that the title text alone is the payload.
523
+ const keepTitles = recipes.length > 0 && recipes.length <= 4;
524
+ const examples = recipes.length === 0
525
+ ? exampleList(tool)
526
+ : recipes.map((recipe) => ({
527
+ id: recipe.id,
528
+ ...(keepTitles ? { title: clampText(recipe.title, 16) } : {}),
529
+ ...(recipe.requiresEnvironmentDerivedIds ? { needsReadback: true } : {}),
530
+ }));
531
+ const compactFirstCall = firstCall === undefined ? undefined : leanFirstCall(firstCall);
462
532
  return {
463
533
  name: tool.name,
464
534
  lane: tool.lane ?? null,
465
535
  kind: tool.kind,
466
- summary: summarizeDescription(tool.description),
536
+ summary: clampText(summarizeDescription(tool.description), 110),
467
537
  required,
468
538
  params,
469
539
  examples,
470
- ...(firstCall !== undefined ? { firstCall } : {}),
471
- // Point cold callers at the cheap runnable face BEFORE they reach for
472
- // --full: a recipe is ~1–2 KB and a single --param is a few hundred bytes,
473
- // while --full is 5–20 KB. Benchmark (bench13): two --full calls were 34 KB
474
- // of a 133 KB task even though a matching recipe existed.
475
- ...(hasRecipe ? { exampleHint: `可运行参数用 --example <id>(~1–2KB);单参数用 --param <name>;仅当二者都缺形状才 --full` } : {}),
476
- ...(!hasRecipe ? { exampleHint: `无静态 recipe:required + params 已够常规调用;单参数说明用 --param <name>;仅当需要全部参数注释/拒绝形状才 --full(5–20KB)` } : {}),
477
- // 1.7 of issue 2026-10-23: the parameter DOC for `subFields` was only
478
- // reachable through --param/--full, i.e. discovering a param needed its
479
- // name first. Name the documented params inline (cheap: names only) so one
480
- // `describe` answers "does this tool take X, and what is X called".
481
- // r26b 读回体积审计(2026-11-05):提示原写「单个参数注释,几百字节」,而
482
- // `--param nodeGraph` 实测 **8773 B**(object 参数展开≈整份 --full)——照提示
483
- // 做反而更贵。现在点名哪些参数是大对象,并改指 --example。
484
- ...(documentedParamNames(tool).length > 0
485
- ? { paramDocs: { available: documentedParamNames(tool), read: largeParamDocsHint(tool) } }
486
- : {}),
540
+ ...(compactFirstCall !== undefined ? { firstCall: compactFirstCall } : {}),
541
+ // One hint instead of three overlapping ones (exampleHint + paramDocs.read +
542
+ // full). It names the cheaper face first, which is what the old prose was
543
+ // for: agents reached for --full even when --example/--param existed.
544
+ next: hasRecipe
545
+ ? "可运行参数 --example <id>(~1–2KB);单参数 --param <name>;全量注释/schema --full(5–20KB)"
546
+ : "单参数 --param <name>;全量注释/schema --full(5–20KB);required + params 已够常规调用",
487
547
  // T3(GitLab #17):封闭取值(schema 里没有 enum 的那些)在默认面内联一次,
488
548
  // 省掉「写错 → 报错 → 再写」的循环;报错里的 accepted* 仍是权威兜底。
489
549
  ...(tool.paramEnums !== undefined ? { paramEnums: tool.paramEnums } : {}),
550
+ // r53 D3 的真机摩擦契约,**不能**跟着 M2 一起搬到 --full:data.save 的载荷
551
+ // 叫 formData、data.load/delete/submit 叫 bizObjectId、submit 另需流程三件套
552
+ // ——分不清就写错参数,代价是一轮 invalid_input。302 B 换掉那一轮,符合
553
+ // 本轮「字节不得用回合换」的方向(test/r53-dataface-ergonomics D3 钉住)。
554
+ ...(tool.name.startsWith("data.") ? { parameterNames: DATA_PARAMETER_NAMES } : {}),
490
555
  // High-frequency read faces: declare the RESULT keys so `--jq` does not
491
556
  // have to learn them from a pathMiss. Zero bytes when undeclared.
492
557
  ...(returnsFace(tool.name) ?? {}),
493
558
  // r32 F1(真机):探针并发发两条 app.create,第二条回 write-lock-held。
494
559
  // 撞上之前没有任何发现面说过"写是环境级串行"——describe 的 params 里没有 wait
495
560
  // (它是 omc call 的 CLI 开关,不在工具 schema),capability notes 是空的。
561
+ ...(tool.kind === "write" ? { writeLock: "写锁=环境级串行:并发写后到的回 write-lock-held(不排队,勿 shell 重试);CLI 可 --wait <ms> 排队" } : {}),
562
+ };
563
+ }
564
+ /** Clamp to `limit` characters, ellipsis included — never cut mid-grapheme. */
565
+ function clampText(text, limit) {
566
+ return text.length <= limit ? text : `${text.slice(0, limit - 1)}…`;
567
+ }
568
+ /**
569
+ * The default `firstCall` keeps the decision-relevant facts — which recipe, can
570
+ * it run as-is, what is missing, where each missing id comes from — and defers
571
+ * the payload. Above 260 B the args are a recipe body, not a one-liner: inlining
572
+ * it makes `describe` as expensive as `--example`, which is why wide tools
573
+ * (rule.save: 1.6 KB of nodeGraph) were 4 KB.
574
+ */
575
+ function leanFirstCall(firstCall) {
576
+ const args = firstCall.args;
577
+ const argsBytes = args === undefined ? undefined : Buffer.byteLength(JSON.stringify(args), "utf8");
578
+ const missing = Array.isArray(firstCall.missing) ? firstCall.missing : [];
579
+ const values = {};
580
+ for (const key of missing) {
581
+ const source = PLACEHOLDER_SOURCES[key];
582
+ if (source === undefined)
583
+ continue;
584
+ // Only the tool name, not the prose: "schemaCode←model.list" answers "what
585
+ // do I run first" in 12 B, where the shipped sentence costs 45.
586
+ values[key] = source.replace(/^omc call /, "").replace(/(.*$/, "").replace(/^omc env.*$/, "omc env");
587
+ }
588
+ return {
589
+ recipeId: firstCall.recipeId,
590
+ ...(argsBytes !== undefined && argsBytes <= 260 ? { args } : {}),
591
+ ...(argsBytes !== undefined && argsBytes > 260 ? { argsBytes } : {}),
592
+ executable: firstCall.executable,
593
+ ...(missing.length > 0 ? { missing } : {}),
594
+ ...(Object.keys(values).length > 0 ? { values } : {}),
595
+ readMore: firstCall.readMore,
596
+ };
597
+ }
598
+ /** `OMC_LEGACY_DISCOVERY=1`: the pre-M2 default face, byte-for-byte. */
599
+ function legacyDescribeTool(tool, required, params, hasRecipe, firstCall) {
600
+ return {
601
+ name: tool.name,
602
+ lane: tool.lane ?? null,
603
+ kind: tool.kind,
604
+ summary: summarizeDescription(tool.description),
605
+ required,
606
+ params,
607
+ examples: exampleList(tool),
608
+ ...(firstCall !== undefined ? { firstCall } : {}),
609
+ ...(hasRecipe ? { exampleHint: `可运行参数用 --example <id>(~1–2KB);单参数用 --param <name>;仅当二者都缺形状才 --full` } : {}),
610
+ ...(!hasRecipe ? { exampleHint: `无静态 recipe:required + params 已够常规调用;单参数说明用 --param <name>;仅当需要全部参数注释/拒绝形状才 --full(5–20KB)` } : {}),
611
+ ...(documentedParamNames(tool).length > 0
612
+ ? { paramDocs: { available: documentedParamNames(tool), read: largeParamDocsHint(tool) } }
613
+ : {}),
614
+ ...(tool.paramEnums !== undefined ? { paramEnums: tool.paramEnums } : {}),
615
+ ...(returnsFace(tool.name) ?? {}),
496
616
  ...(tool.kind === "write" ? { writeLock: "写锁=环境级:同一环境的并发写,后到的直接回 write-lock-held(不排队)。可带 --wait <ms> 让 CLI 内部排队(CLI 开关,不是本工具参数);不要写 shell 重试循环" } : {}),
497
617
  ...(tool.name.startsWith("data.") ? { parameterNames: DATA_PARAMETER_NAMES } : {}),
498
- // Keep the cost salient at the decision point: agents reached for --full even
499
- // when --example/--param existed (sandbox22: 8 --full calls, one 19 KB).
500
618
  full: `omc describe ${tool.name} --full(5–20KB;先试 --example/--param)`,
501
619
  };
502
620
  }