reasonweave 0.0.0-stage → 1.3.2
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/AGENTS.md +101 -0
- package/INSTALL.md +258 -0
- package/README.md +280 -2
- package/bin/lab.mjs +888 -0
- package/constitution.md +55 -0
- package/docs/CONSUMER-PROMPTS.md +474 -0
- package/docs/backlogs/01-forward-wait-self-detach.md +18 -0
- package/docs/backlogs/02-decouple-wait-and-daemon-for-agent-hosts.md +35 -0
- package/docs/backlogs/03-baton-wait-multi-id-lightweight-pubsub.md +34 -0
- package/docs/backlogs/04-adr-cross-repo-automated-dispatch-boundary.md +19 -0
- package/docs/backlogs/05-feat-units-worktree-isolation-engine.md +23 -0
- package/docs/backlogs/06-feat-blind-audit-automated-clean-runner.md +22 -0
- package/docs/backlogs/07-feat-attention-throttle-silent-pipe.md +23 -0
- package/docs/backlogs/08-future-units-shadow-ledger.md +22 -0
- package/docs/backlogs/09-feat-agent-baton-core-convergence-and-resilience.md +42 -0
- package/docs/backlogs/10-feat-anti-orphan-deterministic-wiring-governance.md +35 -0
- package/docs/backlogs/11-perf-orphan-index-fs-read.md +16 -0
- package/docs/backlogs/12-feat-vibe-security-anti-suppression-and-orphan-deps.md +43 -0
- package/docs/backlogs/13-feat-sdd-reppit-tiered-guardrails.md +40 -0
- package/docs/backlogs/14-feat-universal-cli-contract-and-hermetic-test-fixtures.md +48 -0
- package/docs/backlogs/15-feat-reasonweave-rebranding-and-doc-code-synchronization-invariant.md +44 -0
- package/docs/backlogs/16-feat-micro-engineering-skills-and-sdd-baton-fusion.md +52 -0
- package/docs/codegraph-readiness-check.md +49 -0
- package/group/architecture/adr/0001-handoff-async-wait-and-reactive-wakeup.md +87 -0
- package/group/architecture/adr/0002-de-ritualize-handoff-prompt-for-intra-repo.md +53 -0
- package/group/architecture/adr/0003-attention-throttle-and-workspace-driver.md +65 -0
- package/group/architecture/adr/0004-spec-guard-and-drift-prevention.md +90 -0
- package/group/architecture/adr/0005-global-orphan-scavenger-and-read-only-invariants.md +94 -0
- package/group/architecture/adr/0006-triad-engineering-defense-and-mutation-sensitivity.md +68 -0
- package/group/architecture/adr/0007-agent-baton-state-machine-defense-and-workspace-jail-spec.md +86 -0
- package/group/architecture/adr/0008-agent-baton-core-convergence-and-heterogeneous-session-resilience.md +133 -0
- package/group/architecture/adr/0009-anti-orphan-deterministic-wiring-governance-and-federated-guardrails.md +108 -0
- package/group/architecture/adr/0010-agent-baton-identity-security-cryptographic-credentials-and-prompt-anti-confusion.md +119 -0
- package/group/architecture/adr/0011-vibe-security-anti-suppression-and-dependency-reachability.md +161 -0
- package/group/architecture/adr/0012-spec-driven-development-reppit-and-tiered-guardrails.md +130 -0
- package/group/architecture/adr/0013-universal-cli-contract-hermetic-testing-and-defensive-probes.md +110 -0
- package/group/architecture/adr/0014-reasonweave-rebranding-and-doc-code-synchronization-invariant.md +108 -0
- package/group/architecture/adr/0015-micro-engineering-skills-and-dual-core-gate-invariant.md +127 -0
- package/group/architecture/adr/INDEX.md +29 -0
- package/group/architecture/adr/templates/adr-template.md +33 -0
- package/group/architecture/dependency-graph.md +60 -0
- package/group/contracts/npm-packaging.md +69 -0
- package/group/product/intent.md +24 -0
- package/package.json +93 -4
- package/scripts/sync-all-consumers.mjs +174 -0
- package/specs/RFC-20261110-SPEC-GUARD-UNIT.md +353 -0
- package/specs/templates/01-research.md.template +23 -0
- package/specs/templates/02-proposals.md.template +22 -0
- package/specs/templates/03-spec.md.template +33 -0
- package/specs/templates/04-tasks.md.template +29 -0
- package/specs/templates/05-evidence.md.template +29 -0
- package/specs/templates/README.md +26 -0
- package/units/adr/AGENTS.md +85 -0
- package/units/adr/CHANGELOG.md +20 -0
- package/units/adr/README.md +88 -0
- package/units/adr/VERSION.md +10 -0
- package/units/adr/docs/existing-project-prompt.md +24 -0
- package/units/adr/docs/new-project-prompt.md +36 -0
- package/units/adr/scripts/adr-init.sh +101 -0
- package/units/adr/templates/INDEX.md +19 -0
- package/units/adr/templates/adr-frozen.md +33 -0
- package/units/adr/templates/adr-light.md +56 -0
- package/units/adr/templates/adr-standard.md +61 -0
- package/units/backlog/AGENTS.md +53 -0
- package/units/backlog/AUTONOMOUS-GOVERNANCE.md +98 -0
- package/units/backlog/CHANGELOG.md +37 -0
- package/units/backlog/README.md +124 -0
- package/units/backlog/VERSION.md +11 -0
- package/units/backlog/docs/existing-project-ironrules-prompt.md +31 -0
- package/units/backlog/docs/existing-project-prompt.md +24 -0
- package/units/backlog/docs/new-project-prompt.md +19 -0
- package/units/backlog/templates/entry.md +39 -0
- package/units/backlog/templates/project-ironrules.md +36 -0
- package/units/handoffs/AGENT-GUIDE.md +118 -0
- package/units/handoffs/AGENTS.md +28 -0
- package/units/handoffs/CHANGELOG.md +498 -0
- package/units/handoffs/CLAUDE.md +28 -0
- package/units/handoffs/COMMANDS.md +187 -0
- package/units/handoffs/DESIGN.md +74 -0
- package/units/handoffs/README.md +456 -0
- package/units/handoffs/RESPONSE-TEMPLATE.md +138 -0
- package/units/handoffs/VERSION.md +1 -0
- package/units/handoffs/handoff-status.mjs +1017 -0
- package/units/handoffs/handoff.mjs +5675 -0
- package/units/orphan/CHANGELOG.md +118 -0
- package/units/orphan/DESIGN.md +484 -0
- package/units/orphan/README.md +143 -0
- package/units/orphan/VERSION.md +1 -0
- package/units/orphan/adapters/android/index.mjs +140 -0
- package/units/orphan/adapters/python/index.mjs +232 -0
- package/units/orphan/adapters/web/index.mjs +280 -0
- package/units/orphan/bin/lab-orphan.mjs +298 -0
- package/units/orphan/core/blob-reader.mjs +142 -0
- package/units/orphan/core/classifier.mjs +261 -0
- package/units/orphan/core/cleaner.mjs +166 -0
- package/units/orphan/core/diff-checker.mjs +341 -0
- package/units/orphan/core/inverted-index.mjs +124 -0
- package/units/orphan/core/orphan-deps.mjs +192 -0
- package/units/orphan/core/protocol-s1-s3.mjs +194 -0
- package/units/orphan/core/solver.mjs +217 -0
- package/units/orphan/index.mjs +105 -0
- package/units/orphan/templates/ci/orphan-guard.yml +36 -0
- package/units/orphan/templates/pre-commit.d/30-orphan-guard +34 -0
- package/units/orphan/templates/wiring/README.md +51 -0
- package/units/orphan/templates/wiring/miniprogram-route-guard.js.template +80 -0
- package/units/orphan/templates/wiring/pre-commit-node.sh.template +73 -0
- package/units/orphan/templates/wiring/project-agents-gemini-templates.md +60 -0
- package/units/orphan/templates/wiring/python-parity-test.py.template +100 -0
- package/units/orphan/templates/wiring/rust-exhaustive-match.md +65 -0
- package/units/orphan/templates/wiring/swift-periphery.md +56 -0
- package/units/orphan/tests/adapters.test.mjs +243 -0
- package/units/orphan/tests/orphan-deps.test.mjs +131 -0
- package/units/orphan/tests/phase3-gates.test.mjs +135 -0
- package/units/playbook/README.md +106 -0
- package/units/playbook/ZSPEC-AGENT-GUIDE.md +99 -0
- package/units/playbook/docs/01-architecture.md +99 -0
- package/units/playbook/docs/02-bootstrap.md +126 -0
- package/units/playbook/docs/03-units.md +91 -0
- package/units/playbook/docs/04-constitution.md +113 -0
- package/units/playbook/docs/05-adr.md +33 -0
- package/units/playbook/docs/06-spec-kit.md +76 -0
- package/units/playbook/docs/07-backlog.md +30 -0
- package/units/playbook/docs/08-codegraph.md +79 -0
- package/units/playbook/docs/09-skills.md +101 -0
- package/units/playbook/docs/10-handoff.md +72 -0
- package/units/playbook/docs/11-evidence.md +163 -0
- package/units/playbook/docs/12-gates.md +124 -0
- package/units/playbook/docs/13-parallel.md +115 -0
- package/units/playbook/docs/14-dependency-graph.md +86 -0
- package/units/playbook/docs/15-memory.md +153 -0
- package/units/playbook/docs/16-change-control.md +121 -0
- package/units/playbook/docs/17-prompts.md +121 -0
- package/units/playbook/docs/18-shift-left.md +97 -0
- package/units/playbook/docs/19-anti-orphan-vertical-slicing.md +102 -0
- package/units/playbook/docs/20-vibe-security-and-anti-suppression.md +88 -0
- package/units/playbook/docs/21-spec-driven-reppit-closed-loop.md +88 -0
- package/units/playbook/examples/owisel.md +80 -0
- package/units/playbook/references/Agent-Engineering-Framework-AEF-v1.0.md +2033 -0
- package/units/playbook/references/links.md +103 -0
- package/units/playbook/templates/AGENTS.root.md +44 -0
- package/units/playbook/templates/AGENTS.unit.md +52 -0
- package/units/playbook/templates/adr/INDEX.md +17 -0
- package/units/playbook/templates/adr/NNNN-template.md +56 -0
- package/units/playbook/templates/backlogs/entry.md +30 -0
- package/units/playbook/templates/constitution.md +93 -0
- package/units/playbook/templates/evidence/README.md +36 -0
- package/units/playbook/templates/group/architecture/dependency-graph.md +48 -0
- package/units/playbook/templates/group/architecture/system.md +59 -0
- package/units/playbook/templates/group/contracts/api.md +67 -0
- package/units/playbook/templates/group/product/intent.md +30 -0
- package/units/playbook/templates/group/product/requirements.md +48 -0
- package/units/playbook/templates/unit-skeleton/README.md +35 -0
- package/units/preflight/AGENTS.md +45 -0
- package/units/preflight/CHANGELOG.md +55 -0
- package/units/preflight/INSTALL.md +65 -0
- package/units/preflight/README.md +104 -0
- package/units/preflight/VERSION.md +3 -0
- package/units/preflight/docs/audit-requirements.md +114 -0
- package/units/preflight/docs/existing-project-prompt.md +25 -0
- package/units/preflight/docs/new-project-prompt.md +25 -0
- package/units/preflight/docs/transfers/CONSUMER-INSTALL.md +40 -0
- package/units/preflight/docs/transfers/CONSUMER-SELFCHECK.md +51 -0
- package/units/preflight/docs/transfers/README.md +39 -0
- package/units/preflight/docs/transfers/prospero.md +26 -0
- package/units/preflight/templates/check.sh +43 -0
- package/units/preflight/templates/pre-commit +55 -0
- package/units/preflight/templates/pre-commit.d/20-preflight +15 -0
- package/units/preflight/templates/preflight.conf.example +21 -0
- package/units/preflight/templates/preflight.sh +189 -0
- package/units/preflight/templates/wrap-up.md +9 -0
- package/units/review-gate/AGENTS.md +42 -0
- package/units/review-gate/CHANGELOG.md +58 -0
- package/units/review-gate/README.md +118 -0
- package/units/review-gate/VERSION.md +3 -0
- package/units/review-gate/clean-runner.mjs +350 -0
- package/units/review-gate/docs/existing-project-prompt.md +28 -0
- package/units/review-gate/docs/new-project-prompt.md +38 -0
- package/units/review-gate/docs/transfers/iggle.md +34 -0
- package/units/review-gate/docs/transfers/prospero.md +35 -0
- package/units/review-gate/docs/transfers/swoop.md +36 -0
- package/units/review-gate/docs/transfers/yiqiyihuihua.md +35 -0
- package/units/review-gate/templates/.semgrepignore +37 -0
- package/units/review-gate/templates/pre-commit +130 -0
- package/units/review-gate/templates/scan.sh +158 -0
- package/units/skills/AGENTS.md +17 -0
- package/units/skills/CHANGELOG.md +18 -0
- package/units/skills/README.md +63 -0
- package/units/skills/VERSION.md +1 -0
- package/units/skills/bin/review-package.mjs +99 -0
- package/units/skills/bin/task-brief.mjs +102 -0
- package/units/skills/catalog/brainstorming/SKILL.md +75 -0
- package/units/skills/catalog/brainstorming/references/design-doc-template.md +28 -0
- package/units/skills/catalog/systematic-debugging/SKILL.md +101 -0
- package/units/skills/catalog/systematic-debugging/references/root-cause-tracing.md +23 -0
- package/units/skills/catalog/test-driven-development/SKILL.md +88 -0
- package/units/skills/catalog/test-driven-development/references/writing-good-tests.md +13 -0
- package/units/skills/catalog/verification-before-completion/SKILL.md +73 -0
- package/units/skills/skills.mjs +181 -0
- package/units/skills/tests/pipeline.test.mjs +131 -0
- package/units/skills/tests/skill-contract.test.mjs +67 -0
- package/units/skills/tests/skills-cli.test.mjs +107 -0
- package/units/spec-guard/AGENTS.md +43 -0
- package/units/spec-guard/CHANGELOG.md +88 -0
- package/units/spec-guard/README.md +148 -0
- package/units/spec-guard/VERSION.md +1 -0
- package/units/spec-guard/bin/spec-guard.mjs +431 -0
- package/units/spec-guard/core/adr-parser.mjs +540 -0
- package/units/spec-guard/core/matrix-checker.mjs +587 -0
- package/units/spec-guard/core/mutation-runner.mjs +267 -0
- package/units/spec-guard/core/scanner.mjs +333 -0
- package/units/spec-guard/core/telemetry_authenticator.mjs +484 -0
- package/units/spec-guard/core/wiring_tracer.mjs +306 -0
- package/units/spec-guard/templates/annotations/ContractOnly.kt +19 -0
- package/units/spec-guard/templates/annotations/Invariant.kt +16 -0
- package/units/spec-guard/templates/annotations/invariant.go +19 -0
- package/units/spec-guard/templates/annotations/invariant.py +38 -0
- package/units/spec-guard/templates/annotations/invariant.ts +39 -0
- package/units/spec-guard/templates/ci/spec-guard-audit.yml +23 -0
- package/units/spec-guard/templates/pre-commit.d/15-spec-guard +72 -0
- package/units/spec-guard/templates/spec-matrix.overlay.yml +70 -0
- package/units/spec-guard/tests/spec-guard.test.mjs +716 -0
- package/units/spec-guard/tests/telemetry_authenticator.test.mjs +633 -0
- package/units/worktree/AGENTS.md +22 -0
- package/units/worktree/CHANGELOG.md +14 -0
- package/units/worktree/README.md +65 -0
- package/units/worktree/VERSION.md +1 -0
- package/units/worktree/worktree.mjs +352 -0
- package//344/275/277/347/224/250/350/257/264/346/230/216.md +322 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# orphan — 全局死代码与孤儿资产清道夫公共单元
|
|
2
|
+
|
|
3
|
+
> 本单元是 `lab-agent-toolkit` 面向跨语言代码库与多媒体资产的**公共清道夫事实源**,专治死代码膨胀、无主孤儿资产堆积与 AI Agent 误读废弃逻辑等工程退化问题。
|
|
4
|
+
> **详细设计方案与工业界调研**:请完整阅读 [DESIGN.md](./DESIGN.md)。
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 0. 这是什么 / 为什么独立
|
|
9
|
+
|
|
10
|
+
在长期演进的软件项目与 AI 辅助研发过程中,代码和资产往往「只增不减」:
|
|
11
|
+
- 废弃的类、函数与接口无人敢删,怕触发隐式调用;
|
|
12
|
+
- 迭代遗留的布局文件、矢量图标、切图资源悄然变成无主孤儿(Orphan Assets);
|
|
13
|
+
- 过期的特性开关分支(Feature Flags)与测试桩代码在主干长期堆积。
|
|
14
|
+
|
|
15
|
+
**解法不是「凭感觉人肉排查」,而是「严格数学求解与自检自证」**:
|
|
16
|
+
`units/orphan` 沉淀了消费方(如 Tappy)实战验证的 169 项清理成果与求解器范式,将其抽象为可复用、跨技术栈、绝对只读零污染的工程机件。
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 1. 核心设计原则
|
|
21
|
+
|
|
22
|
+
| 原则 | 核心含义 | 为什么必须 |
|
|
23
|
+
|---|---|---|
|
|
24
|
+
| **只读第一 (Read-Only Invariant)** | 恒基于 Git HEAD blob,严禁依赖脏工作树,扫描过程零修改零污染。 | 保证扫描随时可在 CI/本地并发安全执行,不引发 git 冲突与污染。 |
|
|
25
|
+
| **行级倒排索引 (Inverted Index)** | 在内存中对全仓 Token 建立行级倒排索引,毫秒级快速逆向追溯引用。 | 摆脱慢速 grep,消除跨语言全仓大范围扫描的 IO 瓶颈。 |
|
|
26
|
+
| **引用三分类器 (3-Tier Classifier)** | 细分 Code (强)、Resource (中)、Doc/Comment (弱) 三种引用类型。 | 文档或注释中提到的旧名字不能误判为代码存活,也不能草率误删。 |
|
|
27
|
+
| **S1–S3 求解器自检协议** | 严禁硬编码白名单。每次扫描均运行 S1 注入假死检出、S2 在用保护、S3 逐字节可重复自检。 | 求解器自身的正确性与鲁棒性必须机器可判、持续自证。 |
|
|
28
|
+
| **Fail-Closed 安全降级** | 遇动态反射、复杂拼接或不确定契约时,一律标记为待证或保留。 | 杜绝由于静态分析局限导致的线上生产误杀事故。 |
|
|
29
|
+
| **增量只扫新增 (O(Δ) 复杂度)** | 提交门禁仅提取 `git diff` 中添加的行发现新符号,秒级完成拦截。 | 保证 Git 提交体验流畅,门禁耗时 ≤ 1.5s。 |
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 2. 架构概览
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
units/orphan/
|
|
37
|
+
├── README.md # 本规范入口
|
|
38
|
+
├── DESIGN.md # 完整立项调研与架构设计方案 (必读)
|
|
39
|
+
├── VERSION.md # 单一版本事实源 (v1.0.0)
|
|
40
|
+
├── CHANGELOG.md # 变更日志
|
|
41
|
+
├── bin/ # CLI 命令行入口 (lab-orphan.mjs)
|
|
42
|
+
├── core/ # 核心求解器引擎 (Language-Agnostic)
|
|
43
|
+
│ ├── blob-reader.mjs # Git HEAD 只读提取
|
|
44
|
+
│ ├── inverted-index.mjs # 内存行级倒排索引
|
|
45
|
+
│ ├── classifier.mjs # 引用三分类器
|
|
46
|
+
│ ├── protocol-s1-s3.mjs # S1-S3 自检门禁套件
|
|
47
|
+
│ ├── solver.mjs # 统一求解器
|
|
48
|
+
│ ├── diff-checker.mjs # 增量差异比对与门禁判定
|
|
49
|
+
│ ├── orphan-deps.mjs # 依赖清单与凭证求解器 (ADR-0011 / ADR-0012)
|
|
50
|
+
│ └── cleaner.mjs # 安全修剪与 Diff 生成器
|
|
51
|
+
├── adapters/ # 各技术栈专属适配器
|
|
52
|
+
│ ├── android/ # Android (Manifest / R / XML / Kotlin / Qualifiers)
|
|
53
|
+
│ ├── python/ # Python (__all__ / pytest / magic / routes / getattr)
|
|
54
|
+
│ └── web/ # Web / TS (package.json entrypoints / ESM / CJS / exports)
|
|
55
|
+
├── templates/ # 接入配置与 Preflight 门禁脚本模板
|
|
56
|
+
│ ├── pre-commit.d/30-orphan-guard # pre-commit.d 门禁子片
|
|
57
|
+
│ └── ci/orphan-guard.yml # GitHub Actions 工作流
|
|
58
|
+
└── tests/ # 自动化测试套件
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## 3. CLI 命令行用法
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# 1. 运行求解器自检协议(S1 假死检出、S2 在用保护、S3 逐字节一致)
|
|
67
|
+
lab orphan test-solver
|
|
68
|
+
|
|
69
|
+
# 2. 全量扫描当前 HEAD 状态,输出结构化候选文件(只读零污染)
|
|
70
|
+
lab orphan scan [--stack auto|android|python|web] [--out candidates.json] [--json]
|
|
71
|
+
|
|
72
|
+
# 3. 增量提交门禁校验(与 git commit 暂存区联动,拦截新增孤儿)
|
|
73
|
+
lab orphan check-diff --staged
|
|
74
|
+
lab orphan check-diff --base origin/main
|
|
75
|
+
|
|
76
|
+
# 4. 受控安全清理(支持 dry-run 演练预览统一 Patch)
|
|
77
|
+
lab orphan clean [--candidates candidates.json] --dry-run
|
|
78
|
+
lab orphan clean --force
|
|
79
|
+
|
|
80
|
+
# 5. 依赖清单与在用导入对账(消除未导入孤儿包导致的虚假 CVE 报警风暴,支持 --strict 阻断)
|
|
81
|
+
lab orphan check-deps [--strict]
|
|
82
|
+
|
|
83
|
+
# 6. 零调用垃圾假凭证与高熵 Token 扫描(支持 --strict 门禁退出码)
|
|
84
|
+
lab orphan scan-secrets [--strict]
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## 4. 与工程工作流接入
|
|
90
|
+
|
|
91
|
+
### 4.1 接入 Preflight 提交门禁(本地左移防腐)
|
|
92
|
+
将门禁子片安装至项目的 `.githooks/pre-commit.d/`:
|
|
93
|
+
```bash
|
|
94
|
+
cp "$(lab path orphan)/templates/pre-commit.d/30-orphan-guard" .githooks/pre-commit.d/30-orphan-guard
|
|
95
|
+
chmod +x .githooks/pre-commit.d/30-orphan-guard
|
|
96
|
+
```
|
|
97
|
+
在开发者或 Agent 运行 `git commit` 时,门禁将毫秒级分析暂存区新增代码。若引入了从未引用的假死符号或无主资源,将以 Exit 1 阻断提交。
|
|
98
|
+
|
|
99
|
+
### 4.2 接入 CI 流水线(远端合入防腐)
|
|
100
|
+
复制 `templates/ci/orphan-guard.yml` 到项目 `.github/workflows/orphan-guard.yml`,在 Pull Request 评审中自动校验增量改动。
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 5. 反假接线三层正交治理规范 (L1 / L2 / L3 · 沉淀自 ADR-075)
|
|
105
|
+
|
|
106
|
+
在解决“未接线(Orphan)”之后,更隐蔽的工程退化是**“假接线(Fake Wiring)”**——如仅补齐 Schema 声明但分发器/工厂未装配、路由映射存在但返回空任务列表、或底层吞错/伪造成功。为此确立**三层正交解耦原则**,各层只解决可判定的一类问题:
|
|
107
|
+
|
|
108
|
+
| 层级 | 定位与执行环境 | 强制职责边界 | 明令禁止(反假阳性/防死循环) |
|
|
109
|
+
| :--- | :--- | :--- | :--- |
|
|
110
|
+
| **L1 (Fast Gate)** | 本地 `pre-commit` / `audit_wiring --fast`(亚秒级静态检查) | ① **双向拓扑零差集**:显式 `Tool(name=...)` / `types.Tool(name=...)` 注册表 ↔ 分发分支 ↔ 工厂实现,含**反向幽灵工具拦截**;② **基础结构存在性**:分支须调用真实工厂并流入返回、禁 `pass` 空分支、禁 `SKIP_*` 环境变量绕过。 | **严禁**在 L1 离线 AST 中追逐无穷表达式、恒假求值或反射黑名单(防 Rice 定理不可判定性死循环);**反射/动态执行**统一由 `.githooks/pre-commit.d/10-review-gate`(OpenGrep SAST)守卫。 |
|
|
111
|
+
| **L2 (Contract Tests)** | 唯一项目运行时(如 `.venv/bin/python`),强制接入 **CI** 与 **`preflight.conf` `RECONCILE_CMD`** | ① **全量路由非空产出**:遍历全部注册目标,验证真实产出非空实体(如 `List[TaskDefinition]`);② **失败传播与反假成功**:验证 `0` / `None` / 空事件 Fail-Closed、异常向上传播不吞没;③ **内置变异自证(`--verify-mutations`)**:证明吞错或强行篡改成功时契约测试必红。 | **严禁**用离线 `exec()` + `MockPipe` 伪微沙箱替代真实运行时,或私自裂变多套 `.venv-*`。 |
|
|
112
|
+
| **L3 (Runtime Attestation)** | 真机 / 外部设备产出写入持久化存储前 | 采用**非对称 Ed25519**(设备侧隔离区持私钥签发,宿主仅持公钥验签)+ **新鲜度硬门限校验**(绑定设备序列号 `serial` + 时间戳新鲜度 `<= 60s` + 状态哈希 + 结果摘要);缺失/过期/篡改/不匹配时 100% Fail-Closed 熔断拒写。 | **严禁**使用对称 HMAC 替代非对称 Ed25519,严禁无新鲜度校验或静默跳过验签。 |
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 6. Tier 1 / Tier 2 分级自查触发矩阵
|
|
117
|
+
|
|
118
|
+
| 分级 | 触发场景 | 自查动作 |
|
|
119
|
+
| :--- | :--- | :--- |
|
|
120
|
+
| **Tier 1(轻量专项)** | 单点参数透传修改、单路由/单分支新增或局部逻辑调整 | 核对参数全链路透传(Schema → 分发器 → 工厂/执行器)与单分支可达性,跑通对应 L1 局部检查与 L2 定向契约测试。 |
|
|
121
|
+
| **Tier 2(全局自查)** | 新增/重构注册表、跨模块/跨端契约变更、动态加载区调整或发布前验收 | 执行全量 **注册表双向差集**(含反向幽灵工具拦截)、全仓 **孤儿扫描**(`lab orphan scan`)、**动态加载盲区定性隔离**(历史盲区显式标注,禁用原型文件头打标 `[实验态/禁止接入]`)与 **跨端 SSOT 对账**,并跑通 L1 + L2(含 `--verify-mutations`)全量串联。 |
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## 7. Agent 自主识别与呈批开单协议
|
|
126
|
+
|
|
127
|
+
Agent 在执行研发或审计任务中发现未接线或假接线时,必须按归属边界分类处置:
|
|
128
|
+
|
|
129
|
+
1. **本任务新引入断链**:必须**当场修完并复测**(跑通 L1 + L2 正反双向实测),严禁带病提交或仅靠口头说明收尾。
|
|
130
|
+
2. **越界 / 历史 / 跨端未接线或假接线**:**严禁静默跳过**,也**严禁越界硬改**;必须在收尾汇报中附带 **`文件:行号` + L1/L2 复现证据**,主动询问人类是否执行 `baton new` 开立专项整改工单。
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## 8. 新项目 `AGENTS.md` / `GEMINI.md` 接入规范与模板
|
|
135
|
+
|
|
136
|
+
* **创建时机与职责分工**:
|
|
137
|
+
* **何时创建**:仅在**已有真实业务代码的下游消费方仓**(或新项目完成骨架搭建、已存在首个真实注册表/路由/入口与唯一运行时后)创建;**全局安装/升级 `lab-agent-toolkit` 本身或 0 代码空目录严禁创建或强填 `<...>` 占位符**。
|
|
138
|
+
* **由谁创建**:一般由**消费方项目的 Agent** 结合本仓真实目录与运行时路径负责创建并自检,不通过中央脚手架硬编码注入。
|
|
139
|
+
* **SSOT 原则**:业务仓库**不得复制**本单元或 Playbook 的长篇方法论,只放极简本地路由映射(`AGENTS.md` 分级自查段 **`<= 12` 行**、`GEMINI.md` 执行守卫段 **`<= 6` 行**),并保留 `$(lab path orphan)/README.md` 指针。
|
|
140
|
+
* **标准复制模板与 4 项初始化验收清单**(行数预算、路径真实性、`preflight.conf` L1+L2 串联、`pre-commit` SAST 挂载):完整模板见 [`templates/wiring/project-agents-gemini-templates.md`](./templates/wiring/project-agents-gemini-templates.md)。
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
*完整技术细节、业界横向对比矩阵与算法伪代码请参阅 [DESIGN.md](./DESIGN.md)。*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v1.4.2 — 2026-11-22
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Android Stack Adapter for units/orphan
|
|
3
|
+
*
|
|
4
|
+
* 核心特性:
|
|
5
|
+
* 1. AndroidManifest.xml 组件保护与入口提取 (Application, Activity, Service, Receiver, Provider);
|
|
6
|
+
* 2. Qualifier 族成对性 (Qualifier Family Pairing):
|
|
7
|
+
* 成对的多分辨率/夜间模式资源 (drawable-hdpi, drawable-xxhdpi, layout-land 等) 汇聚为单一资源符号,
|
|
8
|
+
* 只要一处使用,全族受保护;全无引用时,全族作为孤儿集合上报;
|
|
9
|
+
* 3. @Keep / tools:keep / tools:ignore 声明保护与反射 (getIdentifier) Fail-Closed 降级。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
|
|
14
|
+
export class AndroidAdapter {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.id = 'android';
|
|
17
|
+
this.name = 'Android Stack Adapter';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 探测是否为 Android 仓库
|
|
22
|
+
* @param {import('../../core/blob-reader.mjs').BlobReader} reader
|
|
23
|
+
* @returns {boolean}
|
|
24
|
+
*/
|
|
25
|
+
detect(reader) {
|
|
26
|
+
const blobs = reader.listBlobs();
|
|
27
|
+
return blobs.some(b =>
|
|
28
|
+
b.path.endsWith('AndroidManifest.xml') ||
|
|
29
|
+
b.path.includes('/res/layout') ||
|
|
30
|
+
b.path.includes('/res/drawable')
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 提取 Android 根入口
|
|
36
|
+
* @param {import('../../core/blob-reader.mjs').BlobReader} reader
|
|
37
|
+
* @returns {Array<{ name: string, path: string, type: string }>}
|
|
38
|
+
*/
|
|
39
|
+
extractEntrypoints(reader) {
|
|
40
|
+
const entrypoints = [];
|
|
41
|
+
const manifests = reader.listBlobs(p => p.endsWith('AndroidManifest.xml'));
|
|
42
|
+
|
|
43
|
+
for (const m of manifests) {
|
|
44
|
+
const xml = reader.readBlobText(m.path);
|
|
45
|
+
// 提取 application android:name
|
|
46
|
+
const appMatch = xml.match(/<application[^>]*android:name=["']([^"']+)["']/);
|
|
47
|
+
if (appMatch) {
|
|
48
|
+
entrypoints.push({ name: appMatch[1], path: m.path, type: 'Application' });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 提取 activity, service, receiver, provider
|
|
52
|
+
const compRegex = /<(activity|service|receiver|provider)[^>]*android:name=["']([^"']+)["']/g;
|
|
53
|
+
let match;
|
|
54
|
+
while ((match = compRegex.exec(xml)) !== null) {
|
|
55
|
+
entrypoints.push({
|
|
56
|
+
type: match[1],
|
|
57
|
+
name: match[2],
|
|
58
|
+
path: m.path,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return entrypoints;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 提取 Android 候选资源并进行 Qualifier 族聚合
|
|
68
|
+
* @param {import('../../core/blob-reader.mjs').BlobReader} reader
|
|
69
|
+
* @returns {Array<{
|
|
70
|
+
* id: string,
|
|
71
|
+
* name: string,
|
|
72
|
+
* resType: string,
|
|
73
|
+
* symbol: string,
|
|
74
|
+
* qualifierPaths: string[],
|
|
75
|
+
* primaryPath: string,
|
|
76
|
+
* lineNo: number,
|
|
77
|
+
* isFamily: boolean
|
|
78
|
+
* }>}
|
|
79
|
+
*/
|
|
80
|
+
extractCandidates(reader) {
|
|
81
|
+
// 匹配 res/{resType}-{qualifiers}/{resName}.{ext} 或 res/{resType}/{resName}.{ext}
|
|
82
|
+
const RES_PATH_RE = /(?:^|\/)res\/([a-z]+)(?:-[a-zA-Z0-9_-]+)?\/([a-zA-Z0-9_]+)\.[a-zA-Z0-9]+$/;
|
|
83
|
+
|
|
84
|
+
const blobs = reader.listBlobs(p => p.includes('/res/'));
|
|
85
|
+
/** @type {Map<string, { resType: string, name: string, paths: string[] }>} */
|
|
86
|
+
const families = new Map();
|
|
87
|
+
|
|
88
|
+
for (const b of blobs) {
|
|
89
|
+
const m = b.path.match(RES_PATH_RE);
|
|
90
|
+
if (!m) continue;
|
|
91
|
+
|
|
92
|
+
const resType = m[1]; // layout, drawable, mipmap, anim, raw, menu, etc.
|
|
93
|
+
const name = m[2]; // resource name
|
|
94
|
+
|
|
95
|
+
// values 目录下的细粒度词条暂不以单文件为单位,排除 values
|
|
96
|
+
if (resType.startsWith('values')) continue;
|
|
97
|
+
|
|
98
|
+
const key = `${resType}:${name}`;
|
|
99
|
+
let fam = families.get(key);
|
|
100
|
+
if (!fam) {
|
|
101
|
+
fam = { resType, name, paths: [] };
|
|
102
|
+
families.set(key, fam);
|
|
103
|
+
}
|
|
104
|
+
fam.paths.push(b.path);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const candidates = [];
|
|
108
|
+
for (const [key, fam] of families.entries()) {
|
|
109
|
+
const symbol = `R.${fam.resType}.${fam.name}`;
|
|
110
|
+
candidates.push({
|
|
111
|
+
id: `orphan-android-${fam.resType}-${fam.name}`,
|
|
112
|
+
name: fam.name,
|
|
113
|
+
resType: fam.resType,
|
|
114
|
+
symbol,
|
|
115
|
+
qualifierPaths: fam.paths,
|
|
116
|
+
primaryPath: fam.paths[0],
|
|
117
|
+
lineNo: 1,
|
|
118
|
+
isFamily: fam.paths.length > 1,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return candidates;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* 检查代码中是否存在动态反射加载资源风险 (Fail-Closed)
|
|
127
|
+
* @param {import('../../core/blob-reader.mjs').BlobReader} reader
|
|
128
|
+
* @returns {boolean}
|
|
129
|
+
*/
|
|
130
|
+
detectReflectionUsage(reader) {
|
|
131
|
+
const codeBlobs = reader.listBlobs(p => p.endsWith('.kt') || p.endsWith('.java'));
|
|
132
|
+
for (const b of codeBlobs) {
|
|
133
|
+
const text = reader.readBlobText(b.path);
|
|
134
|
+
if (text.includes('getIdentifier(') || text.includes('Class.forName(') && text.includes('$R$')) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Python Stack Adapter for units/orphan
|
|
3
|
+
*
|
|
4
|
+
* 核心特性:
|
|
5
|
+
* 1. AST / 正则符号提取 (top-level functions, classes, constants);
|
|
6
|
+
* 2. `__all__` 显式导出列表保护;
|
|
7
|
+
* 3. pytest 测试发现机制保护 (test_* 函数, Test* 类, @pytest.fixture);
|
|
8
|
+
* 4. 魔术方法保护 (__init__, __repr__, __str__ 等);
|
|
9
|
+
* 5. Web 框架路由保护 (@app.*, @router.*, @bp.*, @click.*, @cli.*);
|
|
10
|
+
* 6. 动态调用 (getattr, setattr, importlib) Fail-Closed 降级。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
|
|
15
|
+
export class PythonAdapter {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.id = 'python';
|
|
18
|
+
this.name = 'Python Stack Adapter';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 探测是否为 Python 项目
|
|
23
|
+
* @param {import('../../core/blob-reader.mjs').BlobReader} reader
|
|
24
|
+
* @returns {boolean}
|
|
25
|
+
*/
|
|
26
|
+
detect(reader) {
|
|
27
|
+
const blobs = reader.listBlobs();
|
|
28
|
+
return blobs.some(b =>
|
|
29
|
+
b.path.endsWith('.py') ||
|
|
30
|
+
b.path.endsWith('pyproject.toml') ||
|
|
31
|
+
b.path.endsWith('setup.py') ||
|
|
32
|
+
b.path.endsWith('requirements.txt')
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 提取 Python 根入口 (pyproject.toml scripts, setup.py console_scripts, __main__.py)
|
|
38
|
+
* @param {import('../../core/blob-reader.mjs').BlobReader} reader
|
|
39
|
+
* @returns {Array<{ name: string, path: string, type: string }>}
|
|
40
|
+
*/
|
|
41
|
+
extractEntrypoints(reader) {
|
|
42
|
+
const entrypoints = [];
|
|
43
|
+
const pyprojectBlobs = reader.listBlobs(p => p.endsWith('pyproject.toml'));
|
|
44
|
+
for (const b of pyprojectBlobs) {
|
|
45
|
+
const text = reader.readBlobText(b.path);
|
|
46
|
+
// 匹配 scripts: name = "module:func"
|
|
47
|
+
const scriptSectionMatch = text.match(/\[(?:project\.scripts|tool\.poetry\.scripts)\]([\s\S]*?)(?:\[|$)/);
|
|
48
|
+
if (scriptSectionMatch) {
|
|
49
|
+
const lines = scriptSectionMatch[1].split('\n');
|
|
50
|
+
for (const line of lines) {
|
|
51
|
+
const m = line.match(/^\s*([a-zA-Z0-9_-]+)\s*=\s*["']([^"']+)["']/);
|
|
52
|
+
if (m) {
|
|
53
|
+
entrypoints.push({ name: m[1], target: m[2], path: b.path, type: 'ProjectScript' });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const mainBlobs = reader.listBlobs(p => p.endsWith('__main__.py') || p === 'app.py' || p === 'main.py');
|
|
60
|
+
for (const b of mainBlobs) {
|
|
61
|
+
entrypoints.push({ name: path.basename(b.path), path: b.path, type: 'MainExecutable' });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return entrypoints;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 提取 Python 符号声明及豁免/保护标记
|
|
69
|
+
* @param {import('../../core/blob-reader.mjs').BlobReader} reader
|
|
70
|
+
* @returns {Array<{
|
|
71
|
+
* id: string,
|
|
72
|
+
* name: string,
|
|
73
|
+
* symbol: string,
|
|
74
|
+
* primaryPath: string,
|
|
75
|
+
* lineNo: number,
|
|
76
|
+
* kind: string,
|
|
77
|
+
* isProtected?: boolean,
|
|
78
|
+
* protectionReason?: string
|
|
79
|
+
* }>}
|
|
80
|
+
*/
|
|
81
|
+
extractCandidates(reader) {
|
|
82
|
+
const pyBlobs = reader.listBlobs(p =>
|
|
83
|
+
p.endsWith('.py') &&
|
|
84
|
+
!p.includes('/site-packages/') &&
|
|
85
|
+
!p.includes('/.venv/') &&
|
|
86
|
+
!p.includes('/venv/') &&
|
|
87
|
+
!p.includes('/__pycache__/')
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const candidates = [];
|
|
91
|
+
|
|
92
|
+
for (const b of pyBlobs) {
|
|
93
|
+
const text = reader.readBlobText(b.path);
|
|
94
|
+
if (!text) continue;
|
|
95
|
+
|
|
96
|
+
const lines = text.split(/\r?\n/);
|
|
97
|
+
const isTestFile = b.path.includes('test_') || b.path.includes('_test.py') || b.path.includes('/tests/');
|
|
98
|
+
|
|
99
|
+
// 1. 提取 __all__ 声明的保护名单
|
|
100
|
+
const allExportedNames = new Set();
|
|
101
|
+
const allMatch = text.match(/__all__\s*=\s*[[({]([\s\S]*?)[\])}]/);
|
|
102
|
+
if (allMatch) {
|
|
103
|
+
const items = allMatch[1].match(/["']([a-zA-Z0-9_]+)["']/g);
|
|
104
|
+
if (items) {
|
|
105
|
+
for (const it of items) {
|
|
106
|
+
allExportedNames.add(it.replace(/["']/g, ''));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// 2. 逐行提取顶层定义 (函数, 类, 装饰器)
|
|
112
|
+
let prevDecorator = '';
|
|
113
|
+
for (let i = 0; i < lines.length; i++) {
|
|
114
|
+
const line = lines[i];
|
|
115
|
+
const lineNo = i + 1;
|
|
116
|
+
const trimmed = line.trim();
|
|
117
|
+
|
|
118
|
+
if (trimmed.startsWith('@')) {
|
|
119
|
+
prevDecorator = trimmed;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// 顶层函数: def func(...) 或 async def func(...)
|
|
124
|
+
const funcMatch = line.match(/^(?:async\s+)?def\s+([a-zA-Z0-9_]+)\s*\(/);
|
|
125
|
+
if (funcMatch) {
|
|
126
|
+
const name = funcMatch[1];
|
|
127
|
+
let isProtected = false;
|
|
128
|
+
let protectionReason = '';
|
|
129
|
+
|
|
130
|
+
// 规则 1: __all__ 导出保护
|
|
131
|
+
if (allExportedNames.has(name)) {
|
|
132
|
+
isProtected = true;
|
|
133
|
+
protectionReason = 'Protected: Explicitly exported in __all__';
|
|
134
|
+
}
|
|
135
|
+
// 规则 2: pytest 测试发现机制保护 (test_* 函数 或 @pytest.fixture)
|
|
136
|
+
else if (name.startsWith('test_') || (isTestFile && name.startsWith('test_')) || prevDecorator.includes('@pytest.fixture')) {
|
|
137
|
+
isProtected = true;
|
|
138
|
+
protectionReason = 'Protected: Pytest test function or fixture';
|
|
139
|
+
}
|
|
140
|
+
// 规则 3: 魔术方法 (__init__, __str__, __repr__ 等)
|
|
141
|
+
else if (/^__[a-zA-Z0-9_]+__$/.test(name)) {
|
|
142
|
+
isProtected = true;
|
|
143
|
+
protectionReason = 'Protected: Python magic method';
|
|
144
|
+
}
|
|
145
|
+
// 规则 4: Web 框架路由或 CLI 装饰器 (@app.*, @router.*, @bp.*, @click.*)
|
|
146
|
+
else if (
|
|
147
|
+
prevDecorator.startsWith('@app.') ||
|
|
148
|
+
prevDecorator.startsWith('@router.') ||
|
|
149
|
+
prevDecorator.startsWith('@bp.') ||
|
|
150
|
+
prevDecorator.startsWith('@click.') ||
|
|
151
|
+
prevDecorator.startsWith('@cli.') ||
|
|
152
|
+
prevDecorator.startsWith('@celery.')
|
|
153
|
+
) {
|
|
154
|
+
isProtected = true;
|
|
155
|
+
protectionReason = `Protected: Framework route/command decorator (${prevDecorator})`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
candidates.push({
|
|
159
|
+
id: `orphan-py-func-${path.basename(b.path, '.py')}-${name}`,
|
|
160
|
+
name,
|
|
161
|
+
symbol: name,
|
|
162
|
+
primaryPath: b.path,
|
|
163
|
+
qualifierPaths: [b.path],
|
|
164
|
+
lineNo,
|
|
165
|
+
kind: 'function',
|
|
166
|
+
isProtected,
|
|
167
|
+
protectionReason,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
prevDecorator = '';
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// 顶层类: class ClassName(...)
|
|
175
|
+
const classMatch = line.match(/^class\s+([a-zA-Z0-9_]+)(?:\s*\(|:)/);
|
|
176
|
+
if (classMatch) {
|
|
177
|
+
const name = classMatch[1];
|
|
178
|
+
let isProtected = false;
|
|
179
|
+
let protectionReason = '';
|
|
180
|
+
|
|
181
|
+
if (allExportedNames.has(name)) {
|
|
182
|
+
isProtected = true;
|
|
183
|
+
protectionReason = 'Protected: Explicitly exported in __all__';
|
|
184
|
+
} else if (isTestFile && name.startsWith('Test')) {
|
|
185
|
+
isProtected = true;
|
|
186
|
+
protectionReason = 'Protected: Pytest test class';
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
candidates.push({
|
|
190
|
+
id: `orphan-py-class-${path.basename(b.path, '.py')}-${name}`,
|
|
191
|
+
name,
|
|
192
|
+
symbol: name,
|
|
193
|
+
primaryPath: b.path,
|
|
194
|
+
qualifierPaths: [b.path],
|
|
195
|
+
lineNo,
|
|
196
|
+
kind: 'class',
|
|
197
|
+
isProtected,
|
|
198
|
+
protectionReason,
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
prevDecorator = '';
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
prevDecorator = '';
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return candidates;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* 检查是否包含 getattr / setattr / importlib 等动态反射加载模式 (Fail-Closed)
|
|
214
|
+
* @param {import('../../core/blob-reader.mjs').BlobReader} reader
|
|
215
|
+
* @returns {boolean}
|
|
216
|
+
*/
|
|
217
|
+
detectReflectionUsage(reader) {
|
|
218
|
+
const pyBlobs = reader.listBlobs(p => p.endsWith('.py'));
|
|
219
|
+
for (const b of pyBlobs) {
|
|
220
|
+
const text = reader.readBlobText(b.path);
|
|
221
|
+
if (
|
|
222
|
+
text.includes('getattr(') ||
|
|
223
|
+
text.includes('setattr(') ||
|
|
224
|
+
text.includes('importlib.import_module(') ||
|
|
225
|
+
text.includes('__import__(')
|
|
226
|
+
) {
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
}
|