create-principles-disciple 1.151.0 → 1.152.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/_release/product-identity.json +1 -1
- package/console/dist/server/routes/failed-tasks.js +84 -1
- package/console/dist/web/assets/app.js +22 -22
- package/core/dist/runtime/activation/ledger-identity.d.ts.map +1 -1
- package/core/dist/runtime/activation/ledger-identity.js +5 -0
- package/core/dist/runtime/activation/ledger-identity.js.map +1 -1
- package/core/dist/runtime/activation/prompt-activation-reader-contract.d.ts +6 -0
- package/core/dist/runtime/activation/prompt-activation-reader-contract.d.ts.map +1 -1
- package/core/dist/runtime/activation/prompt-activation-reader-contract.js +105 -7
- package/core/dist/runtime/activation/prompt-activation-reader-contract.js.map +1 -1
- package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js +10 -1
- package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts +13 -0
- package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rollout-reviewer-runner.js +28 -4
- package/core/dist/runtime/internalization/rollout-reviewer-runner.js.map +1 -1
- package/core/dist/runtime/internalization/scribe-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/scribe-runner.js +25 -3
- package/core/dist/runtime/internalization/scribe-runner.js.map +1 -1
- package/core/dist/runtime/signal-collector/types.d.ts +6 -0
- package/core/dist/runtime/signal-collector/types.d.ts.map +1 -1
- package/core/dist/runtime/signal-collector/types.js.map +1 -1
- package/core/dist/runtime/types/rule-candidate-binding.d.ts +1 -1
- package/core/dist/runtime/types/rule-candidate-binding.d.ts.map +1 -1
- package/core/package.json +1 -1
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -1
- package/dist/installer.d.ts +35 -0
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +82 -1
- package/dist/installer.js.map +1 -1
- package/dist/installers/index.d.ts +31 -0
- package/dist/installers/index.d.ts.map +1 -1
- package/dist/installers/index.js +76 -3
- package/dist/installers/index.js.map +1 -1
- package/dist/update/release-manager.d.ts +1 -1
- package/dist/update/release-manager.d.ts.map +1 -1
- package/dist/update/release-manager.js +45 -2
- package/dist/update/release-manager.js.map +1 -1
- package/host-runtime/dist/active-principle-prompt.js +1 -0
- package/host-runtime/dist/governance-signal-admission.js +12 -0
- package/host-runtime/dist/prompt-activation-deliverability.d.ts +2 -0
- package/host-runtime/dist/prompt-activation-deliverability.js +2 -0
- package/host-runtime/dist/prompt-injection-status.js +1 -0
- package/host-runtime/package.json +1 -1
- package/install-layout/dist/mcp-binding-contract.js +5 -0
- package/install-layout/package.json +1 -1
- package/package.json +3 -3
- package/pd-cli/dist/commands/console.d.ts.map +1 -1
- package/pd-cli/dist/commands/console.js +8 -0
- package/pd-cli/dist/commands/console.js.map +1 -1
- package/pd-cli/dist/services/console-launcher.d.ts +15 -0
- package/pd-cli/dist/services/console-launcher.d.ts.map +1 -1
- package/pd-cli/dist/services/console-launcher.js +7 -1
- package/pd-cli/dist/services/console-launcher.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/pd-mcp-server/dist/version.d.ts +1 -1
- package/pd-mcp-server/dist/version.js +1 -1
- package/pd-mcp-server/package.json +1 -1
- package/plugin/dist/bundle.js +401 -401
- package/plugin/dist/core/mcp-binding.d.ts +3 -1
- package/plugin/dist/core/signal-collector-host.d.ts +19 -1
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/mcp/launcher.cjs +85 -0
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/release-manager/dist/installer.js +82 -1
- package/release-manager/dist/installers/index.js +76 -3
- package/release-manager/dist/update/release-manager.js +45 -2
- package/release-manager/package.json +1 -1
- package/workbuddy-adapter/package.json +1 -1
- package/workbuddy-adapter/plugin/mcp/launcher.cjs +85 -0
|
@@ -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/plugin/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
|
|
@@ -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/plugin/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",
|
|
@@ -12,7 +12,7 @@ import { logger } from './utils/logger.js';
|
|
|
12
12
|
import { checkOpenClawGateway, stopOpenClawGateway, restartOpenClawGateway } from './utils/env.js';
|
|
13
13
|
import { t } from './i18n.js';
|
|
14
14
|
import { generateConfigYamlContent, ExistingConfigVerifyInfraError, validateExistingConfigYamlForPreserve, getConfigYamlPath, readEnabledChannelsFromConfigYaml, getOpenClawDir, getPdDir, getPdRuntimeDir, getInstallManifestPath, getPdRuntimeBackupsDir, getPluginExtDir, getInstalledPluginDir, getInstalledLayoutPackageDir, getPdBackupsDir, getInstalledPdCliDir, getInstalledBinDir, getInstalledConsoleDir, getHomeDir, isWindows, } from './mvp-config.js';
|
|
15
|
-
import { detectInstalledHosts, getHostInstallers } from './installers/index.js';
|
|
15
|
+
import { detectInstalledHosts, evaluateRecordedHostPresence, getHostInstallers, isRecordedHost } from './installers/index.js';
|
|
16
16
|
import { readCanonicalRuntimeCohort, readInstalledRuntimeCohort, resolvePluginDataRoot } from './installers/codex-host-installer.js';
|
|
17
17
|
import { runWorkbuddyEarlyPreflight } from './installers/workbuddy-host-installer.js';
|
|
18
18
|
import { INSTALL_LAYOUT_VERSION, getInstallLayoutPaths, getWorkbuddyWorkspaceDir, installManifestHostsForPersist, mergeInstallManifestWorkspaces, parseInstallManifest } from '@principles/install-layout';
|
|
@@ -610,6 +610,87 @@ export async function repairUpdateChain(input) {
|
|
|
610
610
|
notes,
|
|
611
611
|
};
|
|
612
612
|
}
|
|
613
|
+
export function repairInstallManifestHosts(options = {}) {
|
|
614
|
+
const manifestPath = getInstallManifestPath();
|
|
615
|
+
const refuse = (reason, nextAction) => ({
|
|
616
|
+
success: false,
|
|
617
|
+
applied: false,
|
|
618
|
+
manifestPath,
|
|
619
|
+
before: [],
|
|
620
|
+
after: [],
|
|
621
|
+
removed: [],
|
|
622
|
+
entries: [],
|
|
623
|
+
reason,
|
|
624
|
+
nextAction,
|
|
625
|
+
});
|
|
626
|
+
let raw;
|
|
627
|
+
try {
|
|
628
|
+
raw = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
629
|
+
}
|
|
630
|
+
catch (error) {
|
|
631
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
632
|
+
return refuse(`install_manifest_unreadable: ${detail}`, `Inspect ${manifestPath} and re-run the official installer once it is valid JSON.`);
|
|
633
|
+
}
|
|
634
|
+
const parsed = parseInstallManifest(raw);
|
|
635
|
+
if (parsed.manifest === undefined) {
|
|
636
|
+
return refuse(parsed.error ?? 'install_manifest_malformed', `Inspect ${manifestPath}; the host record cannot be judged safely.`);
|
|
637
|
+
}
|
|
638
|
+
const before = installManifestHostsForPersist(parsed.manifest);
|
|
639
|
+
const entries = before.map((host) => {
|
|
640
|
+
if (!isRecordedHost(host)) {
|
|
641
|
+
return { host, verdict: 'not-judged', detail: 'unknown host id — never removed by this repair' };
|
|
642
|
+
}
|
|
643
|
+
const presence = evaluateRecordedHostPresence(host, getHomeDir());
|
|
644
|
+
return presence.status === 'undecidable'
|
|
645
|
+
? { host, verdict: 'undecidable', detail: presence.reason }
|
|
646
|
+
: { host, verdict: presence.status, detail: presence.evidence };
|
|
647
|
+
});
|
|
648
|
+
const removed = entries.filter((entry) => entry.verdict === 'absent').map((entry) => entry.host);
|
|
649
|
+
const after = before.filter((host) => !removed.includes(host));
|
|
650
|
+
if (removed.length === 0) {
|
|
651
|
+
return {
|
|
652
|
+
success: true,
|
|
653
|
+
applied: false,
|
|
654
|
+
manifestPath,
|
|
655
|
+
before,
|
|
656
|
+
after,
|
|
657
|
+
removed,
|
|
658
|
+
entries,
|
|
659
|
+
nextAction: 'Nothing to repair: every recorded host is installed or cannot be judged safely.',
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
if (after.length === 0) {
|
|
663
|
+
return refuse('manifest_would_be_empty: every recorded host is provably absent, so no host installer would serve this installation', `Re-run the official installer to register a host before repairing ${manifestPath}.`);
|
|
664
|
+
}
|
|
665
|
+
if (options.apply !== true) {
|
|
666
|
+
return {
|
|
667
|
+
success: true,
|
|
668
|
+
applied: false,
|
|
669
|
+
manifestPath,
|
|
670
|
+
before,
|
|
671
|
+
after,
|
|
672
|
+
removed,
|
|
673
|
+
entries,
|
|
674
|
+
nextAction: 'Dry run — re-run with --apply to write the repair (the current file is backed up first).',
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
const backupPath = path.join(getPdRuntimeBackupsDir(), `install-manifest.backup.${Date.now()}.json`);
|
|
678
|
+
mkdirSync(getPdRuntimeBackupsDir(), { recursive: true });
|
|
679
|
+
writeFileSync(backupPath, readFileSync(manifestPath));
|
|
680
|
+
writeInstallManifest([...after], [...(parsed.manifest.workspaces ?? [])]);
|
|
681
|
+
return {
|
|
682
|
+
success: true,
|
|
683
|
+
applied: true,
|
|
684
|
+
manifestPath,
|
|
685
|
+
before,
|
|
686
|
+
after,
|
|
687
|
+
removed,
|
|
688
|
+
entries,
|
|
689
|
+
backupPath,
|
|
690
|
+
restoreCommand: `cp "${backupPath}" "${manifestPath}"`,
|
|
691
|
+
nextAction: `Removed ${removed.join(', ')} from the host record. Restore the previous value with: cp "${backupPath}" "${manifestPath}"`,
|
|
692
|
+
};
|
|
693
|
+
}
|
|
613
694
|
function installBundledLayoutPackage(pluginDir) {
|
|
614
695
|
const source = path.join(pluginDir, 'install-layout');
|
|
615
696
|
const destination = getInstalledLayoutPackageDir();
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { existsSync } from 'fs';
|
|
1
|
+
import { existsSync, readFileSync } from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import * as os from 'os';
|
|
4
4
|
import { OpenClawHostInstaller } from './openclaw-host-installer.js';
|
|
5
|
-
import { CodexHostInstaller } from './codex-host-installer.js';
|
|
6
|
-
import { WorkBuddyHostInstaller, readWorkbuddyHostState } from './workbuddy-host-installer.js';
|
|
5
|
+
import { CodexHostInstaller, detectCodexMarketplaceState } from './codex-host-installer.js';
|
|
6
|
+
import { WorkBuddyHostInstaller, readWorkbuddyHostState, resolveWorkbuddyPaths } from './workbuddy-host-installer.js';
|
|
7
7
|
export { OpenClawHostInstaller } from './openclaw-host-installer.js';
|
|
8
8
|
export { CodexHostInstaller } from './codex-host-installer.js';
|
|
9
9
|
export { WorkBuddyHostInstaller } from './workbuddy-host-installer.js';
|
|
@@ -78,4 +78,77 @@ export function detectInstalledHosts(homeDir = os.homedir(), codexHome) {
|
|
|
78
78
|
}
|
|
79
79
|
return detected;
|
|
80
80
|
}
|
|
81
|
+
export const RECORDED_HOSTS = ['openclaw', 'codex', 'workbuddy'];
|
|
82
|
+
export function isRecordedHost(value) {
|
|
83
|
+
return RECORDED_HOSTS.includes(value);
|
|
84
|
+
}
|
|
85
|
+
function errorCode(error) {
|
|
86
|
+
if (error instanceof Error && Object.hasOwn(error, 'code')) {
|
|
87
|
+
const code = Reflect.get(error, 'code');
|
|
88
|
+
return typeof code === 'string' ? code : undefined;
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
function describeError(error) {
|
|
93
|
+
return error instanceof Error ? error.message : String(error);
|
|
94
|
+
}
|
|
95
|
+
export function evaluateRecordedHostPresence(host, homeDir = os.homedir()) {
|
|
96
|
+
const detected = detectInstalledHosts(homeDir).find((entry) => entry.hostId === host);
|
|
97
|
+
if (detected !== undefined) {
|
|
98
|
+
return { status: 'installed', evidence: detected.evidence };
|
|
99
|
+
}
|
|
100
|
+
if (host === 'openclaw') {
|
|
101
|
+
const openclawDir = path.join(homeDir, '.openclaw');
|
|
102
|
+
const configPath = path.join(openclawDir, 'openclaw.json');
|
|
103
|
+
let raw;
|
|
104
|
+
try {
|
|
105
|
+
raw = readFileSync(configPath, 'utf8');
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
if (errorCode(error) === 'ENOENT') {
|
|
109
|
+
return { status: 'absent', evidence: `no PD extension and no ${configPath}` };
|
|
110
|
+
}
|
|
111
|
+
return { status: 'undecidable', reason: `cannot read ${configPath}: ${describeError(error)}` };
|
|
112
|
+
}
|
|
113
|
+
// Conservative: a config that still names PD counts as installed even when
|
|
114
|
+
// the extension directory is gone — dropping the record would strand those
|
|
115
|
+
// entries, and a false "installed" only keeps the manifest as it is.
|
|
116
|
+
if (raw.includes('principles-disciple')) {
|
|
117
|
+
return { status: 'installed', evidence: `${configPath} still references principles-disciple` };
|
|
118
|
+
}
|
|
119
|
+
return { status: 'absent', evidence: `no PD extension and ${configPath} does not reference principles-disciple` };
|
|
120
|
+
}
|
|
121
|
+
if (host === 'codex') {
|
|
122
|
+
const detection = new CodexHostInstaller().detect();
|
|
123
|
+
if (detection.installed) {
|
|
124
|
+
const evidence = detection.paths.find((entry) => entry.exists);
|
|
125
|
+
return { status: 'installed', evidence: evidence?.path ?? 'codex install detected' };
|
|
126
|
+
}
|
|
127
|
+
// The Marketplace cache is the supported install path: its three-state
|
|
128
|
+
// detector distinguishes "absent" from "cannot judge".
|
|
129
|
+
const marketplace = detectCodexMarketplaceState();
|
|
130
|
+
if (marketplace.state === 'unknown') {
|
|
131
|
+
return { status: 'undecidable', reason: marketplace.reason };
|
|
132
|
+
}
|
|
133
|
+
const hooks = detection.paths.find((entry) => entry.name === 'Codex hooks.json' && entry.exists);
|
|
134
|
+
if (hooks !== undefined) {
|
|
135
|
+
try {
|
|
136
|
+
JSON.parse(readFileSync(hooks.path, 'utf8'));
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
return { status: 'undecidable', reason: `${hooks.path} exists but cannot be read as JSON: ${describeError(error)}` };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { status: 'absent', evidence: 'no PD marker, PD hook entries, or Marketplace plugin in the Codex home' };
|
|
143
|
+
}
|
|
144
|
+
const workbuddyPaths = resolveWorkbuddyPaths(homeDir);
|
|
145
|
+
const workbuddy = readWorkbuddyHostState(homeDir);
|
|
146
|
+
if (workbuddy.pluginState === undefined) {
|
|
147
|
+
return { status: 'undecidable', reason: 'workbuddy plugin state could not be read' };
|
|
148
|
+
}
|
|
149
|
+
if (!workbuddy.pluginState.registryReadable) {
|
|
150
|
+
return { status: 'undecidable', reason: `${workbuddyPaths.registryPath} exists but is not a readable plugin registry` };
|
|
151
|
+
}
|
|
152
|
+
return { status: 'absent', evidence: `PD is not registered in ${workbuddyPaths.registryPath}` };
|
|
153
|
+
}
|
|
81
154
|
//# sourceMappingURL=index.js.map
|
|
@@ -19,6 +19,7 @@ import { readBootstrapManifest, readInstallConfig, resolvePdHomePaths, } from '.
|
|
|
19
19
|
import { appendJournalTransition, readActiveRecord, TransactionJournalError, } from './transaction-journal.js';
|
|
20
20
|
import { downloadReleaseAsset, extractAndVerifyReleaseAsset, ApplyPayloadError } from './apply-payload.js';
|
|
21
21
|
import { compareProductVersions, parseProductVersion } from './product-identity.js';
|
|
22
|
+
import { installManifestHostsForPersist, parseInstallManifest } from '@principles/install-layout';
|
|
22
23
|
export class ReleaseManagerError extends Error {
|
|
23
24
|
reason;
|
|
24
25
|
nextAction;
|
|
@@ -147,6 +148,44 @@ function toReleaseManagerError(error) {
|
|
|
147
148
|
const message = error instanceof Error ? error.message : String(error);
|
|
148
149
|
return new ReleaseManagerError('apply_failed', `Release application failed: ${message}`, 'The runtime was left on the previous release (installer backup/restore). Retry the update; if it fails again, run the official installer to repair.');
|
|
149
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* PRI-1204: the deployment host an update must target.
|
|
153
|
+
*
|
|
154
|
+
* `~/.pd/install.json` is the installer-owned record of the hosts this
|
|
155
|
+
* installation serves. No caller of `apply()` supplies a host (the console
|
|
156
|
+
* request carries none), so this layer used to fall back to a literal
|
|
157
|
+
* `'openclaw'` — on a WorkBuddy-only (or Codex-only) installation the update
|
|
158
|
+
* was then deployed AS IF OpenClaw had been requested: the journal recorded a
|
|
159
|
+
* host the machine does not serve, the installer's manifest merge added
|
|
160
|
+
* `openclaw` to `hosts`, and OpenClaw-specific writes ran on a machine with no
|
|
161
|
+
* OpenClaw. The recorded host is the truth.
|
|
162
|
+
*
|
|
163
|
+
* One target is enough: the installer's own upgrade plan refreshes every OTHER
|
|
164
|
+
* installed host in the same run (`resolveHostRefreshTargets`).
|
|
165
|
+
*
|
|
166
|
+
* A legacy install.json without the manifest fields keeps the historical
|
|
167
|
+
* default — there is no record to contradict it.
|
|
168
|
+
*/
|
|
169
|
+
function resolveDeploymentHost(installConfigPath) {
|
|
170
|
+
let value;
|
|
171
|
+
try {
|
|
172
|
+
value = JSON.parse(fs.readFileSync(installConfigPath, 'utf8'));
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return 'openclaw';
|
|
176
|
+
}
|
|
177
|
+
const parsed = parseInstallManifest(value);
|
|
178
|
+
if (!parsed.manifest)
|
|
179
|
+
return 'openclaw';
|
|
180
|
+
const recorded = installManifestHostsForPersist(parsed.manifest);
|
|
181
|
+
if (recorded.includes('openclaw'))
|
|
182
|
+
return 'openclaw';
|
|
183
|
+
if (recorded.includes('workbuddy'))
|
|
184
|
+
return 'workbuddy';
|
|
185
|
+
if (recorded.includes('codex'))
|
|
186
|
+
return 'codex';
|
|
187
|
+
return 'openclaw';
|
|
188
|
+
}
|
|
150
189
|
/**
|
|
151
190
|
* Single authority for active.json: the transaction journal's strict reader
|
|
152
191
|
* (schemaVersion + full field set). This adapter only maps its corruption
|
|
@@ -250,6 +289,10 @@ export class ReleaseManager {
|
|
|
250
289
|
if (status.layout === 'legacy-overlay') {
|
|
251
290
|
throw new ReleaseManagerError('legacy_layout_not_supported', 'This installation uses the legacy overlay layout, which the transactional updater does not serve.', 'Run the official installer to repair this installation into the supported layout, then retry.');
|
|
252
291
|
}
|
|
292
|
+
// PRI-1204: the host this update deploys into comes from the installation
|
|
293
|
+
// record, not from a literal. Resolved once, before any side effect, so the
|
|
294
|
+
// journal, the installer call, and the manifest merge all state ONE target.
|
|
295
|
+
const deploymentHost = options.host ?? resolveDeploymentHost(this.paths.installConfigPath);
|
|
253
296
|
// Pre-transaction resolution phase: no side effects have happened, so any
|
|
254
297
|
// refusal here is a clean, unjournaled refusal — still mapped onto the
|
|
255
298
|
// typed ReleaseManagerError contract (rc-9), never a raw transport error.
|
|
@@ -348,7 +391,7 @@ export class ReleaseManager {
|
|
|
348
391
|
// transaction BEFORE the first side effect. If even 'planned' cannot be
|
|
349
392
|
// written, refuse with zero side effects.
|
|
350
393
|
try {
|
|
351
|
-
appendApplyTransition(journal, 'planned', `host=${
|
|
394
|
+
appendApplyTransition(journal, 'planned', `host=${deploymentHost} mode=smart source=release-manager`);
|
|
352
395
|
}
|
|
353
396
|
catch (error) {
|
|
354
397
|
// PRI-897 (CR-1): the O_EXCL create is the ATOMIC seal. If two writers
|
|
@@ -387,7 +430,7 @@ export class ReleaseManager {
|
|
|
387
430
|
workspaceDir: options.workspaceDir,
|
|
388
431
|
channels: [],
|
|
389
432
|
overwriteConfig: false,
|
|
390
|
-
host:
|
|
433
|
+
host: deploymentHost,
|
|
391
434
|
stopGateway: true,
|
|
392
435
|
}, payloadDir, { quiet: true, nonInteractive: true }, journal);
|
|
393
436
|
if (!installResult.success) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/workbuddy-adapter",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "WorkBuddy host adapter for Principles Disciple — implements the HostAdapter interface for WorkBuddy's Git Bash command-hook model (ADR-0020 third host, SPEC workbuddy-host-adapter v0.3.0).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -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
|