dsh-logicprobe 0.5.5 → 0.6.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.en-US.md CHANGED
@@ -14,7 +14,7 @@ Design documents are not truth — code is. A claim-verification skill that chec
14
14
  |-------|------|
15
15
  | Phase 1-2 | Enumerate every verifiable claim (API names, file paths, enum values, counts, mechanism feasibility) → verify each against the codebase with evidence |
16
16
  | Phase 2a | **8 structural checks** on extracted state-machine models: reachability, deadlock, liveness, determinism, event/guard completeness, invariant validity, monotonic variables |
17
- | Phase 2b | **11 adversarial probes**: unexpected events, race interleaving, order permutation, pair symmetry (lock/unlock), boundary blast, resource injection, minimal counter-example, idempotent replay, leads-to, sequence, atomicity |
17
+ | Phase 2b | **14 adversarial probes**: unexpected events, race interleaving, order permutation, pair symmetry (lock/unlock), boundary blast, resource injection, minimal counter-example, idempotent replay, leads-to, sequence, atomicity, budget (worst-case path cost, A12), probability reachability (A13), deadline (maxTicks + tickEvents, A14) |
18
18
  | Refactoring | Before/after model comparison — behavioral preservation, invariant continuity, deadlock regression, complexity claims |
19
19
  | Data models | DataModelV1 verification — DS/DA/DD checks, migration coverage, copy consistency, before/after breaking-change regression |
20
20
  | Concurrency risk mining | Scans documents/plans for concurrency safety claims (thread-safe, lock-free, race condition, interrupt safety, etc.) and flags them for dedicated verification |
