dsh-harness-reflex 0.1.0 → 0.3.0
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/README.md +20 -6
- package/client.js +3511 -185
- package/dist/attribution.d.ts +266 -0
- package/dist/attribution.js +238 -0
- package/dist/attribution.js.map +1 -0
- package/dist/bridge.d.ts +311 -13
- package/dist/bridge.js +714 -42
- package/dist/bridge.js.map +1 -1
- package/dist/client-bundle.js +4 -1
- package/dist/client-bundle.js.map +1 -1
- package/dist/command.js +10 -0
- package/dist/command.js.map +1 -1
- package/dist/config.d.ts +530 -22
- package/dist/config.js +808 -27
- package/dist/config.js.map +1 -1
- package/dist/delegation-dispatch.d.ts +132 -0
- package/dist/delegation-dispatch.js +186 -0
- package/dist/delegation-dispatch.js.map +1 -0
- package/dist/delegation-health.d.ts +131 -0
- package/dist/delegation-health.js +97 -0
- package/dist/delegation-health.js.map +1 -0
- package/dist/delegation.d.ts +148 -0
- package/dist/delegation.js +186 -0
- package/dist/delegation.js.map +1 -0
- package/dist/effort-delegation.d.ts +144 -0
- package/dist/effort-delegation.js +280 -0
- package/dist/effort-delegation.js.map +1 -0
- package/dist/effort.d.ts +141 -0
- package/dist/effort.js +251 -9
- package/dist/effort.js.map +1 -1
- package/dist/host-patch.d.ts +156 -0
- package/dist/host-patch.js +534 -0
- package/dist/host-patch.js.map +1 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.js +99 -7
- package/dist/index.js.map +1 -1
- package/dist/interventions.d.ts +98 -373
- package/dist/interventions.js +442 -1702
- package/dist/interventions.js.map +1 -1
- package/dist/panel-api.d.ts +328 -4
- package/dist/panel-api.js +322 -15
- package/dist/panel-api.js.map +1 -1
- package/dist/panel-mount.d.ts +81 -22
- package/dist/panel-mount.js +228 -7
- package/dist/panel-mount.js.map +1 -1
- package/dist/routing.d.ts +23 -18
- package/dist/routing.js +471 -153
- package/dist/routing.js.map +1 -1
- package/dist/session-audit.d.ts +70 -0
- package/dist/session-audit.js +73 -0
- package/dist/session-audit.js.map +1 -1
- package/dist/systemone-probe.d.ts +114 -0
- package/dist/systemone-probe.js +383 -0
- package/dist/systemone-probe.js.map +1 -0
- package/dist/testing.d.ts +212 -7
- package/dist/testing.js +333 -27
- package/dist/testing.js.map +1 -1
- package/dist/tools.d.ts +109 -3
- package/dist/tools.js +103 -4
- package/dist/tools.js.map +1 -1
- package/dist/unconfigured-backend.d.ts +72 -0
- package/dist/unconfigured-backend.js +94 -0
- package/dist/unconfigured-backend.js.map +1 -0
- package/dist/vendor/harness-reflex/backend/factory.d.ts +31 -1
- package/dist/vendor/harness-reflex/backend/factory.js +18 -3
- package/dist/vendor/harness-reflex/backend/factory.js.map +1 -1
- package/dist/vendor/harness-reflex/backend/jev.d.ts +20 -0
- package/dist/vendor/harness-reflex/backend/jev.js +11 -4
- package/dist/vendor/harness-reflex/backend/jev.js.map +1 -1
- package/dist/vendor/harness-reflex/backend/simple-jev.d.ts +16 -0
- package/dist/vendor/harness-reflex/backend/simple-jev.js +17 -6
- package/dist/vendor/harness-reflex/backend/simple-jev.js.map +1 -1
- package/dist/vendor/harness-reflex/core/closing.d.ts +90 -0
- package/dist/vendor/harness-reflex/core/closing.js +111 -0
- package/dist/vendor/harness-reflex/core/closing.js.map +1 -0
- package/dist/vendor/harness-reflex/core/evidence.d.ts +119 -0
- package/dist/vendor/harness-reflex/core/evidence.js +209 -0
- package/dist/vendor/harness-reflex/core/evidence.js.map +1 -0
- package/dist/vendor/harness-reflex/core/judge.d.ts +221 -0
- package/dist/vendor/harness-reflex/core/judge.js +251 -0
- package/dist/vendor/harness-reflex/core/judge.js.map +1 -0
- package/dist/vendor/harness-reflex/core/orchestrate-closing.d.ts +237 -0
- package/dist/vendor/harness-reflex/core/orchestrate-closing.js +250 -0
- package/dist/vendor/harness-reflex/core/orchestrate-closing.js.map +1 -0
- package/dist/vendor/harness-reflex/core/orchestrate-correction.d.ts +209 -0
- package/dist/vendor/harness-reflex/core/orchestrate-correction.js +141 -0
- package/dist/vendor/harness-reflex/core/orchestrate-correction.js.map +1 -0
- package/dist/vendor/harness-reflex/core/orchestrate-host.d.ts +225 -0
- package/dist/vendor/harness-reflex/core/orchestrate-host.js +80 -0
- package/dist/vendor/harness-reflex/core/orchestrate-host.js.map +1 -0
- package/dist/vendor/harness-reflex/core/orchestrate-stagnation.d.ts +259 -0
- package/dist/vendor/harness-reflex/core/orchestrate-stagnation.js +270 -0
- package/dist/vendor/harness-reflex/core/orchestrate-stagnation.js.map +1 -0
- package/dist/vendor/harness-reflex/core/orchestrate.d.ts +357 -0
- package/dist/vendor/harness-reflex/core/orchestrate.js +418 -0
- package/dist/vendor/harness-reflex/core/orchestrate.js.map +1 -0
- package/dist/vendor/harness-reflex/core/policy.d.ts +122 -0
- package/dist/vendor/harness-reflex/core/policy.js +102 -0
- package/dist/vendor/harness-reflex/core/policy.js.map +1 -0
- package/dist/vendor/harness-reflex/core/prune-plan.d.ts +141 -0
- package/dist/vendor/harness-reflex/core/prune-plan.js +390 -0
- package/dist/vendor/harness-reflex/core/prune-plan.js.map +1 -0
- package/dist/vendor/harness-reflex/core/text.d.ts +36 -0
- package/dist/vendor/harness-reflex/core/text.js +66 -0
- package/dist/vendor/harness-reflex/core/text.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/audit.d.ts +18 -0
- package/dist/vendor/harness-reflex/ports/audit.js +11 -0
- package/dist/vendor/harness-reflex/ports/audit.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/clock.d.ts +14 -0
- package/dist/vendor/harness-reflex/ports/clock.js +11 -0
- package/dist/vendor/harness-reflex/ports/clock.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/decision.d.ts +75 -0
- package/dist/vendor/harness-reflex/ports/decision.js +2 -0
- package/dist/vendor/harness-reflex/ports/decision.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/index.d.ts +14 -0
- package/dist/vendor/harness-reflex/ports/index.js +2 -0
- package/dist/vendor/harness-reflex/ports/index.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/log.d.ts +22 -0
- package/dist/vendor/harness-reflex/ports/log.js +12 -0
- package/dist/vendor/harness-reflex/ports/log.js.map +1 -0
- package/dist/vendor/harness-reflex/ports/state.d.ts +46 -0
- package/dist/vendor/harness-reflex/ports/state.js +13 -0
- package/dist/vendor/harness-reflex/ports/state.js.map +1 -0
- package/package.json +25 -13
package/dist/command.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;GAWG;AAEH,wEAAwE;AACxE,MAAM,CAAC,MAAM,qBAAqB,GAAG,eAAe,CAAC;AAErD,yEAAyE;AACzE,MAAM,CAAC,MAAM,iCAAiC,GAAG,kBAAkB,CAAC;AAEpE,oDAAoD;AACpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAExC,2DAA2D;AAC3D,MAAM,gBAAgB,GAAG,UAAU,CAAC;AAYpC;;;;GAIG;AACH,SAAS,OAAO,CAAC,GAAW;IAC1B,MAAM,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;QAAE,OAAO,GAAG,CAAC;IAC3C,MAAM,GAAG,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACpE,OAAO,GAAG,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,EAAE,CAAC;AACjF,CAAC;AAED;;;;;GAKG;AACH,SAAS,SAAS,CAAC,SAAiB;IAClC,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAA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AAC;AACH,CAAC","sourcesContent":["import type { Context } from '@deepseek-ai/cordis';\nimport type { CommandResult } from '@deepseek-ai/dsh-commands';\n\nimport type { ReflexLedgerResult, ReflexRuntime } from './bridge.js';\nimport type { BackendHealth } from './vendor/harness-reflex/index.js';\n\n/**\n * The human command that reads this activation's decision ledger.\n *\n * The ledger used to be a `reflex_status_ledger` tool. It is not a decision the\n * model should have to spend a turn on — it is an audit question a person asks —\n * so it lives in the Host's command registry instead: `/reflex-ledger` answers\n * it without a model turn and without a slot on the tool surface. The capability\n * is unchanged: this is the same `runtime.statusLedger` read, formatted for a\n * person rather than for a model.\n *\n * @module dsh-reflex/command\n */\n\n/** Registered name of the ledger command, without the leading slash. */\nexport const REFLEX_LEDGER_COMMAND = 'reflex-ledger';\n\n/** Description the Host advertises for {@link REFLEX_LEDGER_COMMAND}. */\nexport const REFLEX_LEDGER_COMMAND_DESCRIPTION = '查看 Reflex 决策账本汇总';\n\n/** How many recent decisions the command prints. */\nexport const LEDGER_COMMAND_ENTRIES = 5;\n\n/** Name the context exposes the command registry under. */\nconst COMMANDS_SERVICE = 'commands';\n\n/** The slice of the registry this module uses. */\ninterface CommandRegistry {\n register(definition: { name: string; description: string; handler: () => CommandResult }): () => void;\n /** Resolve one definition, or `undefined` when the name is free. */\n find?(agent: undefined, name: string): unknown;\n}\n\n/** One audit entry, in the shape {@link ReflexRuntime.statusLedger} returns. */\ntype LedgerEntry = NonNullable<ReflexLedgerResult['recentEntries']>[number];\n\n/**\n * Format one instant from the ledger as local `HH:MM:SS`.\n * @param iso - the entry's ISO timestamp.\n * @returns the clock time, or the input when it is not a date.\n */\nfunction clockOf(iso: string): string {\n const at = new Date(iso);\n if (Number.isNaN(at.getTime())) return iso;\n const pad = (part: number): string => String(part).padStart(2, '0');\n return `${pad(at.getHours())}:${pad(at.getMinutes())}:${pad(at.getSeconds())}`;\n}\n\n/**\n * Format one latency, keeping a tenth of a millisecond when the backend reports\n * a fractional one.\n * @param latencyMs - measured latency.\n * @returns the human reading.\n */\nfunction latencyOf(latencyMs: number): string {\n return `${Number.isInteger(latencyMs) ? latencyMs : latencyMs.toFixed(1)} ms`;\n}\n\n/**\n * Render one entry as a single line: time, type, and the facts that entry owns.\n * @param entry - one ledger record.\n * @returns the line, without a trailing newline.\n */\nfunction entryLine(entry: LedgerEntry): string {\n const facts = [latencyOf(entry.latencyMs)];\n if (entry.tokensSaved) facts.push(`节省 ${entry.tokensSaved} token`);\n if (entry.type === 'gate') facts.push(entry.passed ? '通过' : '未通过');\n if (entry.type === 'stagnation') facts.push(entry.isStuck ? '判定停滞' : '未见停滞');\n if (entry.shadow) facts.push('shadow');\n if (entry.skipReason) facts.push(`跳过:${entry.skipReason}`);\n return `- ${clockOf(entry.timestamp)} ${entry.type} · ${facts.join(' · ')}`;\n}\n\n/**\n * Render the degraded-backend notice appended to the command reply, if any.\n *\n * The line is bilingual because the panel is, and it stays in the command text:\n * it is a fact for the person typing `/reflex-ledger`, never a message the agent\n * reads. A recovered backend returns `undefined`, so the notice disappears on\n * its own.\n * @param health - backend health at read time, when the backend tracks it.\n * @returns the notice line, or `undefined` when the backend is healthy.\n */\nexport function systemOneHealthLine(health: BackendHealth | undefined): string | undefined {\n if (health === undefined || health.available) return undefined;\n const reason = health.lastFailureReason ?? 'unknown error';\n const count = health.consecutiveFailures;\n const when = health.lastFailureAt === undefined ? '' : `,最近 ${clockOf(health.lastFailureAt)}`;\n const whenEn = health.lastFailureAt === undefined ? '' : `, latest ${clockOf(health.lastFailureAt)}`;\n return [\n `⚠ System One 后端不可用(${reason},连续 ${String(count)} 次失败${when});决策已降级为本地压缩与确定性兜底。`,\n `System One backend unavailable (${reason}, ${String(count)} consecutive failures${whenEn}); decisions degraded to local compression and deterministic fallback.`\n ].join(' / ');\n}\n\n/**\n * Render the ledger summary as plain text a person reads in the command output.\n *\n * The aggregate is always printed; the recent decisions are printed newest\n * first, because \"what just happened\" is the question the command is typed to\n * answer. An empty ledger is a normal state, not an error: it says so instead of\n * printing zeroes that look like a measurement.\n * @param result - the ledger read, with entries attached.\n * @returns the text of the command's reply.\n */\nexport function formatLedgerReport(result: ReflexLedgerResult): string {\n const { summary } = result;\n const health = systemOneHealthLine(result.systemOneHealth);\n const withHealth = (lines: string[]): string => {\n if (health !== undefined) lines.push(health);\n return lines.join('\\n');\n };\n if (summary.totalCalls === 0) {\n return withHealth([\n `Reflex 决策账本(${REFLEX_LEDGER_COMMAND}):暂无记录`,\n '本插件激活以来,System 1 还没有做出任何判定。',\n '第一次判定之后(工具调用或自动干预),这里会给出调用数、时延、节省的 token、门禁结果与停滞告警。'\n ]);\n }\n\n const byType = Object.entries(summary.callsByType)\n .sort((left, right) => right[1] - left[1] || (left[0] < right[0] ? -1 : 1))\n .map(([type, count]) => `${type} ${count}`)\n .join('、');\n\n const lines = [\n `Reflex 决策账本(${REFLEX_LEDGER_COMMAND})`,\n `总调用数:${summary.totalCalls}`,\n `平均时延:${latencyOf(summary.avgLatencyMs)}`,\n `节省 token:${summary.totalTokensSaved}(约 $${summary.estimatedCostSavedUsd.toFixed(4)})`,\n `门禁:通过 ${summary.gatePassedCount} / 失败 ${summary.gateFailedCount}`,\n `停滞告警:${summary.stagnationAlerts}`,\n `按类型:${byType}`\n ];\n\n const recent = (result.recentEntries ?? []).slice(-LEDGER_COMMAND_ENTRIES).reverse();\n if (recent.length > 0) {\n lines.push(`最近 ${recent.length} 条决策(最新在前):`);\n for (const entry of recent) lines.push(entryLine(entry));\n }\n return withHealth(lines);\n}\n\n/**\n * Register `/reflex-ledger` on the Host's command registry.\n *\n * The handler takes no arguments and never reaches the model: the Host renders\n * whatever {@link formatLedgerReport} returns. A deployment whose services were\n * already disposed, and a Host whose command registry is not available, both end\n * as a text answer rather than a crash — the ledger is a diagnostic, and a\n * diagnostic must not be able to break the surface that asks for it.\n *\n * The registry is read through `ctx.reflect.get`, not as `ctx.commands`: the\n * property form throws for a context that does not inject `commands`, and the\n * Host loader is not the only caller of `applyReflex`. The read is still the\n * plain service, so a context that does inject it gets the same object.\n * @param ctx - context carrying the `commands` service.\n * @param runtime - the activation whose ledger is read.\n * @returns the disposer that unregisters this exact command.\n */\nexport function installLedgerCommand(ctx: Context, runtime: ReflexRuntime): () => void {\n const registry = ctx.reflect?.get?.(COMMANDS_SERVICE) as CommandRegistry | undefined;\n if (registry === undefined || typeof registry.register !== 'function') return () => {};\n\n // The name is context-global, while this plugin can be activated more than\n // once on one context (each activation owning its own tools). The first\n // activation owns the command and answers for the ledger; a later one leaves\n // the registry alone rather than failing its whole activation over a\n // diagnostic. The same holds if someone else already claimed the name.\n if (typeof registry.find === 'function' && registry.find(undefined, REFLEX_LEDGER_COMMAND) !== undefined) {\n return () => {};\n }\n\n try {\n return registry.register({\n name: REFLEX_LEDGER_COMMAND,\n description: REFLEX_LEDGER_COMMAND_DESCRIPTION,\n handler: (): CommandResult => {\n try {\n return { kind: 'success', text: formatLedgerReport(runtime.statusLedger({ includeEntries: true })) };\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n return { kind: 'error', text: `Reflex 决策账本读取失败:${reason}` };\n }\n }\n });\n } catch (error) {\n // A registry too old to answer `find` still reports the collision; it is the\n // one failure that means \"someone else owns this name\", not \"broken setup\".\n if (error instanceof Error && error.message.includes('already registered')) return () => {};\n throw error;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAA0B,MAAM,kBAAkB,CAAC;AAG/E;;;;;;;;;;;GAWG;AAEH,wEAAwE;AACxE,MAAM,CAAC,MAAM,qBAAqB,GAAG,eAAe,CAAC;AAErD,yEAAyE;AACzE,MAAM,CAAC,MAAM,iCAAiC,GAAG,kBAAkB,CAAC;AAEpE,oDAAoD;AACpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAExC,2DAA2D;AAC3D,MAAM,gBAAgB,GAAG,UAAU,CAAC;AAYpC;;;;GAIG;AACH,SAAS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AC3B,WAAW,EAAE,iCAAiC;YAC9C,OAAO,EAAE,GAAkB,EAAE;gBAC3B,IAAI,CAAC;oBACH,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;gBACvG,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBACtE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,mBAAmB,MAAM,EAAE,EAAE,CAAC;gBAC9D,CAAC;YACH,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,6EAA6E;QAC7E,4EAA4E;QAC5E,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC;YAAE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAC;QAC5F,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { Context } from '@deepseek-ai/cordis';\nimport type { CommandResult } from '@deepseek-ai/dsh-commands';\n\nimport type { ReflexLedgerResult, ReflexRuntime } from './bridge.js';\nimport { describeAttribution, type LedgerAttribution } from './attribution.js';\nimport type { BackendHealth } from './vendor/harness-reflex/index.js';\n\n/**\n * The human command that reads this activation's decision ledger.\n *\n * The ledger used to be a `reflex_status_ledger` tool. It is not a decision the\n * model should have to spend a turn on — it is an audit question a person asks —\n * so it lives in the Host's command registry instead: `/reflex-ledger` answers\n * it without a model turn and without a slot on the tool surface. The capability\n * is unchanged: this is the same `runtime.statusLedger` read, formatted for a\n * person rather than for a model.\n *\n * @module dsh-reflex/command\n */\n\n/** Registered name of the ledger command, without the leading slash. */\nexport const REFLEX_LEDGER_COMMAND = 'reflex-ledger';\n\n/** Description the Host advertises for {@link REFLEX_LEDGER_COMMAND}. */\nexport const REFLEX_LEDGER_COMMAND_DESCRIPTION = '查看 Reflex 决策账本汇总';\n\n/** How many recent decisions the command prints. */\nexport const LEDGER_COMMAND_ENTRIES = 5;\n\n/** Name the context exposes the command registry under. */\nconst COMMANDS_SERVICE = 'commands';\n\n/** The slice of the registry this module uses. */\ninterface CommandRegistry {\n register(definition: { name: string; description: string; handler: () => CommandResult }): () => void;\n /** Resolve one definition, or `undefined` when the name is free. */\n find?(agent: undefined, name: string): unknown;\n}\n\n/** One audit entry, in the shape {@link ReflexRuntime.statusLedger} returns. */\ntype LedgerEntry = NonNullable<ReflexLedgerResult['recentEntries']>[number];\n\n/**\n * Format one instant from the ledger as local `HH:MM:SS`.\n * @param iso - the entry's ISO timestamp.\n * @returns the clock time, or the input when it is not a date.\n */\nfunction clockOf(iso: string): string {\n const at = new Date(iso);\n if (Number.isNaN(at.getTime())) return iso;\n const pad = (part: number): string => String(part).padStart(2, '0');\n return `${pad(at.getHours())}:${pad(at.getMinutes())}:${pad(at.getSeconds())}`;\n}\n\n/**\n * Format one latency, keeping a tenth of a millisecond when the backend reports\n * a fractional one.\n * @param latencyMs - measured latency.\n * @returns the human reading.\n */\nfunction latencyOf(latencyMs: number): string {\n return `${Number.isInteger(latencyMs) ? latencyMs : latencyMs.toFixed(1)} ms`;\n}\n\n/**\n * Render one entry as a single line: time, type, and the facts that entry owns.\n *\n * The provenance (g-068) comes last: the connection the call used and the model\n * it requested, plus its source whenever that source is not a plain remote\n * answer. An entry recorded before g-068 simply has none of these, and\n * {@link describeAttribution} returns `undefined` for it rather than inventing\n * a connection from today's settings.\n * @param entry - one ledger record.\n * @returns the line, without a trailing newline.\n */\nfunction entryLine(entry: LedgerEntry): string {\n const facts = [latencyOf(entry.latencyMs)];\n if (entry.tokensSaved) facts.push(`节省 ${entry.tokensSaved} token`);\n if (entry.type === 'gate') facts.push(entry.passed ? '通过' : '未通过');\n if (entry.type === 'stagnation') facts.push(entry.isStuck ? '判定停滞' : '未见停滞');\n if (entry.shadow) facts.push('shadow');\n if (entry.skipReason) facts.push(`跳过:${entry.skipReason}`);\n const provenance = describeAttribution((entry.details ?? {}) as Partial<LedgerAttribution>);\n if (provenance !== undefined) facts.push(provenance);\n return `- ${clockOf(entry.timestamp)} ${entry.type} · ${facts.join(' · ')}`;\n}\n\n/**\n * Render the degraded-backend notice appended to the command reply, if any.\n *\n * The line is bilingual because the panel is, and it stays in the command text:\n * it is a fact for the person typing `/reflex-ledger`, never a message the agent\n * reads. A recovered backend returns `undefined`, so the notice disappears on\n * its own.\n * @param health - backend health at read time, when the backend tracks it.\n * @returns the notice line, or `undefined` when the backend is healthy.\n */\nexport function systemOneHealthLine(health: BackendHealth | undefined): string | undefined {\n if (health === undefined || health.available) return undefined;\n const reason = health.lastFailureReason ?? 'unknown error';\n const count = health.consecutiveFailures;\n const when = health.lastFailureAt === undefined ? '' : `,最近 ${clockOf(health.lastFailureAt)}`;\n const whenEn = health.lastFailureAt === undefined ? '' : `, latest ${clockOf(health.lastFailureAt)}`;\n return [\n `⚠ System One 后端不可用(${reason},连续 ${String(count)} 次失败${when});决策已降级为本地压缩与确定性兜底。`,\n `System One backend unavailable (${reason}, ${String(count)} consecutive failures${whenEn}); decisions degraded to local compression and deterministic fallback.`\n ].join(' / ');\n}\n\n/**\n * Render the ledger summary as plain text a person reads in the command output.\n *\n * The aggregate is always printed; the recent decisions are printed newest\n * first, because \"what just happened\" is the question the command is typed to\n * answer. An empty ledger is a normal state, not an error: it says so instead of\n * printing zeroes that look like a measurement.\n * @param result - the ledger read, with entries attached.\n * @returns the text of the command's reply.\n */\nexport function formatLedgerReport(result: ReflexLedgerResult): string {\n const { summary } = result;\n const health = systemOneHealthLine(result.systemOneHealth);\n const withHealth = (lines: string[]): string => {\n if (health !== undefined) lines.push(health);\n return lines.join('\\n');\n };\n if (summary.totalCalls === 0) {\n return withHealth([\n `Reflex 决策账本(${REFLEX_LEDGER_COMMAND}):暂无记录`,\n '本插件激活以来,System 1 还没有做出任何判定。',\n '第一次判定之后(工具调用或自动干预),这里会给出调用数、时延、节省的 token、门禁结果与停滞告警。'\n ]);\n }\n\n const byType = Object.entries(summary.callsByType)\n .sort((left, right) => right[1] - left[1] || (left[0] < right[0] ? -1 : 1))\n .map(([type, count]) => `${type} ${count}`)\n .join('、');\n\n const lines = [\n `Reflex 决策账本(${REFLEX_LEDGER_COMMAND})`,\n `总调用数:${summary.totalCalls}`,\n `平均时延:${latencyOf(summary.avgLatencyMs)}`,\n `节省 token:${summary.totalTokensSaved}(约 $${summary.estimatedCostSavedUsd.toFixed(4)})`,\n `门禁:通过 ${summary.gatePassedCount} / 失败 ${summary.gateFailedCount}`,\n `停滞告警:${summary.stagnationAlerts}`,\n `按类型:${byType}`\n ];\n\n const recent = (result.recentEntries ?? []).slice(-LEDGER_COMMAND_ENTRIES).reverse();\n if (recent.length > 0) {\n lines.push(`最近 ${recent.length} 条决策(最新在前):`);\n for (const entry of recent) lines.push(entryLine(entry));\n }\n return withHealth(lines);\n}\n\n/**\n * Register `/reflex-ledger` on the Host's command registry.\n *\n * The handler takes no arguments and never reaches the model: the Host renders\n * whatever {@link formatLedgerReport} returns. A deployment whose services were\n * already disposed, and a Host whose command registry is not available, both end\n * as a text answer rather than a crash — the ledger is a diagnostic, and a\n * diagnostic must not be able to break the surface that asks for it.\n *\n * The registry is read through `ctx.reflect.get`, not as `ctx.commands`: the\n * property form throws for a context that does not inject `commands`, and the\n * Host loader is not the only caller of `applyReflex`. The read is still the\n * plain service, so a context that does inject it gets the same object.\n * @param ctx - context carrying the `commands` service.\n * @param runtime - the activation whose ledger is read.\n * @returns the disposer that unregisters this exact command.\n */\nexport function installLedgerCommand(ctx: Context, runtime: ReflexRuntime): () => void {\n const registry = ctx.reflect?.get?.(COMMANDS_SERVICE) as CommandRegistry | undefined;\n if (registry === undefined || typeof registry.register !== 'function') return () => {};\n\n // The name is context-global, while this plugin can be activated more than\n // once on one context (each activation owning its own tools). The first\n // activation owns the command and answers for the ledger; a later one leaves\n // the registry alone rather than failing its whole activation over a\n // diagnostic. The same holds if someone else already claimed the name.\n if (typeof registry.find === 'function' && registry.find(undefined, REFLEX_LEDGER_COMMAND) !== undefined) {\n return () => {};\n }\n\n try {\n return registry.register({\n name: REFLEX_LEDGER_COMMAND,\n description: REFLEX_LEDGER_COMMAND_DESCRIPTION,\n handler: (): CommandResult => {\n try {\n return { kind: 'success', text: formatLedgerReport(runtime.statusLedger({ includeEntries: true })) };\n } catch (error) {\n const reason = error instanceof Error ? error.message : String(error);\n return { kind: 'error', text: `Reflex 决策账本读取失败:${reason}` };\n }\n }\n });\n } catch (error) {\n // A registry too old to answer `find` still reports the collision; it is the\n // one failure that means \"someone else owns this name\", not \"broken setup\".\n if (error instanceof Error && error.message.includes('already registered')) return () => {};\n throw error;\n }\n}\n"]}
|