create-principles-disciple 1.148.9 → 1.148.11
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/codex-adapter/package.json +1 -1
- package/console/dist/server/config/WorkspaceConfigStore.js +4 -3
- package/console/dist/server/console-ports.d.ts +13 -0
- package/console/dist/server/console-ports.js +15 -0
- package/console/dist/server/index.js +51 -5
- package/console/dist/server/models/OwnerDecisionConsoleModel.d.ts +18 -0
- package/console/dist/server/models/OwnerDecisionConsoleModel.js +42 -6
- package/console/dist/server/routes/update-transaction.js +4 -4
- package/console/dist/server/routes/update.js +37 -21
- package/console/dist/server/utils/gateway.js +23 -6
- package/console/dist/server/utils/installed-layout.js +5 -3
- package/console/dist/server/utils/pd-backups.d.ts +6 -4
- package/console/dist/server/utils/pd-backups.js +8 -9
- package/console/dist/server/utils/pd-home.d.ts +34 -0
- package/console/dist/server/utils/pd-home.js +47 -0
- package/console/package.json +1 -1
- package/core/dist/runtime/activation/index.d.ts +2 -2
- package/core/dist/runtime/activation/index.d.ts.map +1 -1
- package/core/dist/runtime/activation/index.js +1 -1
- package/core/dist/runtime/activation/index.js.map +1 -1
- package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts +34 -0
- package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts.map +1 -1
- package/core/dist/runtime/activation/promotion-readiness-evaluator.js +49 -8
- package/core/dist/runtime/activation/promotion-readiness-evaluator.js.map +1 -1
- package/core/dist/runtime/activation-compatibility-read-model.d.ts +16 -0
- package/core/dist/runtime/activation-compatibility-read-model.d.ts.map +1 -1
- package/core/dist/runtime/activation-compatibility-read-model.js +32 -4
- package/core/dist/runtime/activation-compatibility-read-model.js.map +1 -1
- package/core/dist/runtime/config/pd-config-types.d.ts +0 -2
- package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-types.js.map +1 -1
- package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-validate.js +82 -0
- package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
- package/core/package.json +1 -1
- package/dist/update/bootstrap-executor.d.ts.map +1 -1
- package/dist/update/bootstrap-executor.js +33 -19
- package/dist/update/bootstrap-executor.js.map +1 -1
- package/host-runtime/package.json +1 -1
- package/install-layout/dist/index.d.ts +7 -0
- package/install-layout/dist/index.js +7 -0
- package/install-layout/dist/pd-home.d.ts +55 -0
- package/install-layout/dist/pd-home.js +226 -0
- package/install-layout/package.json +1 -1
- package/package.json +3 -3
- package/pd-cli/dist/commands/runtime-compatibility-scan.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-compatibility-scan.js +6 -0
- package/pd-cli/dist/commands/runtime-compatibility-scan.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/plugin/dist/bundle.js +284 -284
- package/release-manager/dist/update/bootstrap-executor.js +33 -19
- package/release-manager/package.json +1 -1
- package/workbuddy-adapter/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/codex-adapter",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.7",
|
|
4
4
|
"description": "Codex CLI host adapter for Principles Disciple — implements HostAdapter interface for OpenAI Codex CLI's stdin/stdout JSON hook model (ADR-0020).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
-
import
|
|
4
|
-
const CONFIG_DIR_NAME = '.pd-console';
|
|
3
|
+
import { getPdHome } from '../utils/pd-home.js';
|
|
5
4
|
const WORKSPACES_FILE = 'workspaces.json';
|
|
6
5
|
export class WorkspaceConfigStore {
|
|
7
6
|
configDir;
|
|
8
7
|
configPath;
|
|
9
8
|
entries;
|
|
10
9
|
constructor(configDir) {
|
|
11
|
-
|
|
10
|
+
// PRI-872: the registry lives in the console's PD home, never in a
|
|
11
|
+
// hard-coded `os.homedir()` — an experiment instance must own its own list.
|
|
12
|
+
this.configDir = configDir ?? getPdHome().consoleConfigDir;
|
|
12
13
|
this.configPath = path.join(this.configDir, WORKSPACES_FILE);
|
|
13
14
|
this.entries = this.load();
|
|
14
15
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Console port contract (PRI-872 / SPEC `install-mjs-dev-prod-isolation-review`
|
|
3
|
+
* §6.3). Production keeps the historical 3100; an experiment instance defaults
|
|
4
|
+
* to 13100 so a bare dev start can never take the production port.
|
|
5
|
+
*
|
|
6
|
+
* The paired gateway ports are 18789 (production, read from
|
|
7
|
+
* `<openclawHome>/openclaw.json`) and 19789 (experiment, foreground
|
|
8
|
+
* `openclaw gateway run` owned by the experiment launcher).
|
|
9
|
+
*/
|
|
10
|
+
export declare const PRODUCTION_CONSOLE_PORT = 3100;
|
|
11
|
+
export declare const EXPERIMENT_CONSOLE_PORT = 13100;
|
|
12
|
+
export declare const EXPERIMENT_GATEWAY_PORT = 19789;
|
|
13
|
+
export declare function defaultConsolePort(mode: 'production' | 'experiment'): number;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Console port contract (PRI-872 / SPEC `install-mjs-dev-prod-isolation-review`
|
|
3
|
+
* §6.3). Production keeps the historical 3100; an experiment instance defaults
|
|
4
|
+
* to 13100 so a bare dev start can never take the production port.
|
|
5
|
+
*
|
|
6
|
+
* The paired gateway ports are 18789 (production, read from
|
|
7
|
+
* `<openclawHome>/openclaw.json`) and 19789 (experiment, foreground
|
|
8
|
+
* `openclaw gateway run` owned by the experiment launcher).
|
|
9
|
+
*/
|
|
10
|
+
export const PRODUCTION_CONSOLE_PORT = 3100;
|
|
11
|
+
export const EXPERIMENT_CONSOLE_PORT = 13100;
|
|
12
|
+
export const EXPERIMENT_GATEWAY_PORT = 19789;
|
|
13
|
+
export function defaultConsolePort(mode) {
|
|
14
|
+
return mode === 'experiment' ? EXPERIMENT_CONSOLE_PORT : PRODUCTION_CONSOLE_PORT;
|
|
15
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as http from 'http';
|
|
2
2
|
import * as fs from 'fs';
|
|
3
|
-
import * as os from 'os';
|
|
4
3
|
import * as path from 'path';
|
|
5
4
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
6
5
|
import { resolveApplyFullTimeoutMs, resolveCheckTimeoutMs } from './update-timeout.js';
|
|
@@ -10,6 +9,8 @@ import { createProductTelemetryService, scheduleProductTelemetryExport } from '@
|
|
|
10
9
|
import { AuthConfig } from './config/AuthConfig.js';
|
|
11
10
|
import { assertLoopbackBindForUnauthenticatedServer } from './bind-guard.js';
|
|
12
11
|
import { WorkspaceConfigStore } from './config/WorkspaceConfigStore.js';
|
|
12
|
+
import { getPdHome, PdHomeConfigurationError } from './utils/pd-home.js';
|
|
13
|
+
import { EXPERIMENT_CONSOLE_PORT, defaultConsolePort } from './console-ports.js';
|
|
13
14
|
import { WorkspaceService } from './models/WorkspaceService.js';
|
|
14
15
|
import { handleFeedbackReportsRoute, handleFeedbackChannelsRoute, disposeFeedbackReportModels, } from './routes/feedback-reports.js';
|
|
15
16
|
import { handleFailedTasksRoute, disposeFailedTasksModels } from './routes/failed-tasks.js';
|
|
@@ -94,10 +95,12 @@ function resolveWorkspaceDir(argv) {
|
|
|
94
95
|
}
|
|
95
96
|
return process.cwd();
|
|
96
97
|
}
|
|
97
|
-
function parseArgs(argv) {
|
|
98
|
+
function parseArgs(argv, mode = 'production') {
|
|
98
99
|
const args = argv.slice(2);
|
|
99
100
|
let workspace = resolveWorkspaceDir(argv);
|
|
100
|
-
|
|
101
|
+
// PRI-872 §3: production keeps 3100; an experiment instance defaults to
|
|
102
|
+
// 13100 so a bare dev start cannot grab the production port. --port wins.
|
|
103
|
+
let port = defaultConsolePort(mode);
|
|
101
104
|
let host = '127.0.0.1';
|
|
102
105
|
let noAuth = false;
|
|
103
106
|
let token = undefined;
|
|
@@ -269,7 +272,7 @@ export async function initServices(workspaceDir, authConfig) {
|
|
|
269
272
|
// missing Owner-facing history entries from the transaction journal. Best
|
|
270
273
|
// effort only: history reconciliation never blocks console startup.
|
|
271
274
|
try {
|
|
272
|
-
reconcileUpdateHistoryFromJournals(workspaceDir,
|
|
275
|
+
reconcileUpdateHistoryFromJournals(workspaceDir, getPdHome().pdHome);
|
|
273
276
|
}
|
|
274
277
|
catch (error) {
|
|
275
278
|
console.warn('[pd-console] update history reconciliation skipped:', error instanceof Error ? error.message : error);
|
|
@@ -599,7 +602,36 @@ export function handleRequest(services) {
|
|
|
599
602
|
}
|
|
600
603
|
// ── Server startup ───────────────────────────────────────────────────────────
|
|
601
604
|
export async function main() {
|
|
602
|
-
|
|
605
|
+
// PRI-872: resolve the PD home BEFORE anything else. Everything below
|
|
606
|
+
// (registry, update history, backups, gateway probes) derives from it, and a
|
|
607
|
+
// broken experiment configuration must stop the process here instead of
|
|
608
|
+
// silently serving the production install.
|
|
609
|
+
let pdHome;
|
|
610
|
+
try {
|
|
611
|
+
pdHome = getPdHome();
|
|
612
|
+
}
|
|
613
|
+
catch (error) {
|
|
614
|
+
if (error instanceof PdHomeConfigurationError) {
|
|
615
|
+
console.error(`[pd-console] Refusing to start: ${error.reason}`);
|
|
616
|
+
console.error(`[pd-console] ${error.message}`);
|
|
617
|
+
console.error(`[pd-console] Next: ${error.nextAction}`);
|
|
618
|
+
for (const [key, value] of Object.entries(error.details)) {
|
|
619
|
+
console.error(`[pd-console] ${key}=${value}`);
|
|
620
|
+
}
|
|
621
|
+
process.exit(1);
|
|
622
|
+
}
|
|
623
|
+
throw error;
|
|
624
|
+
}
|
|
625
|
+
const { workspace, port, host, noAuth, token } = parseArgs(process.argv, pdHome.mode);
|
|
626
|
+
if (pdHome.mode === 'experiment') {
|
|
627
|
+
console.log(`[pd-console] Environment: experiment (PD_EXPERIMENT_ROOT=${pdHome.experimentRoot ?? ''})`);
|
|
628
|
+
console.log(`[pd-console] PD home: ${pdHome.pdHome}`);
|
|
629
|
+
console.log(`[pd-console] Workspace registry: ${pdHome.consoleConfigDir}`);
|
|
630
|
+
console.log(`[pd-console] OpenClaw home: ${pdHome.openclawHome}`);
|
|
631
|
+
}
|
|
632
|
+
else {
|
|
633
|
+
console.log(`[pd-console] Environment: production (PD home: ${pdHome.pdHome})`);
|
|
634
|
+
}
|
|
603
635
|
const authConfig = new AuthConfig({
|
|
604
636
|
cliToken: token,
|
|
605
637
|
envToken: process.env.PD_CONSOLE_TOKEN,
|
|
@@ -645,6 +677,20 @@ export async function main() {
|
|
|
645
677
|
};
|
|
646
678
|
process.on('SIGTERM', () => { void shutdown('SIGTERM'); });
|
|
647
679
|
process.on('SIGINT', () => { void shutdown('SIGINT'); });
|
|
680
|
+
// PRI-872: a second instance on an occupied port must fail with an
|
|
681
|
+
// actionable message, not an unhandled 'error' stack. The usual cause is the
|
|
682
|
+
// production console already listening on 3100.
|
|
683
|
+
server.on('error', (error) => {
|
|
684
|
+
if (error.code === 'EADDRINUSE') {
|
|
685
|
+
console.error(`[pd-console] Port ${port} is already in use on ${host}.`);
|
|
686
|
+
console.error(pdHome.mode === 'production'
|
|
687
|
+
? `[pd-console] Another console is probably serving this installation. Stop it, or pick another port with --port.`
|
|
688
|
+
: `[pd-console] Stop the process holding the port, or pass a different --port (the experiment default is ${EXPERIMENT_CONSOLE_PORT}).`);
|
|
689
|
+
process.exit(1);
|
|
690
|
+
}
|
|
691
|
+
console.error('[pd-console] Server error:', error);
|
|
692
|
+
process.exit(1);
|
|
693
|
+
});
|
|
648
694
|
server.listen(port, host, () => {
|
|
649
695
|
console.log('[pd-console] Listening on http://' + host + ':' + port);
|
|
650
696
|
console.log('[pd-console] Workspace: ' + workspace);
|
|
@@ -23,10 +23,28 @@ export interface OwnerDecisionItem {
|
|
|
23
23
|
readonly evidenceUnavailableReason?: string;
|
|
24
24
|
readonly createdAt: string;
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* rc-9 — 一条"本应进入收件箱但没有出现"的 RuleCode 条目。
|
|
28
|
+
*
|
|
29
|
+
* 收件箱此前用 `catch { continue; }` 吞掉 owner-review 读取失败,于是
|
|
30
|
+
* "没有待决"与"读不到"在页面上同形。这里把每类跳过显式计数,并保留
|
|
31
|
+
* 有界样本用于归因(rc-8:不放大输出)。
|
|
32
|
+
*/
|
|
33
|
+
export interface OwnerDecisionReadIssue {
|
|
34
|
+
readonly scope: 'rulecode_shadow';
|
|
35
|
+
readonly reason: 'owner_review_read_failed' | 'readiness_not_actionable' | 'shadow_scan_unavailable';
|
|
36
|
+
readonly count: number;
|
|
37
|
+
/** 最多 5 个 activation id,仅用于归因。 */
|
|
38
|
+
readonly sampleActivationIds: readonly string[];
|
|
39
|
+
/** 首个跳过原因的短摘要(≤200 字符)。 */
|
|
40
|
+
readonly detail?: string;
|
|
41
|
+
}
|
|
26
42
|
export interface OwnerDecisionListResult {
|
|
27
43
|
readonly items: readonly OwnerDecisionItem[];
|
|
28
44
|
readonly total: number;
|
|
29
45
|
readonly generatedAt: string;
|
|
46
|
+
/** rc-9:空数组 = 没有任何条目被静默吞掉。 */
|
|
47
|
+
readonly readIssues: readonly OwnerDecisionReadIssue[];
|
|
30
48
|
}
|
|
31
49
|
export declare class OwnerDecisionConsoleModel {
|
|
32
50
|
private readonly workspaceDir;
|
|
@@ -14,6 +14,12 @@ import * as path from 'node:path';
|
|
|
14
14
|
import { SqliteConnection, SqlitePIArtifactStore, SqliteApprovalQueueStore, collectOwnerDecisionFacts, deriveOwnerDecisionCapability, buildOwnerDecisionReview, } from '@principles/core/runtime';
|
|
15
15
|
import { ActivationsConsoleModel } from './ActivationsConsoleModel.js';
|
|
16
16
|
import { createArtifactPrincipleResolutionDeps, resolveArtifactPrincipleId, } from './artifact-principle-resolver.js';
|
|
17
|
+
/** 每条 issue 保留的样本上限,防止异常放大响应体。 */
|
|
18
|
+
const MAX_READ_ISSUE_SAMPLES = 5;
|
|
19
|
+
const MAX_READ_ISSUE_DETAIL_CHARS = 200;
|
|
20
|
+
function describeError(error) {
|
|
21
|
+
return error instanceof Error ? error.message : String(error);
|
|
22
|
+
}
|
|
17
23
|
const GOVERNANCE_TASK_KINDS = new Set(['evaluator', 'rollout_reviewer']);
|
|
18
24
|
/** tasks.status 合法值(PDTaskStatus)运行时守卫。 */
|
|
19
25
|
const TASK_STATUSES = new Set(['pending', 'leased', 'succeeded', 'retry_wait', 'failed', 'needs_human_review']);
|
|
@@ -191,13 +197,33 @@ export class OwnerDecisionConsoleModel {
|
|
|
191
197
|
async listOwnerDecisionItems(routeContext) {
|
|
192
198
|
const stateDbPath = path.join(this.workspaceDir, '.pd', 'state.db');
|
|
193
199
|
if (!fs.existsSync(stateDbPath)) {
|
|
194
|
-
return { items: [], total: 0, generatedAt: new Date().toISOString() };
|
|
200
|
+
return { items: [], total: 0, generatedAt: new Date().toISOString(), readIssues: [] };
|
|
195
201
|
}
|
|
196
202
|
const conn = new SqliteConnection({ workspaceDir: this.workspaceDir, readonly: true });
|
|
197
203
|
try {
|
|
198
204
|
const db = conn.getDb();
|
|
199
205
|
const artifactStore = new SqlitePIArtifactStore(conn);
|
|
200
206
|
const items = [];
|
|
207
|
+
// rc-9:被跳过/读取失败的条目必须可计数、可归因,不能只体现在"条数变少"。
|
|
208
|
+
const issueByReason = new Map();
|
|
209
|
+
const recordReadIssue = (reason, activationId, detail) => {
|
|
210
|
+
let issue = issueByReason.get(reason);
|
|
211
|
+
if (issue === undefined) {
|
|
212
|
+
issue = { scope: 'rulecode_shadow', reason, count: 0, sampleActivationIds: [] };
|
|
213
|
+
issueByReason.set(reason, issue);
|
|
214
|
+
}
|
|
215
|
+
issue.count += 1;
|
|
216
|
+
if (activationId.length > 0
|
|
217
|
+
&& issue.sampleActivationIds.length < MAX_READ_ISSUE_SAMPLES
|
|
218
|
+
&& !issue.sampleActivationIds.includes(activationId)) {
|
|
219
|
+
issue.sampleActivationIds.push(activationId);
|
|
220
|
+
}
|
|
221
|
+
if (detail !== undefined && detail.length > 0 && issue.detail === undefined) {
|
|
222
|
+
issue.detail = detail.length > MAX_READ_ISSUE_DETAIL_CHARS
|
|
223
|
+
? `${detail.slice(0, MAX_READ_ISSUE_DETAIL_CHARS)}…`
|
|
224
|
+
: detail;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
201
227
|
// ── 1. needs_human_review 的 decision-capable 任务 (PRI-629 核心) ──
|
|
202
228
|
let nhrRows = [];
|
|
203
229
|
try {
|
|
@@ -272,10 +298,14 @@ export class OwnerDecisionConsoleModel {
|
|
|
272
298
|
// Console HTTP surface for the visibility evaluation; promotion
|
|
273
299
|
// still re-evaluates at the real owner-review/promote entry.
|
|
274
300
|
const review = await activationModel.getOwnerReview(activationId, true, { routeContext });
|
|
275
|
-
if (review.readiness.status !== 'ready' && review.readiness.status !== 'evidence_insufficient')
|
|
301
|
+
if (review.readiness.status !== 'ready' && review.readiness.status !== 'evidence_insufficient') {
|
|
302
|
+
// 非待决:不进收件箱,但必须留下计数与原因(否则该 activation 永久不可见)。
|
|
303
|
+
recordReadIssue('readiness_not_actionable', activationId, `readiness=${review.readiness.status}`);
|
|
276
304
|
continue;
|
|
305
|
+
}
|
|
277
306
|
}
|
|
278
|
-
catch {
|
|
307
|
+
catch (error) {
|
|
308
|
+
recordReadIssue('owner_review_read_failed', activationId, describeError(error));
|
|
279
309
|
continue;
|
|
280
310
|
}
|
|
281
311
|
items.push({
|
|
@@ -295,10 +325,16 @@ export class OwnerDecisionConsoleModel {
|
|
|
295
325
|
});
|
|
296
326
|
}
|
|
297
327
|
}
|
|
298
|
-
catch {
|
|
299
|
-
// activations 表缺失 →
|
|
328
|
+
catch (error) {
|
|
329
|
+
// activations 表缺失 → 无影子规则可列;这本身是降级事实,必须可见。
|
|
330
|
+
recordReadIssue('shadow_scan_unavailable', '', describeError(error));
|
|
300
331
|
}
|
|
301
|
-
return {
|
|
332
|
+
return {
|
|
333
|
+
items,
|
|
334
|
+
total: items.length,
|
|
335
|
+
generatedAt: new Date().toISOString(),
|
|
336
|
+
readIssues: [...issueByReason.values()],
|
|
337
|
+
};
|
|
302
338
|
}
|
|
303
339
|
finally {
|
|
304
340
|
conn.close();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
-
import * as os from 'node:os';
|
|
4
3
|
import { sendSuccess, sendMethodNotAllowed, sendNotFound, errorMessage } from '../utils/response.js';
|
|
4
|
+
import { getPdHome } from '../utils/pd-home.js';
|
|
5
5
|
/** Transaction ids are installer/console-generated (`<word>-<ts>-<hex>`); this
|
|
6
6
|
* pattern doubles as the path-traversal guard for the journal file name (rc-1). */
|
|
7
7
|
const TRANSACTION_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
|
|
@@ -36,7 +36,7 @@ async function transactionStatus(res, transactionId) {
|
|
|
36
36
|
}
|
|
37
37
|
const journal = await import('create-principles-disciple/update-console');
|
|
38
38
|
const layout = journal;
|
|
39
|
-
const paths = layout.resolvePdHomePaths(
|
|
39
|
+
const paths = layout.resolvePdHomePaths(getPdHome().pdHome);
|
|
40
40
|
const journalPath = path.join(paths.transactionsDir, `${transactionId}.jsonl`);
|
|
41
41
|
if (!fs.existsSync(journalPath)) {
|
|
42
42
|
sendSuccess(res, { transactionId, exists: false });
|
|
@@ -65,7 +65,7 @@ async function transactionStatus(res, transactionId) {
|
|
|
65
65
|
async function recoveryStatus(res) {
|
|
66
66
|
const journal = await import('create-principles-disciple/update-console');
|
|
67
67
|
const layout = journal;
|
|
68
|
-
const paths = layout.resolvePdHomePaths(
|
|
68
|
+
const paths = layout.resolvePdHomePaths(getPdHome().pdHome);
|
|
69
69
|
const entries = (() => {
|
|
70
70
|
try {
|
|
71
71
|
return fs.readdirSync(paths.transactionsDir, { withFileTypes: true })
|
|
@@ -209,7 +209,7 @@ async function recoveryResolve(res, req) {
|
|
|
209
209
|
}
|
|
210
210
|
const journal = await import('create-principles-disciple/update-console');
|
|
211
211
|
const layout = journal;
|
|
212
|
-
const paths = layout.resolvePdHomePaths(
|
|
212
|
+
const paths = layout.resolvePdHomePaths(getPdHome().pdHome);
|
|
213
213
|
const journalPath = path.join(paths.transactionsDir, `${transactionId}.jsonl`);
|
|
214
214
|
if (!fs.existsSync(journalPath)) {
|
|
215
215
|
sendSuccess(res, { ok: false, reason: 'unknown_transaction', message: `No journal exists for transaction ${transactionId}.` });
|
|
@@ -4,6 +4,7 @@ import * as os from 'node:os';
|
|
|
4
4
|
import { spawn } from 'node:child_process';
|
|
5
5
|
import { randomUUID } from 'node:crypto';
|
|
6
6
|
import { sendSuccess, sendMethodNotAllowed, sendNotFound, errorMessage } from '../utils/response.js';
|
|
7
|
+
import { getPdHome, isExperimentInstance } from '../utils/pd-home.js';
|
|
7
8
|
import { appendUpdateHistory } from './update-history.js';
|
|
8
9
|
const REPAIR_ACTION = 'Resolve the reported cause, or run the official installer (npx create-principles-disciple) to repair the installation, then retry.';
|
|
9
10
|
function appendGovernedUpdateHistory(workspaceDir, entry) {
|
|
@@ -56,7 +57,7 @@ async function checkUpdate(authority, res) {
|
|
|
56
57
|
*/
|
|
57
58
|
async function applyFullUpdate(authority, res, workspaceDir) {
|
|
58
59
|
const layout = await import('create-principles-disciple/update-console');
|
|
59
|
-
const pdHomePaths = layout.resolvePdHomePaths(
|
|
60
|
+
const pdHomePaths = layout.resolvePdHomePaths(getPdHome().pdHome);
|
|
60
61
|
const entryPath = path.join(pdHomePaths.bootstrapExecutorDir, 'dist', 'bootstrap-entry.js');
|
|
61
62
|
// Readiness already re-verified the registration digest, but the route owns
|
|
62
63
|
// the spawn-level guard: no executor file → repair next action (this is the
|
|
@@ -190,29 +191,44 @@ export async function handleUpdateRoute(req, res, workspaceDir, subPath) {
|
|
|
190
191
|
let mod;
|
|
191
192
|
let authority;
|
|
192
193
|
let failure = { reason: 'installer_missing', message: 'ReleaseManager is unavailable.', nextAction: REPAIR_ACTION, transactionOpened: false };
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
194
|
+
// PRI-872: an experiment console owns `<root>/.pd`, which is not a signed
|
|
195
|
+
// install. Refuse explicitly instead of letting the readiness gate report a
|
|
196
|
+
// misleading `install_state_corrupt` — and, above all, keep the real
|
|
197
|
+
// installer (which stops the machine-level gateway and swaps the production
|
|
198
|
+
// runtime) unreachable from a second instance.
|
|
199
|
+
if (isExperimentInstance()) {
|
|
200
|
+
failure = {
|
|
201
|
+
reason: 'experimental_instance',
|
|
202
|
+
message: 'This console is an experiment instance; product updates apply to the production installation only.',
|
|
203
|
+
nextAction: 'Run the update from the production console, or install the experiment build with the official installer while PD_EXPERIMENT_ROOT points at this root.',
|
|
204
|
+
transactionOpened: false,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
try {
|
|
209
|
+
mod = await import('create-principles-disciple/update-console');
|
|
210
|
+
authority = mod.createReleaseManagerAuthority({
|
|
211
|
+
pdHome: getPdHome().pdHome,
|
|
212
|
+
metadataBaseUrl: process.env.PD_RELEASE_METADATA_URL,
|
|
213
|
+
});
|
|
214
|
+
const readiness = authority.kinds[subPath === '/check' ? 'check' : 'apply-full'];
|
|
215
|
+
if (!readiness.ready || authority.installStatus === null) {
|
|
216
|
+
failure = { ...failure, reason: readiness.reasons.join(',') || 'install_state_corrupt', message: 'The installation is not ready for a signed release update.' };
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
if (subPath === '/check')
|
|
220
|
+
await checkUpdate(authority, res);
|
|
221
|
+
else
|
|
222
|
+
await applyFullUpdate(authority, res, workspaceDir);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
202
225
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
await applyFullUpdate(authority, res, workspaceDir);
|
|
208
|
-
return;
|
|
226
|
+
catch (error) {
|
|
227
|
+
failure = mod
|
|
228
|
+
? mod.mapReleaseManagerError(error)
|
|
229
|
+
: { ...failure, message: errorMessage(error) };
|
|
209
230
|
}
|
|
210
231
|
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
failure = mod
|
|
213
|
-
? mod.mapReleaseManagerError(error)
|
|
214
|
-
: { ...failure, message: errorMessage(error) };
|
|
215
|
-
}
|
|
216
232
|
console.error(`[update] ${subPath} refused (${failure.reason}): ${failure.message}`);
|
|
217
233
|
if (subPath === '/check') {
|
|
218
234
|
// SPEC §12.1: a check that cannot complete is check_failed — it must never
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
import { execFileSync } from 'child_process';
|
|
11
11
|
import * as fs from 'fs';
|
|
12
12
|
import * as path from 'path';
|
|
13
|
-
import * as os from 'os';
|
|
14
13
|
import * as net from 'net';
|
|
15
14
|
import { errorMessage } from './response.js';
|
|
15
|
+
import { getPdHome, getPdHomeResolution } from './pd-home.js';
|
|
16
16
|
// rc-2: type guard instead of `as` cast on parsed JSON.
|
|
17
17
|
function isRecord(v) {
|
|
18
18
|
return typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
@@ -22,13 +22,14 @@ function isRecord(v) {
|
|
|
22
22
|
// ---------------------------------------------------------------------------
|
|
23
23
|
/**
|
|
24
24
|
* Resolve the OpenClaw config directory.
|
|
25
|
-
*
|
|
25
|
+
*
|
|
26
|
+
* PRI-872: derived from the process-wide PD home (production keeps
|
|
27
|
+
* OPENCLAW_HOME > ~/.openclaw; an experiment instance reads its own root), so
|
|
28
|
+
* the console never reports or probes the production gateway from a second
|
|
29
|
+
* instance.
|
|
26
30
|
*/
|
|
27
31
|
function resolveOpenClawConfigDir() {
|
|
28
|
-
|
|
29
|
-
if (envHome && envHome.trim().length > 0)
|
|
30
|
-
return path.resolve(envHome);
|
|
31
|
-
return path.join(os.homedir(), '.openclaw');
|
|
32
|
+
return getPdHome().openclawHome;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* Read the gateway port from ~/.openclaw/openclaw.json → { gateway: { port } }.
|
|
@@ -112,6 +113,22 @@ export async function checkOpenClawGateway() {
|
|
|
112
113
|
* with a structured reason + nextAction instead of crashing mid-update.
|
|
113
114
|
*/
|
|
114
115
|
function runGatewayServiceCommand(subcommand, extraArgs = []) {
|
|
116
|
+
// PRI-872: `openclaw gateway stop|start` drives the MACHINE-LEVEL service
|
|
117
|
+
// (launchd/systemd/schtasks), not a process this console owns. An experiment
|
|
118
|
+
// instance must never stop the production gateway — its own gateway is a
|
|
119
|
+
// foreground `openclaw gateway run` owned by the experiment launcher.
|
|
120
|
+
// Resolution failure is reported, not thrown: this helper's contract is
|
|
121
|
+
// "never throws" (rc-9), so callers degrade on a structured result.
|
|
122
|
+
const pdHome = getPdHomeResolution();
|
|
123
|
+
if (!pdHome.ok) {
|
|
124
|
+
return { ok: false, error: `pd_home_invalid (${pdHome.reason}): ${pdHome.message}` };
|
|
125
|
+
}
|
|
126
|
+
if (pdHome.mode === 'experiment') {
|
|
127
|
+
return {
|
|
128
|
+
ok: false,
|
|
129
|
+
error: 'experimental_instance: the machine-level OpenClaw service belongs to the production install; the experiment gateway runs in the foreground under the experiment launcher and must be restarted there.',
|
|
130
|
+
};
|
|
131
|
+
}
|
|
115
132
|
try {
|
|
116
133
|
// EP-08: argv array + typed subcommand union — every argv is a constant
|
|
117
134
|
// literal, so no external input can reach the command line. shell:true is
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import * as fs from 'fs';
|
|
14
14
|
import * as path from 'path';
|
|
15
|
-
import * as os from 'os';
|
|
16
15
|
import { getInstallLayoutPaths, resolveInstallLayout } from '@principles/install-layout';
|
|
17
16
|
import { resolveOpenClawHome } from './pd-backups.js';
|
|
17
|
+
import { getPdHome } from './pd-home.js';
|
|
18
18
|
export function resolveExtensionsDir() {
|
|
19
19
|
return path.join(resolveOpenClawHome(), 'extensions');
|
|
20
20
|
}
|
|
@@ -42,7 +42,9 @@ function resolveCanonicalCodexAdapterDir(paths) {
|
|
|
42
42
|
: undefined;
|
|
43
43
|
}
|
|
44
44
|
export function resolveUpdateLayout() {
|
|
45
|
-
|
|
45
|
+
// PRI-872: the home comes from the process-wide resolution, so an experiment
|
|
46
|
+
// console inspects the EXPERIMENT install instead of the production one.
|
|
47
|
+
const { homeDir } = getPdHome();
|
|
46
48
|
const paths = getInstallLayoutPaths(homeDir);
|
|
47
49
|
const legacyPluginDir = path.join(resolveExtensionsDir(), 'principles-disciple');
|
|
48
50
|
let manifest;
|
|
@@ -99,7 +101,7 @@ export function resolvePluginDir(_workspaceDir) {
|
|
|
99
101
|
* guard allow-root even when the install resolves to legacy mode.
|
|
100
102
|
*/
|
|
101
103
|
export function resolveCanonicalRuntimeRoot() {
|
|
102
|
-
return getInstallLayoutPaths(
|
|
104
|
+
return getInstallLayoutPaths(getPdHome().homeDir).runtimeDir;
|
|
103
105
|
}
|
|
104
106
|
// rc-2: type-guard the parsed JSON instead of an `as` cast (ERR-001).
|
|
105
107
|
function isRecord(value) {
|
|
@@ -7,11 +7,13 @@ export interface LegacyBackupMigrationResult {
|
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Resolve the OpenClaw install home.
|
|
10
|
-
* Priority: OPENCLAW_HOME env var (explicit override) > ~/.openclaw
|
|
11
10
|
*
|
|
12
|
-
*
|
|
13
|
-
* (
|
|
14
|
-
*
|
|
11
|
+
* PRI-872: delegated to the process-wide PD home resolution. In production it
|
|
12
|
+
* keeps the historical priority (OPENCLAW_HOME env var > ~/.openclaw); in an
|
|
13
|
+
* experiment instance it points at the experiment root, so backup placement
|
|
14
|
+
* and installed-layout resolution can never read the production host.
|
|
15
|
+
* Single authority for home resolution — `resolvePdBackupsRoot` and
|
|
16
|
+
* `utils/installed-layout.ts` both derive from it.
|
|
15
17
|
*/
|
|
16
18
|
export declare function resolveOpenClawHome(): string;
|
|
17
19
|
/** Backups root — outside the extensions dir OpenClaw scans for plugins. */
|
|
@@ -16,21 +16,20 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import * as fs from 'fs';
|
|
18
18
|
import * as path from 'path';
|
|
19
|
-
import * as os from 'os';
|
|
20
19
|
import { errorMessage } from './response.js';
|
|
20
|
+
import { getPdHome } from './pd-home.js';
|
|
21
21
|
/**
|
|
22
22
|
* Resolve the OpenClaw install home.
|
|
23
|
-
* Priority: OPENCLAW_HOME env var (explicit override) > ~/.openclaw
|
|
24
23
|
*
|
|
25
|
-
*
|
|
26
|
-
* (
|
|
27
|
-
*
|
|
24
|
+
* PRI-872: delegated to the process-wide PD home resolution. In production it
|
|
25
|
+
* keeps the historical priority (OPENCLAW_HOME env var > ~/.openclaw); in an
|
|
26
|
+
* experiment instance it points at the experiment root, so backup placement
|
|
27
|
+
* and installed-layout resolution can never read the production host.
|
|
28
|
+
* Single authority for home resolution — `resolvePdBackupsRoot` and
|
|
29
|
+
* `utils/installed-layout.ts` both derive from it.
|
|
28
30
|
*/
|
|
29
31
|
export function resolveOpenClawHome() {
|
|
30
|
-
|
|
31
|
-
if (envHome && envHome.trim().length > 0)
|
|
32
|
-
return path.resolve(envHome);
|
|
33
|
-
return path.join(os.homedir(), '.openclaw');
|
|
32
|
+
return getPdHome().openclawHome;
|
|
34
33
|
}
|
|
35
34
|
/** Backups root — outside the extensions dir OpenClaw scans for plugins. */
|
|
36
35
|
export function resolvePdBackupsRoot() {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The console's single entry point for "which PD home am I serving?".
|
|
3
|
+
*
|
|
4
|
+
* PRI-872: every route and store used to call `os.homedir()` directly, so a
|
|
5
|
+
* second console (a dev/experiment instance) silently read and MUTATED the
|
|
6
|
+
* production install: the update page resolved `~/.pd`, "apply" spawned the
|
|
7
|
+
* production bootstrap executor, and both instances shared
|
|
8
|
+
* `~/.pd-console/workspaces.json`.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately NOT cached: the resolver is a pure derivation from the
|
|
11
|
+
* environment plus a handful of path syscalls, and caching would pin the
|
|
12
|
+
* answer for the process lifetime — including across tests and across a
|
|
13
|
+
* launcher that re-points the root. The failure mode stays fail-closed either
|
|
14
|
+
* way: an unusable `PD_EXPERIMENT_ROOT` throws, it never falls back to the
|
|
15
|
+
* real user home.
|
|
16
|
+
*/
|
|
17
|
+
import { type PdHomeFailureReason, type PdHomePaths, type PdHomeResolution } from '@principles/install-layout';
|
|
18
|
+
export declare class PdHomeConfigurationError extends Error {
|
|
19
|
+
readonly reason: PdHomeFailureReason;
|
|
20
|
+
readonly nextAction: string;
|
|
21
|
+
readonly details: Readonly<Record<string, string>>;
|
|
22
|
+
constructor(failure: Extract<PdHomeResolution, {
|
|
23
|
+
ok: false;
|
|
24
|
+
}>);
|
|
25
|
+
}
|
|
26
|
+
export declare function getPdHomeResolution(): PdHomeResolution;
|
|
27
|
+
/** Throws `PdHomeConfigurationError` when the environment is unusable. */
|
|
28
|
+
export declare function getPdHome(): PdHomePaths;
|
|
29
|
+
/**
|
|
30
|
+
* True only for an explicitly declared experiment instance. A broken
|
|
31
|
+
* configuration throws rather than answering `false` — "cannot tell" must not
|
|
32
|
+
* be reported as "production".
|
|
33
|
+
*/
|
|
34
|
+
export declare function isExperimentInstance(): boolean;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The console's single entry point for "which PD home am I serving?".
|
|
3
|
+
*
|
|
4
|
+
* PRI-872: every route and store used to call `os.homedir()` directly, so a
|
|
5
|
+
* second console (a dev/experiment instance) silently read and MUTATED the
|
|
6
|
+
* production install: the update page resolved `~/.pd`, "apply" spawned the
|
|
7
|
+
* production bootstrap executor, and both instances shared
|
|
8
|
+
* `~/.pd-console/workspaces.json`.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately NOT cached: the resolver is a pure derivation from the
|
|
11
|
+
* environment plus a handful of path syscalls, and caching would pin the
|
|
12
|
+
* answer for the process lifetime — including across tests and across a
|
|
13
|
+
* launcher that re-points the root. The failure mode stays fail-closed either
|
|
14
|
+
* way: an unusable `PD_EXPERIMENT_ROOT` throws, it never falls back to the
|
|
15
|
+
* real user home.
|
|
16
|
+
*/
|
|
17
|
+
import { resolvePdHome, } from '@principles/install-layout';
|
|
18
|
+
export class PdHomeConfigurationError extends Error {
|
|
19
|
+
reason;
|
|
20
|
+
nextAction;
|
|
21
|
+
details;
|
|
22
|
+
constructor(failure) {
|
|
23
|
+
super(failure.message);
|
|
24
|
+
this.name = 'PdHomeConfigurationError';
|
|
25
|
+
this.reason = failure.reason;
|
|
26
|
+
this.nextAction = failure.nextAction;
|
|
27
|
+
this.details = failure.details;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function getPdHomeResolution() {
|
|
31
|
+
return resolvePdHome();
|
|
32
|
+
}
|
|
33
|
+
/** Throws `PdHomeConfigurationError` when the environment is unusable. */
|
|
34
|
+
export function getPdHome() {
|
|
35
|
+
const resolution = getPdHomeResolution();
|
|
36
|
+
if (!resolution.ok)
|
|
37
|
+
throw new PdHomeConfigurationError(resolution);
|
|
38
|
+
return resolution;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* True only for an explicitly declared experiment instance. A broken
|
|
42
|
+
* configuration throws rather than answering `false` — "cannot tell" must not
|
|
43
|
+
* be reported as "production".
|
|
44
|
+
*/
|
|
45
|
+
export function isExperimentInstance() {
|
|
46
|
+
return getPdHome().mode === 'experiment';
|
|
47
|
+
}
|
package/console/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"build:ui:production": "node scripts/build-ui.mjs --production",
|
|
9
9
|
"build": "npm run clean && npm run build:ui:production && tsc -p tsconfig.build.json && node ../../scripts/build/check-dist-hygiene.mjs",
|
|
10
10
|
"clean": "node ../../scripts/build/clean-dist.mjs",
|
|
11
|
-
"dev": "npx tsx src/server/index.ts
|
|
11
|
+
"dev": "npx tsx src/server/index.ts",
|
|
12
12
|
"start": "node dist/server.js",
|
|
13
13
|
"test": "vitest run",
|
|
14
14
|
"test:watch": "vitest",
|
|
@@ -11,8 +11,8 @@ export { SqliteActivationSafetyStore } from './sqlite-activation-safety-store.js
|
|
|
11
11
|
export type { ActivationDecisionRecord, ActivationDecisionSubject, ActivationDecisionKind, ActivationControlState, GlobalRuleCodePause } from './activation-control-types.js';
|
|
12
12
|
export { RuleCodeOwnerDecisionService } from './rulecode-owner-decision-service.js';
|
|
13
13
|
export type { PromotionEvidenceSnapshot, PromotionFailedCheck, PromotionReadinessResult, OwnerPromotionActor, OwnerPromotionRequest, PromotionCommitInput, OwnerPromotionResult, RuleCodeOwnerDecisionServiceDeps, } from './rulecode-owner-decision-service.js';
|
|
14
|
-
export { REQUIRED_PROMOTION_CHECK_IDS, evaluateRuleCodePromotionReadiness } from './promotion-readiness-evaluator.js';
|
|
15
|
-
export type { PromotionCheckId, PromotionReadinessCheck, PromotionReadinessEvaluationInput } from './promotion-readiness-evaluator.js';
|
|
14
|
+
export { REQUIRED_PROMOTION_CHECK_IDS, PROMOTION_EVIDENCE_THRESHOLDS, evaluateRuleCodePromotionReadiness, evaluatePromotionEvidenceCriteria, explainPromotionReadiness, } from './promotion-readiness-evaluator.js';
|
|
15
|
+
export type { PromotionCheckId, PromotionReadinessCheck, PromotionReadinessEvaluationInput, PromotionEvidenceCriterionId, PromotionEvidenceCriterion, } from './promotion-readiness-evaluator.js';
|
|
16
16
|
export { PromotionReadinessReader } from './promotion-readiness-reader.js';
|
|
17
17
|
export type { PromotionReadinessReaderDeps } from './promotion-readiness-reader.js';
|
|
18
18
|
export { evaluateRuleCodeSafetyCircuit, initialRuleCodeSafetyCircuitState } from './rulecode-safety-circuit-breaker.js';
|