@principles/host-runtime 4.12.0 → 5.1.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/dist/atomic-write-file.d.ts +1 -0
- package/dist/atomic-write-file.js +100 -0
- package/dist/codex-disclosure.d.ts +1 -1
- package/dist/codex-disclosure.js +1 -1
- package/dist/correction-cue-learner.d.ts +69 -0
- package/dist/correction-cue-learner.js +366 -0
- package/dist/correction-observer-config.d.ts +21 -0
- package/dist/correction-observer-config.js +55 -0
- package/dist/correction-observer-cycle.d.ts +33 -0
- package/dist/correction-observer-cycle.js +255 -0
- package/dist/correction-trajectory-reader.d.ts +35 -0
- package/dist/correction-trajectory-reader.js +113 -0
- package/dist/diagnostician-auto-run.d.ts +1 -1
- package/dist/diagnostician-auto-run.js +15 -1
- package/dist/governance-signal-admission.js +25 -3
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/dist/keyword-optimization-service.d.ts +73 -0
- package/dist/keyword-optimization-service.js +265 -0
- package/dist/pain-inbox.d.ts +8 -0
- package/dist/pain-inbox.js +115 -1
- package/dist/production-rulehost-gate.js +0 -19
- package/dist/signal-health.d.ts +54 -0
- package/dist/signal-health.js +194 -0
- package/dist/workspace-pipeline-host-deps.d.ts +2 -0
- package/dist/workspace-pipeline-host-deps.js +1 -1
- package/package.json +7 -3
- package/dist/legacy-rule-contract-symbols.d.ts +0 -20
- package/dist/legacy-rule-contract-symbols.js +0 -124
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PRI-788 G4: 纠正信号检测健康度产物。
|
|
3
|
+
*
|
|
4
|
+
* 背景:检测器停摆 5 天 409 次失败只进 7 天滚动的 SYSTEM log(ERR-101 家族),
|
|
5
|
+
* Owner 无从发现。本模块把检测链路的关键计数/时间戳原子写入
|
|
6
|
+
* `<workspace>/.state/signal-health.json`,供 `pd config doctor` 呈现。
|
|
7
|
+
*
|
|
8
|
+
* 契约:
|
|
9
|
+
* - 当日计数(stage1Strong/stage2Confirmed/stage2Queued/stage2Dropped/
|
|
10
|
+
* stage2Invocations/stage2BatchSkipped/stage2DiscoverySkipped)在跨日首次写入时归零;
|
|
11
|
+
* 时间戳字段为绝对 ISO 值。
|
|
12
|
+
* - 写失败绝不抛出(健康度是旁路观测,不阻塞检测管线)——通知宿主的可选错误处理(rc-9)。
|
|
13
|
+
* - 文件缺失/损坏按默认值重建,读取方(doctor)自行 unknown 呈现。
|
|
14
|
+
* - AUDIT-P2-02:stage2Invocations/stage2BatchSkipped 为新增字段,升级前的
|
|
15
|
+
* 旧文件缺这两个键仍合法(读作 0);写路径始终写入完整新格式。
|
|
16
|
+
* - 所有 I/O 路径先经 guardWorkspaceLeak:测试里 mock 的 '/fake/state' 在
|
|
17
|
+
* Windows 会被 resolve 成盘根 D:\fake\state,必须和其它 I/O 入口一样重定向
|
|
18
|
+
* 到 os.tmpdir(),否则每次跑测试都在文件系统根重建目录(含 mkdir)。
|
|
19
|
+
*/
|
|
20
|
+
import * as fs from 'fs';
|
|
21
|
+
import * as path from 'path';
|
|
22
|
+
import { atomicWriteFileSync } from './atomic-write-file.js';
|
|
23
|
+
import { guardWorkspaceLeak } from '@principles/core/runtime/store/workspace-leak-guard';
|
|
24
|
+
const SIGNAL_HEALTH_FILE = 'signal-health.json';
|
|
25
|
+
const CORRECTION_OBSERVER_HOSTS = ['openclaw', 'codex', 'workbuddy'];
|
|
26
|
+
function parseObserverInputDigests(value) {
|
|
27
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
28
|
+
return undefined;
|
|
29
|
+
const state = value;
|
|
30
|
+
const digests = {};
|
|
31
|
+
for (const hostKind of CORRECTION_OBSERVER_HOSTS) {
|
|
32
|
+
const digest = Object.hasOwn(state, hostKind) ? state[hostKind] : undefined;
|
|
33
|
+
if (typeof digest === 'string' && /^[a-f0-9]{64}$/.test(digest))
|
|
34
|
+
digests[hostKind] = digest;
|
|
35
|
+
}
|
|
36
|
+
return Object.keys(digests).length > 0 ? digests : undefined;
|
|
37
|
+
}
|
|
38
|
+
function defaultState(now) {
|
|
39
|
+
return {
|
|
40
|
+
stage1Strong: 0,
|
|
41
|
+
stage2Confirmed: 0,
|
|
42
|
+
stage2Queued: 0,
|
|
43
|
+
stage2Dropped: 0,
|
|
44
|
+
stage2Invocations: 0,
|
|
45
|
+
stage2BatchSkipped: 0,
|
|
46
|
+
stage2DiscoverySkipped: 0,
|
|
47
|
+
pendingCount: 0,
|
|
48
|
+
lastStage2SuccessAt: null,
|
|
49
|
+
observerLastSuccessAt: null,
|
|
50
|
+
observerConsecutiveFailures: 0,
|
|
51
|
+
day: now.toISOString().slice(0, 10),
|
|
52
|
+
updatedAt: now.toISOString(),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function healthFilePath(stateDir) {
|
|
56
|
+
return path.join(stateDir, SIGNAL_HEALTH_FILE);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 结构校验 + 解析:只接受带全部必需数值/字符串字段的对象(ERR-001/ERR-013),
|
|
60
|
+
* 并逐字段构造出完整的 SignalHealthState。
|
|
61
|
+
* 用 Object.hasOwn + typeof 做运行时收窄,避免 `in` 命中原型链、
|
|
62
|
+
* 也避免 `as` 把未校验数据直接断言成领域类型。
|
|
63
|
+
*
|
|
64
|
+
* AUDIT-P2-02 向后兼容规则:stage2Invocations / stage2BatchSkipped 是新增
|
|
65
|
+
* 字段——升级前的旧健康文件没有它们,必须照常解析(缺省读作 0),
|
|
66
|
+
* 否则升级会让 doctor 从「有计数」退化成 unknown。字段存在时仍必须是 number。
|
|
67
|
+
*/
|
|
68
|
+
function parseSignalHealthState(value) {
|
|
69
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const obj = value;
|
|
73
|
+
const requiredNum = (key) => {
|
|
74
|
+
if (!Object.hasOwn(obj, key))
|
|
75
|
+
return null;
|
|
76
|
+
const v = obj[key];
|
|
77
|
+
return typeof v === 'number' ? v : null;
|
|
78
|
+
};
|
|
79
|
+
const optionalNum = (key) => {
|
|
80
|
+
const v = obj[key];
|
|
81
|
+
return typeof v === 'number' ? v : 0;
|
|
82
|
+
};
|
|
83
|
+
const optionalStr = (key) => {
|
|
84
|
+
const v = obj[key];
|
|
85
|
+
return typeof v === 'string' ? v : null;
|
|
86
|
+
};
|
|
87
|
+
const stage1Strong = requiredNum('stage1Strong');
|
|
88
|
+
const stage2Confirmed = requiredNum('stage2Confirmed');
|
|
89
|
+
const stage2Queued = requiredNum('stage2Queued');
|
|
90
|
+
const stage2Dropped = requiredNum('stage2Dropped');
|
|
91
|
+
const pendingCount = requiredNum('pendingCount');
|
|
92
|
+
const observerConsecutiveFailures = requiredNum('observerConsecutiveFailures');
|
|
93
|
+
const day = optionalStr('day');
|
|
94
|
+
const updatedAt = optionalStr('updatedAt');
|
|
95
|
+
if (stage1Strong === null || stage2Confirmed === null || stage2Queued === null ||
|
|
96
|
+
stage2Dropped === null || pendingCount === null || observerConsecutiveFailures === null ||
|
|
97
|
+
day === null || updatedAt === null) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
// 新字段存在但非数值 → 视为损坏(与旧必需字段同一纪律)。
|
|
101
|
+
if (Object.hasOwn(obj, 'stage2Invocations') && typeof obj.stage2Invocations !== 'number')
|
|
102
|
+
return null;
|
|
103
|
+
if (Object.hasOwn(obj, 'stage2BatchSkipped') && typeof obj.stage2BatchSkipped !== 'number')
|
|
104
|
+
return null;
|
|
105
|
+
if (Object.hasOwn(obj, 'stage2DiscoverySkipped') && typeof obj.stage2DiscoverySkipped !== 'number')
|
|
106
|
+
return null;
|
|
107
|
+
const digests = parseObserverInputDigests(obj.observerInputDigests);
|
|
108
|
+
return {
|
|
109
|
+
stage1Strong,
|
|
110
|
+
stage2Confirmed,
|
|
111
|
+
stage2Queued,
|
|
112
|
+
stage2Dropped,
|
|
113
|
+
stage2Invocations: optionalNum('stage2Invocations'),
|
|
114
|
+
stage2BatchSkipped: optionalNum('stage2BatchSkipped'),
|
|
115
|
+
stage2DiscoverySkipped: optionalNum('stage2DiscoverySkipped'),
|
|
116
|
+
pendingCount,
|
|
117
|
+
lastStage2SuccessAt: optionalStr('lastStage2SuccessAt'),
|
|
118
|
+
observerLastSuccessAt: optionalStr('observerLastSuccessAt'),
|
|
119
|
+
...(digests === undefined ? {} : { observerInputDigests: digests }),
|
|
120
|
+
observerConsecutiveFailures,
|
|
121
|
+
day,
|
|
122
|
+
updatedAt,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function loadState(stateDir, now) {
|
|
126
|
+
try {
|
|
127
|
+
const raw = fs.readFileSync(healthFilePath(stateDir), 'utf-8');
|
|
128
|
+
const parsed = JSON.parse(raw);
|
|
129
|
+
const state = parseSignalHealthState(parsed);
|
|
130
|
+
if (state) {
|
|
131
|
+
const today = now.toISOString().slice(0, 10);
|
|
132
|
+
if (state.day !== today) {
|
|
133
|
+
// 跨日:当日计数归零(含 AUDIT-P2-02 新增计数),时间戳与失败计数保留
|
|
134
|
+
return {
|
|
135
|
+
...state,
|
|
136
|
+
stage1Strong: 0,
|
|
137
|
+
stage2Confirmed: 0,
|
|
138
|
+
stage2Queued: 0,
|
|
139
|
+
stage2Dropped: 0,
|
|
140
|
+
stage2Invocations: 0,
|
|
141
|
+
stage2BatchSkipped: 0,
|
|
142
|
+
stage2DiscoverySkipped: 0,
|
|
143
|
+
day: today,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return state;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
// 缺失/损坏 → 重建默认值(doctor 侧以 updatedAt/字段存在性呈现 unknown)
|
|
151
|
+
}
|
|
152
|
+
return defaultState(now);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* 读健康状态(doctor 用)。文件缺失/损坏返回 null,由读取方呈现 unknown。
|
|
156
|
+
* 旧格式(无 AUDIT-P2-02 新增计数字段)照常解析,缺省字段读作 0。
|
|
157
|
+
*/
|
|
158
|
+
export function readSignalHealth(stateDir) {
|
|
159
|
+
try {
|
|
160
|
+
const raw = fs.readFileSync(healthFilePath(guardWorkspaceLeak(stateDir)), 'utf-8');
|
|
161
|
+
const parsed = JSON.parse(raw);
|
|
162
|
+
return parseSignalHealthState(parsed);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
export function updateSignalHealth(stateDir, mutate, onError) {
|
|
169
|
+
// Guard BEFORE the mkdir — a leaked '/fake/state' must not recreate
|
|
170
|
+
// D:\fake\state on Windows. loadState / healthFilePath receive the same
|
|
171
|
+
// guarded dir, so read and write always agree on one location.
|
|
172
|
+
const safeStateDir = guardWorkspaceLeak(stateDir);
|
|
173
|
+
try {
|
|
174
|
+
const now = new Date();
|
|
175
|
+
const state = loadState(safeStateDir, now);
|
|
176
|
+
mutate(state);
|
|
177
|
+
state.updatedAt = now.toISOString();
|
|
178
|
+
state.day = now.toISOString().slice(0, 10);
|
|
179
|
+
fs.mkdirSync(safeStateDir, { recursive: true });
|
|
180
|
+
atomicWriteFileSync(healthFilePath(safeStateDir), JSON.stringify(state, null, 2));
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
// Without a concrete workspace, do not write an audit line to cwd.
|
|
184
|
+
// Reporting is best-effort too: an optional host callback cannot block detection.
|
|
185
|
+
if (safeStateDir) {
|
|
186
|
+
try {
|
|
187
|
+
onError?.(path.dirname(safeStateDir), err);
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
// The health write has already failed; keep the side channel non-blocking.
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
@@ -45,6 +45,8 @@ export interface ResolveWorkspacePipelineHostDepsInput {
|
|
|
45
45
|
readonly workspaceDir: string;
|
|
46
46
|
/** The CURRENT entry's effective config — the intent reader's flag authority (SPEC §13.1). */
|
|
47
47
|
readonly effectiveConfig: EffectivePdConfig;
|
|
48
|
+
/** Reuse the worker cycle's workspace-scoped, live consent port. */
|
|
49
|
+
readonly sourceMaterialAuthorization?: SourceMaterialAuthorizationPort;
|
|
48
50
|
/**
|
|
49
51
|
* OpenClaw Gateway hook / command processes already hold
|
|
50
52
|
* `WorkspaceContext.trajectory`; pass it here to replace the default
|
|
@@ -57,7 +57,7 @@ export function resolveWorkspacePipelineHostDeps(input) {
|
|
|
57
57
|
// trajectory reader and every gate consumer returned to the caller observe
|
|
58
58
|
// the SAME latest-consent state (the double-instance defect this module
|
|
59
59
|
// exists to remove).
|
|
60
|
-
const sourceMaterialAuthorization = createConsentLedgerSourceMaterialAuthorization(input.workspaceDir);
|
|
60
|
+
const sourceMaterialAuthorization = input.sourceMaterialAuthorization ?? createConsentLedgerSourceMaterialAuthorization(input.workspaceDir);
|
|
61
61
|
const overrideHostKind = input.trajectoryTurnReaderOverrideHostKind;
|
|
62
62
|
if (input.trajectoryTurnReaderOverride !== undefined && overrideHostKind === undefined) {
|
|
63
63
|
throw new Error('trajectoryTurnReaderOverrideHostKind is required when trajectoryTurnReaderOverride is provided');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/host-runtime",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Shared host-neutral orchestration for Principles Disciple MVP-Core hook paths.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
"default": "./dist/index.js"
|
|
12
12
|
},
|
|
13
13
|
"./package.json": "./package.json",
|
|
14
|
+
"./atomic-write-file": {
|
|
15
|
+
"types": "./dist/atomic-write-file.d.ts",
|
|
16
|
+
"default": "./dist/atomic-write-file.js"
|
|
17
|
+
},
|
|
14
18
|
"./behavior-example-pack-assembler": {
|
|
15
19
|
"types": "./dist/behavior-example-pack-assembler.d.ts",
|
|
16
20
|
"default": "./dist/behavior-example-pack-assembler.js"
|
|
@@ -39,7 +43,7 @@
|
|
|
39
43
|
"lint": "eslint \"src/**/*.ts\""
|
|
40
44
|
},
|
|
41
45
|
"dependencies": {
|
|
42
|
-
"@principles/core": "^
|
|
46
|
+
"@principles/core": "^10.0.1",
|
|
43
47
|
"@principles/install-layout": "^0.12.0",
|
|
44
48
|
"better-sqlite3": "^13.0.3",
|
|
45
49
|
"js-yaml": "^5.4.3"
|
|
@@ -57,5 +61,5 @@
|
|
|
57
61
|
"url": "git+https://github.com/csuzngjh/principles.git"
|
|
58
62
|
},
|
|
59
63
|
"license": "Apache-2.0",
|
|
60
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "a6798ad286b1584b8d6e2da6fd9b81e9b99609cf"
|
|
61
65
|
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retired RuleHost contract symbol scan — host-runtime local copy.
|
|
3
|
-
*
|
|
4
|
-
* The shared canonical scanner lives in @principles/core
|
|
5
|
-
* (internalization/legacy-rule-contract-scanner.ts) and is used by the
|
|
6
|
-
* plugin, console, installer, and pd-cli. This module deliberately does NOT
|
|
7
|
-
* import it: the published codex-adapter bundle installs host-runtime
|
|
8
|
-
* against the CURRENTLY PUBLISHED @principles/core from the npm registry,
|
|
9
|
-
* and a new runtime import would break clean installs until the next core
|
|
10
|
-
* release (see tests/published-codex-adapter-bundle.test.ts — it enforces
|
|
11
|
-
* exactly this constraint). Keep the symbol patterns in sync with the core
|
|
12
|
-
* scanner; the host-runtime tests cover the same detection behavior.
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Conservative scan of persisted RuleCode source for retired RuleHost
|
|
16
|
-
* contract symbols (field reads and helper calls). A hit means the rule must
|
|
17
|
-
* NOT execute against the current contract — its reads would silently
|
|
18
|
-
* resolve to undefined and change owner-approved behavior.
|
|
19
|
-
*/
|
|
20
|
-
export declare function scanRetiredContractSymbols(implementationCode: string): string[];
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retired RuleHost contract symbol scan — host-runtime local copy.
|
|
3
|
-
*
|
|
4
|
-
* The shared canonical scanner lives in @principles/core
|
|
5
|
-
* (internalization/legacy-rule-contract-scanner.ts) and is used by the
|
|
6
|
-
* plugin, console, installer, and pd-cli. This module deliberately does NOT
|
|
7
|
-
* import it: the published codex-adapter bundle installs host-runtime
|
|
8
|
-
* against the CURRENTLY PUBLISHED @principles/core from the npm registry,
|
|
9
|
-
* and a new runtime import would break clean installs until the next core
|
|
10
|
-
* release (see tests/published-codex-adapter-bundle.test.ts — it enforces
|
|
11
|
-
* exactly this constraint). Keep the symbol patterns in sync with the core
|
|
12
|
-
* scanner; the host-runtime tests cover the same detection behavior.
|
|
13
|
-
*/
|
|
14
|
-
// Helper-call form is listed before the bare-word form; the field pattern's
|
|
15
|
-
// negative lookahead prevents one hasPlanFile( call reporting twice.
|
|
16
|
-
const RETIRED_SYMBOL_PATTERNS = [
|
|
17
|
-
{ symbol: 'recentThinking', pattern: /\brecentThinking\b/ },
|
|
18
|
-
{ symbol: 'planStatus', pattern: /\bplanStatus\b/ },
|
|
19
|
-
{ symbol: 'getPlanStatus', pattern: /\bgetPlanStatus\s*\(/ },
|
|
20
|
-
{ symbol: 'hasPlanFileHelper', pattern: /\bhasPlanFile\s*\(/ },
|
|
21
|
-
{ symbol: 'hasPlanFile', pattern: /\bhasPlanFile\b(?!\s*\()/ },
|
|
22
|
-
];
|
|
23
|
-
function maskNonExecutableText(source) {
|
|
24
|
-
let state = 'code';
|
|
25
|
-
let templateExpressionDepth = 0;
|
|
26
|
-
let masked = '';
|
|
27
|
-
for (let index = 0; index < source.length; index += 1) {
|
|
28
|
-
const char = source[index] ?? '';
|
|
29
|
-
const next = source[index + 1] ?? '';
|
|
30
|
-
if (state === 'code') {
|
|
31
|
-
if (templateExpressionDepth > 0 && char === '{') {
|
|
32
|
-
templateExpressionDepth += 1;
|
|
33
|
-
masked += char;
|
|
34
|
-
}
|
|
35
|
-
else if (templateExpressionDepth > 0 && char === '}') {
|
|
36
|
-
templateExpressionDepth -= 1;
|
|
37
|
-
masked += char;
|
|
38
|
-
if (templateExpressionDepth === 0)
|
|
39
|
-
state = 'template';
|
|
40
|
-
}
|
|
41
|
-
else if (char === '/' && next === '/') {
|
|
42
|
-
masked += ' ';
|
|
43
|
-
index += 1;
|
|
44
|
-
state = 'line_comment';
|
|
45
|
-
}
|
|
46
|
-
else if (char === '/' && next === '*') {
|
|
47
|
-
masked += ' ';
|
|
48
|
-
index += 1;
|
|
49
|
-
state = 'block_comment';
|
|
50
|
-
}
|
|
51
|
-
else if (char === "'") {
|
|
52
|
-
masked += ' ';
|
|
53
|
-
state = 'single_quote';
|
|
54
|
-
}
|
|
55
|
-
else if (char === '"') {
|
|
56
|
-
masked += ' ';
|
|
57
|
-
state = 'double_quote';
|
|
58
|
-
}
|
|
59
|
-
else if (char === '`') {
|
|
60
|
-
masked += ' ';
|
|
61
|
-
state = 'template';
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
masked += char;
|
|
65
|
-
}
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
if (state === 'line_comment') {
|
|
69
|
-
masked += char === '\n' || char === '\r' ? char : ' ';
|
|
70
|
-
if (char === '\n' || char === '\r')
|
|
71
|
-
state = 'code';
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if (state === 'block_comment') {
|
|
75
|
-
if (char === '*' && next === '/') {
|
|
76
|
-
masked += ' ';
|
|
77
|
-
index += 1;
|
|
78
|
-
state = 'code';
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
masked += char === '\n' || char === '\r' ? char : ' ';
|
|
82
|
-
}
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
if (state === 'template' && char === '$' && next === '{') {
|
|
86
|
-
masked += ' {';
|
|
87
|
-
index += 1;
|
|
88
|
-
templateExpressionDepth = 1;
|
|
89
|
-
state = 'code';
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (char === '\\') {
|
|
93
|
-
masked += ' ';
|
|
94
|
-
if (index + 1 < source.length) {
|
|
95
|
-
masked += source[index + 1] === '\n' || source[index + 1] === '\r' ? source[index + 1] : ' ';
|
|
96
|
-
index += 1;
|
|
97
|
-
}
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
const closesLiteral = (state === 'single_quote' && char === "'") ||
|
|
101
|
-
(state === 'double_quote' && char === '"') ||
|
|
102
|
-
(state === 'template' && char === '`');
|
|
103
|
-
masked += char === '\n' || char === '\r' ? char : ' ';
|
|
104
|
-
if (closesLiteral)
|
|
105
|
-
state = 'code';
|
|
106
|
-
}
|
|
107
|
-
return masked;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Conservative scan of persisted RuleCode source for retired RuleHost
|
|
111
|
-
* contract symbols (field reads and helper calls). A hit means the rule must
|
|
112
|
-
* NOT execute against the current contract — its reads would silently
|
|
113
|
-
* resolve to undefined and change owner-approved behavior.
|
|
114
|
-
*/
|
|
115
|
-
export function scanRetiredContractSymbols(implementationCode) {
|
|
116
|
-
const executableSource = maskNonExecutableText(implementationCode);
|
|
117
|
-
const symbols = [];
|
|
118
|
-
for (const { symbol, pattern } of RETIRED_SYMBOL_PATTERNS) {
|
|
119
|
-
if (pattern.test(executableSource)) {
|
|
120
|
-
symbols.push(symbol);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return symbols;
|
|
124
|
-
}
|