principles-disciple 1.161.0 → 1.163.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/commands/pain.js +2 -2
- package/dist/core/intent-doc-reader-adapter.d.ts +13 -5
- package/dist/core/intent-doc-reader-adapter.js +25 -5
- package/dist/core/intent-doc-reader.d.ts +13 -4
- package/dist/core/intent-doc-reader.js +45 -24
- package/dist/hooks/gate.js +58 -1
- package/dist/hooks/pain.js +2 -2
- package/dist/hooks/prompt.js +2 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/commands/pain.js
CHANGED
|
@@ -5,7 +5,7 @@ import { resolvePluginCommandWorkspaceDir } from '../utils/workspace-resolver.js
|
|
|
5
5
|
import { computeHash } from '../utils/hashing.js';
|
|
6
6
|
import { PainToPrincipleService, PrincipleTreeLedgerAdapter } from '@principles/core/runtime-v2';
|
|
7
7
|
import { loadPdConfigForPlugin } from '../core/pd-config-loader.js';
|
|
8
|
-
import { createIntentDocReader } from '../core/intent-doc-reader-adapter.js';
|
|
8
|
+
import { createIntentDocReader, resolveIntentLang } from '../core/intent-doc-reader-adapter.js';
|
|
9
9
|
/**
|
|
10
10
|
* Creates a visual progress bar (e.g., [██████░░░░])
|
|
11
11
|
*/
|
|
@@ -275,7 +275,7 @@ export async function handlePainReportCommand(ctx) {
|
|
|
275
275
|
autoIntakeEnabled: true,
|
|
276
276
|
effectiveConfig: configResult.effective,
|
|
277
277
|
getEnvVar: (name) => process.env[name],
|
|
278
|
-
intentDocReader: createIntentDocReader(wctx.workspaceDir),
|
|
278
|
+
intentDocReader: createIntentDocReader(wctx.workspaceDir, resolveIntentLang(wctx.workspaceDir)),
|
|
279
279
|
});
|
|
280
280
|
const result = await service.recordPain({
|
|
281
281
|
painId: painData.painId,
|
|
@@ -17,12 +17,20 @@
|
|
|
17
17
|
* Architecture: this file is I/O (delegates to fs-reading safeReadIntentDoc).
|
|
18
18
|
* It will be added to KNOWN_PLUGIN_CORE_FILES in architecture-regression.test.ts.
|
|
19
19
|
*/
|
|
20
|
-
import type { IntentDocReader } from '@principles/core/runtime-v2';
|
|
20
|
+
import type { IntentDocReader, IntentLang } from '@principles/core/runtime-v2';
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Detect which language's INTENT file exists on disk.
|
|
23
|
+
* Priority: zh-CN first, then en. Defaults to zh-CN if neither exists.
|
|
23
24
|
*
|
|
24
|
-
*
|
|
25
|
+
* This lets hooks avoid hardcoding a single language — the Owner may have
|
|
26
|
+
* created either INTENT.zh-CN.md or INTENT.en.md.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveIntentLang(workspaceDir: string): IntentLang;
|
|
29
|
+
/**
|
|
30
|
+
* Create an IntentDocReader bound to a specific workspace and language.
|
|
31
|
+
*
|
|
32
|
+
* The returned reader is stateless beyond the (workspace, lang) binding — each
|
|
25
33
|
* `readIntentDoc()` call delegates to `safeReadIntentDoc()`, which owns
|
|
26
|
-
* the TTL+mtime cache
|
|
34
|
+
* the TTL+mtime cache keyed by `${workspaceDir}:${lang}`.
|
|
27
35
|
*/
|
|
28
|
-
export declare function createIntentDocReader(workspaceDir: string): IntentDocReader;
|
|
36
|
+
export declare function createIntentDocReader(workspaceDir: string, lang: IntentLang): IntentDocReader;
|
|
@@ -17,18 +17,38 @@
|
|
|
17
17
|
* Architecture: this file is I/O (delegates to fs-reading safeReadIntentDoc).
|
|
18
18
|
* It will be added to KNOWN_PLUGIN_CORE_FILES in architecture-regression.test.ts.
|
|
19
19
|
*/
|
|
20
|
+
import * as fs from 'node:fs';
|
|
21
|
+
import * as path from 'node:path';
|
|
20
22
|
import { safeReadIntentDoc } from './intent-doc-reader.js';
|
|
23
|
+
import { getIntentFilename, } from '@principles/core/runtime-v2';
|
|
24
|
+
const INTENT_DIR = '.principles';
|
|
21
25
|
/**
|
|
22
|
-
*
|
|
26
|
+
* Detect which language's INTENT file exists on disk.
|
|
27
|
+
* Priority: zh-CN first, then en. Defaults to zh-CN if neither exists.
|
|
23
28
|
*
|
|
24
|
-
*
|
|
29
|
+
* This lets hooks avoid hardcoding a single language — the Owner may have
|
|
30
|
+
* created either INTENT.zh-CN.md or INTENT.en.md.
|
|
31
|
+
*/
|
|
32
|
+
export function resolveIntentLang(workspaceDir) {
|
|
33
|
+
const zhPath = path.join(workspaceDir, INTENT_DIR, getIntentFilename('zh-CN'));
|
|
34
|
+
if (fs.existsSync(zhPath))
|
|
35
|
+
return 'zh-CN';
|
|
36
|
+
const enPath = path.join(workspaceDir, INTENT_DIR, getIntentFilename('en'));
|
|
37
|
+
if (fs.existsSync(enPath))
|
|
38
|
+
return 'en';
|
|
39
|
+
return 'zh-CN';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create an IntentDocReader bound to a specific workspace and language.
|
|
43
|
+
*
|
|
44
|
+
* The returned reader is stateless beyond the (workspace, lang) binding — each
|
|
25
45
|
* `readIntentDoc()` call delegates to `safeReadIntentDoc()`, which owns
|
|
26
|
-
* the TTL+mtime cache
|
|
46
|
+
* the TTL+mtime cache keyed by `${workspaceDir}:${lang}`.
|
|
27
47
|
*/
|
|
28
|
-
export function createIntentDocReader(workspaceDir) {
|
|
48
|
+
export function createIntentDocReader(workspaceDir, lang) {
|
|
29
49
|
return {
|
|
30
50
|
readIntentDoc() {
|
|
31
|
-
const result = safeReadIntentDoc(workspaceDir);
|
|
51
|
+
const result = safeReadIntentDoc(workspaceDir, lang);
|
|
32
52
|
if (result.ok && result.doc) {
|
|
33
53
|
const doc = result.doc;
|
|
34
54
|
const reference = {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* Architecture: this file is I/O (fs, path). It is whitelisted in
|
|
22
22
|
* architecture-regression.test.ts KNOWN_PLUGIN_CORE_FILES.
|
|
23
23
|
*/
|
|
24
|
-
import { type IntentDocSections, type IntentDocWarning } from '@principles/core/runtime-v2';
|
|
24
|
+
import { type IntentDocSections, type IntentDocWarning, type IntentLang } from '@principles/core/runtime-v2';
|
|
25
25
|
export type SafeReadIntentDocReason = 'flag_disabled' | 'not_found' | 'oversized' | 'read_error';
|
|
26
26
|
export interface IntentDoc {
|
|
27
27
|
/** Raw INTENT.md content (unescaped — caller escapes for prompt injection). */
|
|
@@ -55,9 +55,17 @@ export interface SafeReadIntentDocResult {
|
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Reset the intent doc cache for test isolation.
|
|
58
|
-
*
|
|
58
|
+
*
|
|
59
|
+
* - No args: clear the whole cache.
|
|
60
|
+
* - workspaceDir only: delete all entries for that workspace (any lang).
|
|
61
|
+
* Keys are formatted as `${workspaceDir}:${lang}`, so we match by prefix.
|
|
62
|
+
* - workspaceDir + lang: delete the single `${workspaceDir}:${lang}` entry.
|
|
63
|
+
*
|
|
64
|
+
* Note: prompt.ts resetPromptStateForTest passes workspaceDir only — the
|
|
65
|
+
* previous signature treated it as a literal cache key, which never matched
|
|
66
|
+
* the `${workspaceDir}:${lang}` format and silently left entries behind.
|
|
59
67
|
*/
|
|
60
|
-
export declare function resetIntentDocCacheForTest(workspaceDir?: string): void;
|
|
68
|
+
export declare function resetIntentDocCacheForTest(workspaceDir?: string, lang?: IntentLang): void;
|
|
61
69
|
/**
|
|
62
70
|
* Safely read INTENT.md for prompt injection.
|
|
63
71
|
*
|
|
@@ -69,10 +77,11 @@ export declare function resetIntentDocCacheForTest(workspaceDir?: string): void;
|
|
|
69
77
|
* 4. Never throws — all errors return structured reason + nextAction.
|
|
70
78
|
*
|
|
71
79
|
* @param workspaceDir - Absolute path to the workspace root
|
|
80
|
+
* @param lang - Mandatory language code ('zh-CN' | 'en'); selects INTENT.${lang}.md
|
|
72
81
|
* @param options - Optional logger for debug-level diagnostics
|
|
73
82
|
* @returns SafeReadIntentDocResult (never throws)
|
|
74
83
|
*/
|
|
75
|
-
export declare function safeReadIntentDoc(workspaceDir: string, options?: {
|
|
84
|
+
export declare function safeReadIntentDoc(workspaceDir: string, lang: IntentLang, options?: {
|
|
76
85
|
logger?: {
|
|
77
86
|
debug?: (msg: string) => void;
|
|
78
87
|
warn?: (msg: string) => void;
|
|
@@ -23,29 +23,48 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import * as fs from 'node:fs';
|
|
25
25
|
import * as path from 'node:path';
|
|
26
|
-
import { INTENT_MAX_BYTES, parseIntentDocSections, computeIntentContentHash, validateIntentDocSections, } from '@principles/core/runtime-v2';
|
|
26
|
+
import { INTENT_MAX_BYTES, getIntentFilename, parseIntentDocSections, computeIntentContentHash, validateIntentDocSections, } from '@principles/core/runtime-v2';
|
|
27
27
|
import { loadFeatureFlagFromConfig } from './pd-config-loader.js';
|
|
28
28
|
// ── Constants ────────────────────────────────────────────────────────────────
|
|
29
|
-
const INTENT_FILENAME = 'INTENT.md';
|
|
30
29
|
const INTENT_DIR = '.principles';
|
|
31
30
|
const INTENT_CACHE_TTL_MS = 60_000; // 1 minute (SPEC §12.1)
|
|
32
31
|
// ── Module-level cache (per-workspace) ───────────────────────────────────────
|
|
33
32
|
const _intentDocCache = new Map();
|
|
34
33
|
/**
|
|
35
34
|
* Reset the intent doc cache for test isolation.
|
|
36
|
-
*
|
|
35
|
+
*
|
|
36
|
+
* - No args: clear the whole cache.
|
|
37
|
+
* - workspaceDir only: delete all entries for that workspace (any lang).
|
|
38
|
+
* Keys are formatted as `${workspaceDir}:${lang}`, so we match by prefix.
|
|
39
|
+
* - workspaceDir + lang: delete the single `${workspaceDir}:${lang}` entry.
|
|
40
|
+
*
|
|
41
|
+
* Note: prompt.ts resetPromptStateForTest passes workspaceDir only — the
|
|
42
|
+
* previous signature treated it as a literal cache key, which never matched
|
|
43
|
+
* the `${workspaceDir}:${lang}` format and silently left entries behind.
|
|
37
44
|
*/
|
|
38
|
-
export function resetIntentDocCacheForTest(workspaceDir) {
|
|
39
|
-
if (workspaceDir) {
|
|
40
|
-
_intentDocCache.delete(workspaceDir);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
45
|
+
export function resetIntentDocCacheForTest(workspaceDir, lang) {
|
|
46
|
+
if (workspaceDir === undefined) {
|
|
43
47
|
_intentDocCache.clear();
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (lang !== undefined) {
|
|
51
|
+
_intentDocCache.delete(`${workspaceDir}:${lang}`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// workspaceDir only — clear all langs for this workspace by prefix.
|
|
55
|
+
const prefix = `${workspaceDir}:`;
|
|
56
|
+
for (const key of _intentDocCache.keys()) {
|
|
57
|
+
if (key.startsWith(prefix)) {
|
|
58
|
+
_intentDocCache.delete(key);
|
|
59
|
+
}
|
|
44
60
|
}
|
|
45
61
|
}
|
|
46
62
|
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
47
|
-
function getIntentFilePath(workspaceDir) {
|
|
48
|
-
return path.join(workspaceDir, INTENT_DIR,
|
|
63
|
+
function getIntentFilePath(workspaceDir, lang) {
|
|
64
|
+
return path.join(workspaceDir, INTENT_DIR, getIntentFilename(lang));
|
|
65
|
+
}
|
|
66
|
+
function getCacheKey(workspaceDir, lang) {
|
|
67
|
+
return `${workspaceDir}:${lang}`;
|
|
49
68
|
}
|
|
50
69
|
function buildDocFromRaw(raw, filePath, readAt) {
|
|
51
70
|
const sections = parseIntentDocSections(raw);
|
|
@@ -72,10 +91,11 @@ function buildDocFromRaw(raw, filePath, readAt) {
|
|
|
72
91
|
* 4. Never throws — all errors return structured reason + nextAction.
|
|
73
92
|
*
|
|
74
93
|
* @param workspaceDir - Absolute path to the workspace root
|
|
94
|
+
* @param lang - Mandatory language code ('zh-CN' | 'en'); selects INTENT.${lang}.md
|
|
75
95
|
* @param options - Optional logger for debug-level diagnostics
|
|
76
96
|
* @returns SafeReadIntentDocResult (never throws)
|
|
77
97
|
*/
|
|
78
|
-
export function safeReadIntentDoc(workspaceDir, options) {
|
|
98
|
+
export function safeReadIntentDoc(workspaceDir, lang, options) {
|
|
79
99
|
// SPEC §12 — Flag check FIRST. Flag off → no fs access, no cache access.
|
|
80
100
|
const flagResult = loadFeatureFlagFromConfig(workspaceDir, 'intent_engineering', options?.logger);
|
|
81
101
|
if (!flagResult.enabled) {
|
|
@@ -84,14 +104,15 @@ export function safeReadIntentDoc(workspaceDir, options) {
|
|
|
84
104
|
found: false,
|
|
85
105
|
flagEnabled: false,
|
|
86
106
|
reason: 'flag_disabled',
|
|
87
|
-
nextAction:
|
|
107
|
+
nextAction: `Enable the intent_engineering feature flag in .pd/config.yaml to read ${getIntentFilename(lang)}.`,
|
|
88
108
|
warnings: [],
|
|
89
109
|
};
|
|
90
110
|
}
|
|
91
|
-
const
|
|
111
|
+
const cacheKey = getCacheKey(workspaceDir, lang);
|
|
112
|
+
const filePath = getIntentFilePath(workspaceDir, lang);
|
|
92
113
|
const now = Date.now();
|
|
93
114
|
// Check cache freshness (TTL + mtime)
|
|
94
|
-
const cached = _intentDocCache.get(
|
|
115
|
+
const cached = _intentDocCache.get(cacheKey);
|
|
95
116
|
if (cached && (now - cached.loadedAt) < INTENT_CACHE_TTL_MS) {
|
|
96
117
|
// Cache is within TTL. Verify mtime hasn't changed.
|
|
97
118
|
try {
|
|
@@ -117,26 +138,26 @@ export function safeReadIntentDoc(workspaceDir, options) {
|
|
|
117
138
|
// Check existence first
|
|
118
139
|
if (!fs.existsSync(filePath)) {
|
|
119
140
|
// Invalidate stale cache entry if any
|
|
120
|
-
_intentDocCache.delete(
|
|
141
|
+
_intentDocCache.delete(cacheKey);
|
|
121
142
|
return {
|
|
122
143
|
ok: false,
|
|
123
144
|
found: false,
|
|
124
145
|
flagEnabled: true,
|
|
125
146
|
reason: 'not_found',
|
|
126
|
-
nextAction:
|
|
147
|
+
nextAction: `Create .principles/${getIntentFilename(lang)} using "pd intent init".`,
|
|
127
148
|
warnings: [],
|
|
128
149
|
};
|
|
129
150
|
}
|
|
130
151
|
const stat = fs.statSync(filePath);
|
|
131
152
|
// SPEC §12 — 32KB size cap
|
|
132
153
|
if (stat.size > INTENT_MAX_BYTES) {
|
|
133
|
-
_intentDocCache.delete(
|
|
154
|
+
_intentDocCache.delete(cacheKey);
|
|
134
155
|
return {
|
|
135
156
|
ok: false,
|
|
136
157
|
found: true,
|
|
137
158
|
flagEnabled: true,
|
|
138
159
|
reason: 'oversized',
|
|
139
|
-
nextAction:
|
|
160
|
+
nextAction: `${getIntentFilename(lang)} exceeds ${INTENT_MAX_BYTES} bytes (${stat.size} bytes). Reduce content.`,
|
|
140
161
|
warnings: [],
|
|
141
162
|
};
|
|
142
163
|
}
|
|
@@ -147,19 +168,19 @@ export function safeReadIntentDoc(workspaceDir, options) {
|
|
|
147
168
|
// an oversized file would enter parse/hash/cache as ok:true.
|
|
148
169
|
const actualBytes = Buffer.byteLength(raw, 'utf8');
|
|
149
170
|
if (actualBytes > INTENT_MAX_BYTES) {
|
|
150
|
-
_intentDocCache.delete(
|
|
171
|
+
_intentDocCache.delete(cacheKey);
|
|
151
172
|
return {
|
|
152
173
|
ok: false,
|
|
153
174
|
found: true,
|
|
154
175
|
flagEnabled: true,
|
|
155
176
|
reason: 'oversized',
|
|
156
|
-
nextAction:
|
|
177
|
+
nextAction: `${getIntentFilename(lang)} exceeds ${INTENT_MAX_BYTES} bytes (${actualBytes} bytes after read). Reduce content.`,
|
|
157
178
|
warnings: [],
|
|
158
179
|
};
|
|
159
180
|
}
|
|
160
181
|
const doc = buildDocFromRaw(raw, filePath, new Date(now).toISOString());
|
|
161
182
|
// Update cache
|
|
162
|
-
_intentDocCache.set(
|
|
183
|
+
_intentDocCache.set(cacheKey, {
|
|
163
184
|
doc,
|
|
164
185
|
mtime: stat.mtimeMs,
|
|
165
186
|
loadedAt: now,
|
|
@@ -174,15 +195,15 @@ export function safeReadIntentDoc(workspaceDir, options) {
|
|
|
174
195
|
}
|
|
175
196
|
catch (err) {
|
|
176
197
|
// ERR-002 — graceful degradation with reason + nextAction
|
|
177
|
-
_intentDocCache.delete(
|
|
198
|
+
_intentDocCache.delete(cacheKey);
|
|
178
199
|
const message = err instanceof Error ? err.message : String(err);
|
|
179
|
-
options?.logger?.warn?.(`[PD:Intent] safeReadIntentDoc failed: workspace=${workspaceDir}, error=${message}`);
|
|
200
|
+
options?.logger?.warn?.(`[PD:Intent] safeReadIntentDoc failed: workspace=${workspaceDir}, lang=${lang}, error=${message}`);
|
|
180
201
|
return {
|
|
181
202
|
ok: false,
|
|
182
203
|
found: false,
|
|
183
204
|
flagEnabled: true,
|
|
184
205
|
reason: 'read_error',
|
|
185
|
-
nextAction:
|
|
206
|
+
nextAction: `Check filesystem permissions for .principles/${getIntentFilename(lang)}.`,
|
|
186
207
|
warnings: [],
|
|
187
208
|
};
|
|
188
209
|
}
|
package/dist/hooks/gate.js
CHANGED
|
@@ -12,12 +12,14 @@ import { normalizePath } from '../utils/io.js';
|
|
|
12
12
|
import { WorkspaceContext } from '../core/workspace-context.js';
|
|
13
13
|
import { recordGateBlockAndReturn } from './gate-block-helper.js';
|
|
14
14
|
import { RuleHost } from '../core/rule-host.js';
|
|
15
|
-
import { validateCorrectionProposal, validateProposedPathBounds } from '@principles/core/runtime-v2';
|
|
15
|
+
import { validateCorrectionProposal, validateProposedPathBounds, computeFeatureFlagsFromConfig, UNAVAILABLE_RULE_CONTEXT } from '@principles/core/runtime-v2';
|
|
16
16
|
import { AGENT_TOOLS, BASH_TOOLS_SET, WRITE_TOOLS } from '../constants/tools.js';
|
|
17
17
|
import { getSession, hasRecentThinking } from '../core/session-tracker.js';
|
|
18
18
|
import { getEvolutionEngine } from '../core/evolution-engine.js';
|
|
19
19
|
import { EventLogService } from '../core/event-log.js';
|
|
20
20
|
import { estimateLineChanges } from '@principles/core/runtime-v2';
|
|
21
|
+
import { loadPdConfigForPlugin } from '../core/pd-config-loader.js';
|
|
22
|
+
import { buildProductionRuleContext } from '../core/rule-context-assembler.js';
|
|
21
23
|
export function handleBeforeToolCall(event, ctx) {
|
|
22
24
|
const logger = ctx.logger || console;
|
|
23
25
|
// 1. Identify tool type
|
|
@@ -53,6 +55,10 @@ export function handleBeforeToolCall(event, ctx) {
|
|
|
53
55
|
// 3. Rule Host Evaluation — sole gate
|
|
54
56
|
try {
|
|
55
57
|
const ruleHost = new RuleHost(wctx.stateDir, logger, { workspaceDir: ctx.workspaceDir });
|
|
58
|
+
// PRI-483 Phase 4: assemble RuleContextV2 when `rulecode_context_v2` flag is ON.
|
|
59
|
+
// flag OFF → undefined (v1 zero-change, no trajectory access).
|
|
60
|
+
// flag ON → RuleContextV2 (available or unavailable). Never throws (ERR-024).
|
|
61
|
+
const ruleContext = _buildRuleContextIfEnabled(wctx, relPath, ctx.sessionId, logger);
|
|
56
62
|
const hostInput = {
|
|
57
63
|
action: {
|
|
58
64
|
toolName: event.toolName,
|
|
@@ -80,6 +86,7 @@ export function handleBeforeToolCall(event, ctx) {
|
|
|
80
86
|
estimatedLineChanges: estimateLineChanges({ toolName: event.toolName, params: event.params ?? {} }),
|
|
81
87
|
bashRisk: _getBashRisk(event),
|
|
82
88
|
},
|
|
89
|
+
context: ruleContext,
|
|
83
90
|
};
|
|
84
91
|
const hostResult = ruleHost.evaluate(hostInput);
|
|
85
92
|
// Always emit rulehost_evaluated
|
|
@@ -379,3 +386,53 @@ function _getBashRisk(event) {
|
|
|
379
386
|
return 'unknown';
|
|
380
387
|
}
|
|
381
388
|
}
|
|
389
|
+
/**
|
|
390
|
+
* PRI-483 Phase 4 — Build RuleContextV2 for RuleHost.evaluate when the
|
|
391
|
+
* `rulecode_context_v2` feature flag is ON. Returns `undefined` when the flag
|
|
392
|
+
* is OFF (v1 zero-change — does NOT touch trajectory) or when config loading
|
|
393
|
+
* fails (conservative fail-soft: can't determine flag state → v1-style).
|
|
394
|
+
*
|
|
395
|
+
* ERR-024 prevention: context assembly failures never skip RuleHost.evaluate.
|
|
396
|
+
* - loadPdConfigForPlugin throws → return undefined (v1-style)
|
|
397
|
+
* - buildProductionRuleContext throws → return UNAVAILABLE_RULE_CONTEXT
|
|
398
|
+
* (structured unavailable so v2 rules see "context unavailable" and allow)
|
|
399
|
+
*
|
|
400
|
+
* Spec: docs/superpowers/specs/2026-06-27-rulecode-context-vision-design.md §5.3
|
|
401
|
+
*/
|
|
402
|
+
function _buildRuleContextIfEnabled(wctx, targetPath, sessionId, logger) {
|
|
403
|
+
// Step 1: load PD config (flag-gated). If this throws, we can't safely
|
|
404
|
+
// determine whether v2 context is required — fall back to v1 (undefined).
|
|
405
|
+
let configResult;
|
|
406
|
+
try {
|
|
407
|
+
configResult = loadPdConfigForPlugin(wctx.workspaceDir);
|
|
408
|
+
}
|
|
409
|
+
catch (err) {
|
|
410
|
+
logger?.warn?.(`[PD_GATE] RuleContext v2: config load failed, skipping context assembly: ${String(err)}`);
|
|
411
|
+
return undefined;
|
|
412
|
+
}
|
|
413
|
+
// Step 2: compute effective flags and check rulecode_context_v2.
|
|
414
|
+
// Explicit ok:false guard (rc-9-no-silent-fallback): when config is malformed,
|
|
415
|
+
// do NOT silently fall through to flag computation on defaults — log and
|
|
416
|
+
// return v1-style undefined so config issues surface to the operator.
|
|
417
|
+
if (!configResult.ok) {
|
|
418
|
+
const reasons = configResult.errors.map(e => e.reason).join('; ');
|
|
419
|
+
logger?.warn?.(`[PD_GATE] RuleContext v2: config load returned malformed result, skipping context assembly: ${reasons}`);
|
|
420
|
+
return undefined;
|
|
421
|
+
}
|
|
422
|
+
const flagsResult = computeFeatureFlagsFromConfig(configResult.effective);
|
|
423
|
+
const v2Flag = flagsResult.flags.rulecode_context_v2;
|
|
424
|
+
if (!v2Flag?.enabled) {
|
|
425
|
+
// Flag OFF → v1 zero-change. Do NOT access trajectory (spec §10.1).
|
|
426
|
+
return undefined;
|
|
427
|
+
}
|
|
428
|
+
// Step 3: flag ON → assemble context via production data source.
|
|
429
|
+
// buildProductionRuleContext is fail-soft internally (returns unavailable),
|
|
430
|
+
// but wrap in try/catch as defense-in-depth (ERR-024).
|
|
431
|
+
try {
|
|
432
|
+
return buildProductionRuleContext(sessionId, targetPath, wctx.trajectory, wctx.workspaceDir);
|
|
433
|
+
}
|
|
434
|
+
catch (err) {
|
|
435
|
+
logger?.warn?.(`[PD_GATE] RuleContext v2: buildProductionRuleContext threw unexpectedly, using unavailable context: ${String(err)}`);
|
|
436
|
+
return UNAVAILABLE_RULE_CONTEXT;
|
|
437
|
+
}
|
|
438
|
+
}
|
package/dist/hooks/pain.js
CHANGED
|
@@ -25,7 +25,7 @@ import { resolveWorkspaceDirForRuntimeV2 } from '../utils/workspace-resolver.js'
|
|
|
25
25
|
import { PainToPrincipleService, PrincipleTreeLedgerAdapter } from '@principles/core/runtime-v2';
|
|
26
26
|
import { evaluatePainDiagnosticGate } from '../core/pain-diagnostic-gate.js';
|
|
27
27
|
import { loadPdConfigForPlugin, loadFeatureFlagFromConfig } from '../core/pd-config-loader.js';
|
|
28
|
-
import { createIntentDocReader } from '../core/intent-doc-reader-adapter.js';
|
|
28
|
+
import { createIntentDocReader, resolveIntentLang } from '../core/intent-doc-reader-adapter.js';
|
|
29
29
|
import { evaluateTriggerController } from '@principles/core/runtime-v2';
|
|
30
30
|
import { isSharedCooldownActive, markSharedEpisodeAsDiagnosed } from './trigger-cooldown-tracker.js';
|
|
31
31
|
import { buildManualPainObservation, resolveSourceKind } from './raw-observation-adapter.js';
|
|
@@ -48,7 +48,7 @@ function createPainToPrincipleService(wctx) {
|
|
|
48
48
|
// PRI-468: wire INTENT.md reader so Stage A can produce intentTension
|
|
49
49
|
// when intent_engineering flag is on. Adapter performs no I/O beyond
|
|
50
50
|
// delegating to safeReadIntentDoc (which owns the flag-first check).
|
|
51
|
-
intentDocReader: createIntentDocReader(wctx.workspaceDir),
|
|
51
|
+
intentDocReader: createIntentDocReader(wctx.workspaceDir, resolveIntentLang(wctx.workspaceDir)),
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
// buildTrajectoryEvidence is in ./trajectory-evidence.ts (re-exported above)
|
package/dist/hooks/prompt.js
CHANGED
|
@@ -21,6 +21,7 @@ import { buildEmpathyObservation, resolveSourceKind } from './raw-observation-ad
|
|
|
21
21
|
import { evaluateEvidenceTriage } from './triage-adapter.js';
|
|
22
22
|
import { loadFeatureFlagFromConfig } from '../core/pd-config-loader.js';
|
|
23
23
|
import { safeReadIntentDoc, resetIntentDocCacheForTest } from '../core/intent-doc-reader.js';
|
|
24
|
+
import { resolveIntentLang } from '../core/intent-doc-reader-adapter.js';
|
|
24
25
|
import { buildIntentFrictionBlock } from '@principles/core/runtime-v2';
|
|
25
26
|
import { CorrectionCueLearner } from '../core/correction-cue-learner.js';
|
|
26
27
|
import { detectCorrectionCue as coreDetectCorrectionCue, escapeXml, extractMessageContent, isMinimalTrigger, } from '@principles/core/prompt-builder';
|
|
@@ -909,7 +910,7 @@ export async function handleBeforePromptBuild(event, ctx) {
|
|
|
909
910
|
try {
|
|
910
911
|
const intentFlag = loadFeatureFlagFromConfig(workspaceDir, 'intent_engineering', logger);
|
|
911
912
|
if (intentFlag.enabled) {
|
|
912
|
-
const intentResult = safeReadIntentDoc(workspaceDir, { logger });
|
|
913
|
+
const intentResult = safeReadIntentDoc(workspaceDir, resolveIntentLang(workspaceDir), { logger });
|
|
913
914
|
if (intentResult.ok && intentResult.doc) {
|
|
914
915
|
const block = buildIntentFrictionBlock({ rawIntentMd: intentResult.doc.raw });
|
|
915
916
|
if (block.length > 0) {
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "principles-disciple",
|
|
3
3
|
"name": "Principles Disciple",
|
|
4
4
|
"description": "Evolutionary programming agent framework with strategic guardrails and reflection loops.",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.163.0",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onCapabilities": [
|
|
8
8
|
"hook"
|