principles-disciple 4.1.0 → 4.1.1
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/bundle.js +401 -401
- package/dist/core/mcp-binding.d.ts +3 -1
- package/dist/core/signal-collector-host.d.ts +19 -1
- package/dist/openclaw.plugin.json +1 -1
- package/mcp/launcher.cjs +85 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +4 -4
|
@@ -38,4 +38,6 @@ export declare function invalidateMcpBinding(extensionRoot: string): {
|
|
|
38
38
|
removed: boolean;
|
|
39
39
|
reason?: string;
|
|
40
40
|
};
|
|
41
|
-
export declare function ensureMcpBinding(workspaceDir: string | undefined, extensionRoot: string, homeDir: string
|
|
41
|
+
export declare function ensureMcpBinding(workspaceDir: string | undefined, extensionRoot: string, homeDir: string, options?: {
|
|
42
|
+
experimentRoot?: string | null;
|
|
43
|
+
}): McpBindingOutcome;
|
|
@@ -91,6 +91,12 @@ export declare class SignalCollectorHost {
|
|
|
91
91
|
private readonly processedRuns;
|
|
92
92
|
/** Zero-hit discovery budget for this workspace's host process. */
|
|
93
93
|
private discoveryBucket;
|
|
94
|
+
/**
|
|
95
|
+
* Per-session discovery buckets. The global bucket alone lets one chatty
|
|
96
|
+
* session starve every other session's explicit corrections; the per-session
|
|
97
|
+
* dimension keeps ordinary conversation from exhausting the shared budget.
|
|
98
|
+
*/
|
|
99
|
+
private readonly discoverySessionBuckets;
|
|
94
100
|
constructor(wctx: WorkspaceContext, options?: SignalCollectorHostOptions);
|
|
95
101
|
/**
|
|
96
102
|
* ★ 同步路径 (prompt.ts before_prompt_build 钩子里调用,绝不能阻塞)。
|
|
@@ -150,9 +156,21 @@ export declare class SignalCollectorHost {
|
|
|
150
156
|
private countStage2Invocation;
|
|
151
157
|
/**
|
|
152
158
|
* 零命中发现调用的配额判定(纯内存,同步安全)。
|
|
153
|
-
*
|
|
159
|
+
* 全局每小时最多 discoveryRateLimitPerHour 次,且每个 session 最多
|
|
160
|
+
* discoveryRateLimitPerSessionPerHour 次;0/未设置 = 该维度不限制。
|
|
161
|
+
*
|
|
162
|
+
* 先判 session 再判全局:一个 session 达到自己的上限时不能继续消耗共享
|
|
163
|
+
* 预算,否则"某个会话聊得多"仍会间接饿死其它会话的明确纠正。
|
|
154
164
|
*/
|
|
155
165
|
private takeDiscoveryBudget;
|
|
166
|
+
/**
|
|
167
|
+
* 预算耗尽的结构化诊断:每小时窗口内每个 scope 只记一次 SYSTEM log,
|
|
168
|
+
* 健康计数仍然逐次累加(stage2DiscoverySkipped)。既有"挡下了多少次",
|
|
169
|
+
* 也有"为什么被挡、是哪个 scope、上限多少"。
|
|
170
|
+
*/
|
|
171
|
+
private reportDiscoveryExhaustion;
|
|
172
|
+
/** Expired session buckets carry no information; keep the map bounded. */
|
|
173
|
+
private pruneDiscoverySessionBuckets;
|
|
156
174
|
/** 被配额挡下的零命中发现计数(旁路,同 countStage2* 推迟到微任务)。 */
|
|
157
175
|
private countStage2DiscoverySkipped;
|
|
158
176
|
/**
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "principles-disciple",
|
|
3
3
|
"name": "Principles Disciple",
|
|
4
4
|
"description": "Principles Disciple is an AI Agent Governance System. Stop correcting the same AI behavior across sessions. Turn repeated Agent corrections into Owner-approved, observable, reversible behavior principles.",
|
|
5
|
-
"version": "4.1.
|
|
5
|
+
"version": "4.1.1",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onStartup": true,
|
|
8
8
|
"onCapabilities": [
|
package/mcp/launcher.cjs
CHANGED
|
@@ -94,6 +94,76 @@ const logState = {
|
|
|
94
94
|
exhausted: false,
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
+
// ── Experiment isolation (P0, 2026-11-13 real-host E2E) ────────────────────
|
|
98
|
+
// The experiment gateway inherits this launcher's environment. When
|
|
99
|
+
// PD_EXPERIMENT_ROOT is present every PD-owned path used here must stay inside
|
|
100
|
+
// it: the log directory (default would be the PRODUCTION `~/.pd/logs/mcp`) and
|
|
101
|
+
// the binding workspace (a stale/inherited binding must never point the
|
|
102
|
+
// experiment at the production workspace). Refuse BEFORE any MCP traffic.
|
|
103
|
+
const EXPERIMENT_ROOT = typeof process.env.PD_EXPERIMENT_ROOT === 'string'
|
|
104
|
+
? process.env.PD_EXPERIMENT_ROOT.trim()
|
|
105
|
+
: '';
|
|
106
|
+
|
|
107
|
+
function canonicalExisting(target) {
|
|
108
|
+
const resolved = path.resolve(target);
|
|
109
|
+
const missing = [];
|
|
110
|
+
let current = resolved;
|
|
111
|
+
for (;;) {
|
|
112
|
+
try {
|
|
113
|
+
const real = fs.realpathSync.native(current);
|
|
114
|
+
return missing.length === 0 ? real : path.join(real, ...missing.reverse());
|
|
115
|
+
} catch {
|
|
116
|
+
// Missing path (the log dir is created later): canonicalize the deepest
|
|
117
|
+
// existing ancestor so an 8.3-form ancestor cannot make two views of the
|
|
118
|
+
// same directory look different.
|
|
119
|
+
}
|
|
120
|
+
const parent = path.dirname(current);
|
|
121
|
+
if (parent === current) return resolved;
|
|
122
|
+
missing.push(path.basename(current));
|
|
123
|
+
current = parent;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function isInsideOrSame(parent, child) {
|
|
128
|
+
const relative = path.relative(path.resolve(parent), path.resolve(child));
|
|
129
|
+
return relative === '' || (!path.isAbsolute(relative) && relative !== '..' && !relative.startsWith('..' + path.sep));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function experimentRootRealPath() {
|
|
133
|
+
if (EXPERIMENT_ROOT === '') return null;
|
|
134
|
+
if (!path.isAbsolute(EXPERIMENT_ROOT)) {
|
|
135
|
+
fail('experiment_root_not_absolute', 'PD_EXPERIMENT_ROOT must be an absolute path; refusing to start the MCP server from an ambiguous root.');
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
return fs.realpathSync.native(EXPERIMENT_ROOT);
|
|
139
|
+
} catch {
|
|
140
|
+
fail('experiment_root_missing', 'PD_EXPERIMENT_ROOT does not resolve to an existing directory; refusing to start the MCP server.');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function isLogDirAllowed(dir) {
|
|
145
|
+
if (EXPERIMENT_ROOT === '') return true;
|
|
146
|
+
const rootReal = experimentRootRealPath();
|
|
147
|
+
return rootReal !== null && isInsideOrSame(rootReal, canonicalExisting(dir));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (EXPERIMENT_ROOT !== '') {
|
|
151
|
+
const logOverride = typeof process.env.PD_MCP_LOG_DIR === 'string' ? process.env.PD_MCP_LOG_DIR.trim() : '';
|
|
152
|
+
if (logOverride === '') {
|
|
153
|
+
fail(
|
|
154
|
+
'experiment_mcp_log_dir_missing',
|
|
155
|
+
'PD_MCP_LOG_DIR must be set for an experiment instance; the default log directory is the production ~/.pd/logs/mcp.',
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
const rootReal = experimentRootRealPath();
|
|
159
|
+
if (rootReal !== null && !isInsideOrSame(rootReal, canonicalExisting(logOverride))) {
|
|
160
|
+
fail(
|
|
161
|
+
'experiment_mcp_log_dir_outside_root',
|
|
162
|
+
'PD_MCP_LOG_DIR resolves outside PD_EXPERIMENT_ROOT; refusing to write MCP logs into production state.',
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
97
167
|
function pad(value, width) {
|
|
98
168
|
return String(value).padStart(width || 2, '0');
|
|
99
169
|
}
|
|
@@ -176,6 +246,7 @@ function ensureLogFile() {
|
|
|
176
246
|
if (logState.currentPath !== null) return logState.currentPath;
|
|
177
247
|
try {
|
|
178
248
|
const dir = logDir();
|
|
249
|
+
if (!isLogDirAllowed(dir)) return null;
|
|
179
250
|
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
180
251
|
if (!fs.statSync(dir).isDirectory()) return null;
|
|
181
252
|
maintainLogDir(dir, Date.now(), null);
|
|
@@ -497,6 +568,20 @@ if (!workspaceStat.isDirectory()) {
|
|
|
497
568
|
}
|
|
498
569
|
logState.workspaceResolution = 'ok';
|
|
499
570
|
|
|
571
|
+
// P0 (2026-11-13): an experiment must never bind a workspace outside its own
|
|
572
|
+
// root. The binding is untrusted input written by another process generation;
|
|
573
|
+
// a stale one (or one produced from an inherited production pointer) keeps the
|
|
574
|
+
// production path while every environment variable says "experiment".
|
|
575
|
+
if (EXPERIMENT_ROOT !== '') {
|
|
576
|
+
const rootReal = experimentRootRealPath();
|
|
577
|
+
if (rootReal !== null && !isInsideOrSame(rootReal, canonicalExisting(binding.workspaceDir))) {
|
|
578
|
+
fail(
|
|
579
|
+
'experiment_binding_workspace_outside_root',
|
|
580
|
+
'mcp-binding.json binds a workspace outside PD_EXPERIMENT_ROOT. Restart the experiment gateway so the PD plugin rewrites the binding for the experiment workspace.',
|
|
581
|
+
);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
500
585
|
// ── OpenClaw workspace-declaration gate (SPEC §3.5, final safety closure) ──
|
|
501
586
|
// The OpenClaw binding is HOST-WIDE while agents have per-agent workspaces, so
|
|
502
587
|
// a binding may only be trusted while it still matches the workspace the Owner
|
package/openclaw.plugin.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "principles-disciple",
|
|
3
3
|
"name": "Principles Disciple",
|
|
4
4
|
"description": "Principles Disciple is an AI Agent Governance System. Stop correcting the same AI behavior across sessions. Turn repeated Agent corrections into Owner-approved, observable, reversible behavior principles.",
|
|
5
|
-
"version": "4.1.
|
|
5
|
+
"version": "4.1.1",
|
|
6
6
|
"activation": {
|
|
7
7
|
"onStartup": true,
|
|
8
8
|
"onCapabilities": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "principles-disciple",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "Principles Disciple is an AI Agent Governance System. Stop correcting the same AI behavior across sessions. Turn repeated Agent corrections into Owner-approved, observable, reversible behavior principles.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"compile-principles": "node scripts/compile-principles.mjs"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@principles/core": "^7.6.
|
|
80
|
-
"@principles/host-runtime": "^4.1.
|
|
79
|
+
"@principles/core": "^7.6.1",
|
|
80
|
+
"@principles/host-runtime": "^4.1.1",
|
|
81
81
|
"@types/better-sqlite3": "^9.6.0",
|
|
82
82
|
"@types/js-yaml": "^4.0.9",
|
|
83
83
|
"@types/micromatch": "^4.0.10",
|
|
@@ -109,5 +109,5 @@
|
|
|
109
109
|
"js-yaml": "^5.4.3",
|
|
110
110
|
"micromatch": "^4.0.8"
|
|
111
111
|
},
|
|
112
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "8582e5dde27a582c63f3ad6804675a84c0d0c11e"
|
|
113
113
|
}
|