focus-guard 3.0.7 → 3.4.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/LICENSE +683 -21
- package/NOTICE +25 -0
- package/README.md +14 -9
- package/README.zh-CN.md +12 -9
- package/docs/AB-PROMPTS.md +123 -0
- package/docs/AB-SESSION.md +161 -0
- package/docs/ARCH-MAP.md +148 -0
- package/docs/BENCH-BASELINE.json +95 -0
- package/docs/BENCH.md +323 -0
- package/docs/GATE-INPUTS.json +10 -0
- package/docs/HANDOFF-2026-10-27.md +736 -0
- package/docs/HOOK-ORDERING.md +139 -0
- package/docs/LEGISLATION-LAW.md +4 -2
- package/docs/MCP-4.0-PLAN.md +184 -0
- package/docs/MEMORY-4.5-PLAN.md +415 -0
- package/docs/PROFILE-TUNING.md +147 -0
- package/docs/RATCHET.json +48 -0
- package/docs/RELEASE-POLICY.md +163 -0
- package/docs/RULES.md +95 -14
- package/docs/THREAT-MODEL.md +68 -0
- package/docs/TOOL-SCHEMA.json +6 -0
- package/docs/VERSION-PLAN.md +532 -0
- package/docs/WRITING-STYLE.md +109 -0
- package/docs/architecture-map.mermaid +186 -0
- package/docs/deepseek-pricing-audit.md +2 -0
- package/hooks/guard.mjs +92 -56
- package/package.json +34 -5
- package/skills/focus-thinking/SKILL.md +9 -7
- package/src/adapters/dsh/eligibility-gate.mjs +446 -23
- package/src/adapters/dsh/tool-kinds.mjs +81 -0
- package/src/core/approval.mjs +2 -8
- package/src/core/approvals.mjs +208 -0
- package/src/core/audit-writer.mjs +297 -0
- package/src/core/audit.mjs +46 -16
- package/src/core/backup.mjs +37 -11
- package/src/core/checkEligibility.mjs +7 -4
- package/src/core/constants.mjs +67 -22
- package/src/core/decisionEngine.mjs +12 -0
- package/src/core/env.mjs +147 -19
- package/src/core/grants.mjs +54 -13
- package/src/core/kpi.mjs +16 -0
- package/src/core/outputGate.mjs +77 -0
- package/src/core/patterns.mjs +129 -0
- package/src/core/prefixStability.mjs +143 -0
- package/src/core/profileLoader.mjs +40 -5
- package/src/core/progressPolicy.mjs +65 -0
- package/src/core/redlines.mjs +49 -5
- package/src/core/risk.mjs +94 -15
- package/src/core/schemaDrift.mjs +125 -0
- package/src/core/sessionScratch.mjs +147 -0
- package/src/core/stageGraph.mjs +104 -0
- package/src/core/staleCleanup.mjs +153 -0
- package/src/core/state.mjs +215 -81
- package/src/core/stopPolicy.mjs +97 -0
- package/src/core/tempPath.mjs +23 -0
- package/src/dsh/audit.mjs +168 -118
- package/src/dsh/compactionWatch/announce.mjs +117 -0
- package/src/dsh/compactionWatch.mjs +68 -153
- package/src/dsh/guard/authz.mjs +97 -0
- package/src/dsh/guard/evidence.mjs +308 -0
- package/src/dsh/guard/hardCheck.mjs +85 -0
- package/src/dsh/guard/redline.mjs +62 -0
- package/src/dsh/guard/risk.mjs +196 -0
- package/src/dsh/guard/runtime.mjs +162 -0
- package/src/dsh/guard/superpowers.mjs +70 -0
- package/src/dsh/guard/tooling.mjs +177 -0
- package/src/dsh/guard/volume.mjs +181 -0
- package/src/dsh/guard/wholeFile.mjs +109 -0
- package/src/dsh/heartbeat.mjs +76 -13
- package/src/dsh/hookOrder.mjs +101 -0
- package/src/dsh/index.js +247 -15
- package/src/dsh/pipeline.mjs +77 -854
- package/src/dsh/policy-audit.mjs +84 -0
- package/src/dsh/postProgress.mjs +400 -274
- package/src/dsh/preGuard.mjs +249 -228
- package/src/dsh/repeatGuard.mjs +98 -0
- package/src/dsh/seams/pre-step.mjs +186 -0
- package/src/dsh/seams/prompt-rules.mjs +59 -0
- package/src/dsh/seams/session-start.mjs +297 -0
- package/src/dsh/seams/shared.mjs +109 -0
- package/src/dsh/seams.mjs +95 -408
- package/src/dsh/search-hints.mjs +136 -0
- package/src/dsh/sessionScope.mjs +28 -0
- package/src/dsh/status.mjs +7 -0
- package/src/dsh/stopGuard.mjs +225 -164
- package/src/dsh/testRuntime.mjs +62 -0
- package/src/dsh/toolKindAudit.mjs +66 -0
- package/src/dsh/tools.mjs +81 -5
- package/src/dsh/traceMeta.mjs +125 -0
- package/src/dsh/value-gate.mjs +93 -0
- package/src/dsh/workspace.mjs +3 -143
- package/src/memory/index.mjs +15 -0
- package/src/memory/tags.mjs +30 -0
- package/src/memory/workspace.mjs +283 -0
- package/src/peak-cost.mjs +1 -1
- package/src/profiles/deepseek-flash.mjs +7 -1
- package/src/profiles/deepseek-pro.mjs +6 -1
- package/src/profiles/default.mjs +6 -1
- package/src/profiles/glm.mjs +6 -1
- package/src/profiles/gpt-astra.mjs +6 -1
- package/tools/bench-ab.mjs +240 -0
- package/tools/bench-cost.mjs +176 -0
- package/tools/brain-cosmic.mjs +43 -0
- package/tools/brain-view.html +853 -0
- package/tools/brain.mjs +317 -0
- package/tools/capture-fixtures.mjs +182 -0
- package/tools/case-audit.mjs +114 -0
- package/tools/collect-panel.mjs +218 -0
- package/tools/dead-export.mjs +60 -0
- package/tools/docs-lint.mjs +82 -0
- package/tools/env-fingerprint.mjs +126 -33
- package/tools/first-run-sweep.mjs +123 -0
- package/tools/focusguard.mjs +155 -0
- package/tools/gate-audit.mjs +140 -0
- package/tools/gate-inputs.mjs +115 -0
- package/tools/handoff.mjs +56 -0
- package/tools/health.mjs +182 -0
- package/tools/knowledge.mjs +118 -0
- package/tools/layering-audit.mjs +105 -0
- package/tools/lib/book-style.mjs +136 -0
- package/tools/lib/brain-core.mjs +342 -0
- package/tools/lib/brain-docs.mjs +293 -0
- package/tools/lib/brain-regions.mjs +169 -0
- package/tools/lib/brain-relate.mjs +235 -0
- package/tools/lib/brain-text.mjs +121 -0
- package/tools/lib/case-tool.mjs +186 -0
- package/tools/lib/docs-core.mjs +392 -0
- package/tools/lib/docs-version.mjs +66 -0
- package/tools/lib/envMap.mjs +31 -0
- package/tools/lib/health-core.mjs +94 -0
- package/tools/lib/import-graph.mjs +118 -0
- package/tools/lib/index-io.mjs +70 -0
- package/tools/lib/open.mjs +32 -0
- package/tools/lib/prefix-cost.mjs +143 -0
- package/tools/lib/ratchet.mjs +174 -0
- package/tools/lib/reach.mjs +28 -0
- package/tools/lib/sessionDump.mjs +80 -0
- package/tools/lib/source-text.mjs +112 -0
- package/tools/library-book.mjs +313 -0
- package/tools/library-build.mjs +50 -12
- package/tools/library-index.mjs +91 -0
- package/tools/lint.mjs +282 -0
- package/tools/log-audit.mjs +108 -0
- package/tools/manifest-sync.mjs +111 -0
- package/tools/memory-audit.mjs +67 -0
- package/tools/module-audit.mjs +56 -0
- package/tools/mutate.mjs +316 -0
- package/tools/prefix-audit.mjs +122 -0
- package/tools/prefix-drift.mjs +325 -0
- package/tools/privacy-guard.mjs +352 -0
- package/tools/quality-audit.mjs +166 -0
- package/tools/schema-fingerprint.mjs +191 -0
- package/{src/dsh → tools}/selftest.mjs +75 -22
- package/tools/smells.mjs +398 -0
- package/tools/verify-case-paths.mjs +93 -0
- package/tools/version.mjs +191 -0
- package/docs/MASTER-PLAN-2.0.0.md +0 -133
- package/docs/MASTER-PLAN-3.0.0.md +0 -76
- package/src/adapters/dsh/fg-appeal-tool.mjs +0 -47
- package/src/adapters/dsh/fg-apply-tool.mjs +0 -68
- /package/{src/adapters/dsh → hooks}/protocol.mjs +0 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 策略可达性自检(Policy Self-Audit,2026-10-24)
|
|
3
|
+
*
|
|
4
|
+
* 背景:2026-10-22 用真实会话发现三条闸**永不触发**(`args.output_mode`/`args.pages` 在新宿主 schema 里
|
|
5
|
+
* 根本不存在)。那类失效的特点是:测试全绿、线上全漏——因为测试用的是合成参数。
|
|
6
|
+
*
|
|
7
|
+
* 本模块把那次人工排查变成**启动自检**:
|
|
8
|
+
* ① 从判定源码里抽出引用的参数键(`args.X` / `arguments.X` / `ti.X`);
|
|
9
|
+
* ② 与当前会话真实的工具 schema(`ctx.tools.schemas()`)求差;
|
|
10
|
+
* ③ 只报警(warn + 审计行),**不改变任何判定**。
|
|
11
|
+
*
|
|
12
|
+
* 只读、幂等、失败 sink 到 warn——不影响执法缝。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { readFileSync } from 'node:fs'
|
|
16
|
+
|
|
17
|
+
const KEY_RE = /\b(?:args|arguments|ti)\.([A-Za-z_$][\w$]*)/g
|
|
18
|
+
|
|
19
|
+
/** 从源码文本里抽参数键 → 出处行号。 */
|
|
20
|
+
export function referencedKeysOf(sourceText, label = '') {
|
|
21
|
+
const out = new Map()
|
|
22
|
+
sourceText.split('\n').forEach((line, idx) => {
|
|
23
|
+
if (/^\s*(\*|\/\/)/.test(line)) return // 注释不算(避免把说明文字当引用)
|
|
24
|
+
for (const m of line.matchAll(KEY_RE)) {
|
|
25
|
+
const key = m[1]
|
|
26
|
+
if (!out.has(key)) out.set(key, [])
|
|
27
|
+
out.get(key).push(`${label}:${idx + 1}`)
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
return out
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 从 `ctx.tools.schemas()` 的结果里取参数键并集。 */
|
|
34
|
+
export function schemaKeysOf(schemas = []) {
|
|
35
|
+
const keys = new Set()
|
|
36
|
+
for (const s of schemas || []) {
|
|
37
|
+
const props = (s && s.parameters && s.parameters.properties) || {}
|
|
38
|
+
for (const k of Object.keys(props)) keys.add(k)
|
|
39
|
+
}
|
|
40
|
+
return keys
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 计算不可达键(引用了但真实 schema 里没有)。
|
|
45
|
+
* @param {{ files: Array<{label: string, text: string}>, schemaKeys: Set<string>, ignore?: string[] }} input
|
|
46
|
+
* @returns {{ ghost: Array<{key: string, sites: string[]}>, reachable: string[], scanned: number }}
|
|
47
|
+
*/
|
|
48
|
+
export function auditReachability({ files = [], schemaKeys = new Set(), ignore = [] }) {
|
|
49
|
+
const skip = new Set(ignore)
|
|
50
|
+
const refs = new Map()
|
|
51
|
+
for (const f of files) {
|
|
52
|
+
for (const [k, sites] of referencedKeysOf(f.text, f.label)) {
|
|
53
|
+
const cur = refs.get(k) || []
|
|
54
|
+
refs.set(k, [...cur, ...sites])
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const ghost = []
|
|
58
|
+
const reachable = []
|
|
59
|
+
for (const [key, sites] of refs) {
|
|
60
|
+
if (skip.has(key)) continue
|
|
61
|
+
if (schemaKeys.has(key)) reachable.push(key)
|
|
62
|
+
else ghost.push({ key, sites: sites.slice(0, 5) })
|
|
63
|
+
}
|
|
64
|
+
ghost.sort((a, b) => a.key.localeCompare(b.key))
|
|
65
|
+
reachable.sort()
|
|
66
|
+
return { ghost, reachable, scanned: refs.size }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 运行时入口:读判定源码 + 当前 schema,返回报告。
|
|
71
|
+
* @param {{ schemas: any[], files?: string[], ignore?: string[] }} opts
|
|
72
|
+
*/
|
|
73
|
+
export function runPolicyAudit({ schemas = [], files, ignore = [] } = {}) {
|
|
74
|
+
const targets = files || []
|
|
75
|
+
const loaded = []
|
|
76
|
+
for (const f of targets) {
|
|
77
|
+
try {
|
|
78
|
+
loaded.push({ label: f.split(/[\\/]/).slice(-2).join('/'), text: readFileSync(f, 'utf8') })
|
|
79
|
+
} catch {
|
|
80
|
+
/* 读不到就跳过(打包/裁剪环境下正常) */
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return auditReachability({ files: loaded, schemaKeys: schemaKeysOf(schemas), ignore })
|
|
84
|
+
}
|