@@ -67,7 +67,10 @@ Native dsh support ships as a cordis plugin bundle at the repository root (the r
67
67
  - The skill is discovered as-is by dsh's `skill-filesystem` provider (Agent Skills open standard) — zero code.
68
68
  - The bundle injects the claim-verification gate (1% Rule / Red Flags / proactive suggestion) into the first model step of every agent session — the dsh-native counterpart of the Claude `SessionStart` hook. It also registers a model-visible catalog entry (`cordis_inspect`), a native `logicprobe_verify` tool (`ctx.tools`), and a policy-aware `logicprobe:mode` context (`ctx.systemPrompt`).
69
69
  - `logicprobe_datamodel_verify` adds data-model verification: DataModelV1, migration coverage, copy consistency, and DD1-DD4 before/after data regression.
70
- - `logicprobe_concurrency_scan` mines documents/plans for concurrency risk claims (thread-safe, lock-free, race condition, mutex, etc.) and flags them for dedicated verification.
70
+ - `logicprobe_concurrency_scan` mines documents/plans for concurrency risk claims (thread-safe, lock-free, race condition, mutex, etc.), flags them for dedicated verification, and attaches tool-routing `suggestions` to absolute claims.
71
+ - `logicprobe_verify` also supports transition `cost` (default 1) with `budget` invariants (A12 worst-case path-cost check incl. positive-cost-cycle detection), and transition `weight` (default 1) with `probability` invariants (A13 probability reachability).
72
+ - State `onEntry`/`onExit` actions are treated by A4 Pair Symmetry as implicit acquire/release; `maxTicks` + `tickEvents` deadlines (A14); report `coverageNotes` routes timing/preemption/hybrid/probability vocabulary to dedicated tools (UPPAAL, TSan/CBMC/TLA+, SpaceEx, PRISM, ...).
73
+ - `logicprobe_compose_verify`: composition verification of two or more state machines (rendezvous handshake semantics) reporting C1 composition deadlock / C2 rendezvous never fires.
71
74
  - Together with the embedded-workbench bundle's Plan Verification Gate, this closes the claim-verification loop in dsh.
72
75
 
73
76
  Install: see [`.dsh/INSTALL.md`](.dsh/INSTALL.md) (four options, from plain skill copy to `dsh plugin add`).
@@ -85,7 +88,7 @@ The plugin auto-injects a capability notification into the first model step. The
85
88
 
86
89
  The skill auto-classifies depth (LIGHTWEIGHT / STANDARD / ESCALATED) from plan features in Phase 0, and appends a `## Plan Verification` summary block as the audit trail.
87
90
 
88
- In DSH, prefer the native `logicprobe_verify` tool for state machines and `logicprobe_datamodel_verify` for data models (see the schema references under each skill). Python remains optional for non-DSH hosts: state-machine checks use `skills/logicprobe/references/verification-harness.py`; data-model checks use `skills/logicprobe-datamodel/references/data-model-harness.py`. When Python is unavailable, the corresponding guide provides a manual verification mode.
91
+ In DSH, prefer the native `logicprobe_verify` tool for state machines and `logicprobe_datamodel_verify` for data models (see the schema references under each skill). Python remains optional for non-DSH hosts: when a LogicModelV1 JSON already exists, run the standalone engine `skills/logicprobe/references/logicprobe-engine.py` (`verify` runs S1-S8/A1-A14/D1-D4, `compose` runs C1/C2 composition, `export` emits UPPAAL/TLA+/PRISM/SPIN input — byte-identical to the dsh tools, cross-checked by tests/python/run.mjs); when the model only exists as extracted tables, fill in `skills/logicprobe/references/verification-harness.py`; data-model checks use `skills/logicprobe-datamodel/references/data-model-harness.py`. When Python is unavailable, the corresponding guide provides a manual verification mode.
89
92
 
90
93
  Sample models are available under [`examples/`](examples/README.md): order state-machine before/after, e-commerce data model, and User field migration.
91
94
 
package/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
  |------|------|
13
13
  | Phase 1-2 | 枚举每个可验证声称(API 名、文件路径、枚举值、数量、机制可行性)→ 逐条对照代码库给出证据 |
14
14
  | Phase 2a | 对提取的状态机模型执行 **8 项结构检查**:可达性、死锁、活性、确定性、事件/守卫完备性、不变量有效性、单调变量 |
15
- | Phase 2b | **11 种对抗探针**:意外事件、竞态交错、顺序置换、配对对称(lock/unlock)、边界轰炸、资源注入、最小反例、幂等重放、必达、顺序、原子性 |
15
+ | Phase 2b | **14 种对抗探针**:意外事件、竞态交错、顺序置换、配对对称(lock/unlock)、边界轰炸、资源注入、最小反例、幂等重放、必达、顺序、原子性、预算(最坏路径代价 A12)、概率可达(P(击中)≥p,A13)、期限(maxTicks+tickEvents,A14) |
16
16
  | 重构模式 | 前后模型对比——行为保持、不变量连续性、死锁回归、复杂度声称 |
17
17
  | 数据模型模式 | DataModelV1 数据模型验证——DS/DA/DD 检查,迁移覆盖、copy 一致性、before/after 破坏性变更回归 |
18
18
  | 并发风险挖掘 | 扫描文档/计划中的并发安全声称(thread-safe、lock-free、race condition、中断安全等),标记需要专用验证 |
@@ -65,6 +65,9 @@ git clone https://github.com/AmethystLuna/logicprobe.git ~/.claude/plugins/dev/l
65
65
  - 技能遵循 Agent Skills 开放标准,被 dsh 的 `skill-filesystem` provider 原样发现——零代码。
66
66
  - bundle 将 claim 验证门禁(1% Rule / Red Flags / 主动建议)注入每个 agent 会话的第一个模型步骤——是 Claude `SessionStart` hook 在 dsh 的原生对应物,并注册模型可见目录条目(`cordis_inspect`)、原生工具 `logicprobe_verify`(`ctx.tools`)以及策略感知上下文 `logicprobe:mode`(`ctx.systemPrompt`)。
67
67
  - `logicprobe_verify` 支持 `beforeModel` + `stateMapping` 的 BEFORE/AFTER 对比(D1-D4),可直接验证重构/迁移的行为保持、不变量连续性、回归增量和死锁/活性回归。
68
+ - `logicprobe_verify` 还支持:迁移/处理器代价 `cost`(缺省 1)与 `budget` 不变量(A12 最坏路径代价检查,含正成本环检测)、迁移权重 `weight` 与 `probability` 不变量(A13 概率可达)。
69
+ - 状态 `onEntry`/`onExit` 动作(A4 自动纳入配对检查);`maxTicks`+`tickEvents` 期限(A14);报告 `coverageNotes`(时序/抢占/混合/概率词汇 → UPPAAL/TSan/CBMC/TLA+/SpaceEx/PRISM 等外部工具路由)。
70
+ - `logicprobe_compose_verify`:两台及以上状态机组合验证(握手 rendezvous 语义),报 C1 组合死锁 / C2 握手永不触发。
68
71
  - `logicprobe_datamodel_verify` 新增数据模型验证:DataModelV1、迁移覆盖、copy 一致性、DD1-DD4 before/after 数据回归。
69
72
  - `logicprobe_concurrency_scan` 扫描文档/计划中的并发风险声称(thread-safe、lock-free、race condition、mutex 等),标记需要专用并发验证。
70
73
  - 与 embedded-workbench bundle 的 Plan Verification Gate 配合,在 dsh 中闭环了 claim 验证链路。
@@ -84,7 +87,7 @@ git clone https://github.com/AmethystLuna/logicprobe.git ~/.claude/plugins/dev/l
84
87
 
85
88
  技能在 Phase 0 依据计划特征自动分级(LIGHTWEIGHT / STANDARD / ESCALATED),并在计划文件追加 `## Plan Verification` 摘要块作为审计痕迹。
86
89
 
87
- Python 可选:状态机验证使用 `skills/logicprobe/references/verification-harness.py`,数据模型验证使用 `skills/logicprobe-datamodel/references/data-model-harness.py`;不可用(如离线开发机)时,对应 guide 提供手动验证模式。
90
+ Python 可选:已有 LogicModelV1 JSON 时可直接运行独立引擎 `skills/logicprobe/references/logicprobe-engine.py`(`verify` 跑 S1-S8/A1-A14/D1-D4,`compose` 跑 C1/C2 组合,`export` 生成 UPPAAL/TLA+/PRISM/SPIN 输入——与 dsh 工具逐字节一致,见 tests/python/run.mjs);模型仅为抽取出的状态表时,填充模板 `skills/logicprobe/references/verification-harness.py`;数据模型验证使用 `skills/logicprobe-datamodel/references/data-model-harness.py`;不可用(如离线开发机)时,对应 guide 提供手动验证模式。
88
91
 
89
92
  示例模型见 [`examples/`](examples/README.md):订单状态机 before/after、电商数据模型、User 字段迁移。
90
93
 
@@ -0,0 +1,43 @@
1
+ import { defineTool } from '@deepseek-ai/dsh-tools';
2
+ import { runCompositionVerification } from './engine.js';
3
+ export const LOGICPROBE_COMPOSE_TOOL_NAME = 'logicprobe_compose_verify';
4
+ /**
5
+ * DSH tool wrapping multi-machine composition verification:
6
+ * product-space reachability with rendezvous handshakes (C1 deadlock, C2 sync).
7
+ */
8
+ export const logicProbeComposeTool = defineTool({
9
+ name: LOGICPROBE_COMPOSE_TOOL_NAME,
10
+ description: 'Run composition verification over two or more LogicModelV1 state machines (logicprobe). Pass machines as an array of models and optionally rendezvous: a list of handshake events that must fire simultaneously across all machines declaring them (at least two participants, all jointly enabled, guards held; a terminal machine stops participating). Non-rendezvous events advance exactly one firing machine. Returns C1 composition-deadlock findings (a reachable state where no machine can advance while at least one is not terminal) and C2 rendezvous-never-fires findings. Each machine validates against the same schema as logicprobe_verify.',
11
+ parameters: {
12
+ machines: {
13
+ type: 'json',
14
+ required: true,
15
+ description: 'Array of LogicModelV1 state-machine models to compose (two or more).',
16
+ },
17
+ rendezvous: {
18
+ type: 'json',
19
+ description: 'Optional array of handshake event names shared by the machines.',
20
+ },
21
+ maxStates: {
22
+ type: 'integer',
23
+ description: 'Maximum composite states to explore. Default 10000.',
24
+ },
25
+ },
26
+ output: {
27
+ schema: {
28
+ type: 'json',
29
+ description: 'Composition verification report with C1/C2 findings.',
30
+ },
31
+ render(_args, value) {
32
+ return [{ type: 'text', text: JSON.stringify(value, null, 2) }];
33
+ },
34
+ },
35
+ timeoutMs: 10_000,
36
+ isConcurrencySafe: () => true,
37
+ async execute(args) {
38
+ return runCompositionVerification(args.machines, {
39
+ rendezvous: args.rendezvous,
40
+ maxStates: args.maxStates,
41
+ });
42
+ },
43
+ });
@@ -36,6 +36,15 @@ export function runConcurrencyScan(text) {
36
36
  const lines = text.split(/\r?\n/);
37
37
  const findings = [];
38
38
  const seen = new Set();
39
+ const suggestionsFor = (label) => {
40
+ if (/thread-safe|lock-free|wait-free|race-free|no data race|data race|race condition|thread safety/.test(label)) {
41
+ return ['TSan / Helgrind (runtime data-race detection)', 'CBMC / static analysis (proof-oriented)', 'TLA+ (exhaustive interleaving model)'];
42
+ }
43
+ if (/interrupt-safe|ISR-safe|interrupt context|critical section|disable_irq|enable_irq/.test(label)) {
44
+ return ['RTOS-aware analysis (interrupt latency, priority inversion)', 'CBMC (state-machine + ISR interleaving proof)', 'TLA+ (preemption/exclusion model)'];
45
+ }
46
+ return ['Dedicated concurrency verification (TSan, CBMC, TLA+, or RTOS-specific analysis)'];
47
+ };
39
48
  lines.forEach((line, index) => {
40
49
  const lineNumber = index + 1;
41
50
  const lower = line.toLowerCase();
@@ -50,11 +59,12 @@ export function runConcurrencyScan(text) {
50
59
  code: rule.absolute ? 'CONCURRENCY_ABSOLUTE_CLAIM' : 'CONCURRENCY_KEYWORD',
51
60
  severity: rule.absolute ? 'error' : 'warning',
52
61
  message: rule.absolute
53
- ? 'Concurrency safety claim "' + rule.label + '" detected; this requires dedicated verification (TSan, model checker, or explicit proof).'
62
+ ? 'Concurrency safety claim "' + rule.label + '" detected; logicprobe does not verify concurrency — this needs dedicated verification.'
54
63
  : 'Concurrency-related term "' + rule.label + '" detected; review whether the plan addresses this risk.',
55
64
  line: lineNumber,
56
65
  snippet: line.trim().slice(0, 200),
57
66
  keyword: rule.label,
67
+ ...(rule.absolute ? { suggestions: suggestionsFor(rule.label) } : {}),
58
68
  };
59
69
  findings.push(finding);
60
70
  }