create-principles-disciple 1.150.6 → 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.
Files changed (169) hide show
  1. package/README.md +5 -5
  2. package/_release/product-identity.json +1 -1
  3. package/codex-adapter/dist/ingestion/codex-version.d.ts +14 -12
  4. package/codex-adapter/dist/ingestion/codex-version.js +19 -20
  5. package/codex-adapter/package.json +1 -1
  6. package/console/dist/server/bind-guard.d.ts +6 -13
  7. package/console/dist/server/bind-guard.js +8 -17
  8. package/console/dist/server/index.d.ts +9 -3
  9. package/console/dist/server/index.js +55 -53
  10. package/console/dist/server/models/ActivationsConsoleModel.js +2 -1
  11. package/console/dist/server/models/OwnerDecisionConsoleModel.js +58 -19
  12. package/console/dist/server/routes/activations.js +2 -2
  13. package/console/dist/server/routes/diagnostician.js +1 -1
  14. package/console/dist/server/routes/evidence-outcomes.d.ts +3 -2
  15. package/console/dist/server/routes/evidence-outcomes.js +1 -1
  16. package/console/dist/server/routes/failed-tasks.js +85 -2
  17. package/console/dist/server/routes/governance.d.ts +9 -6
  18. package/console/dist/server/routes/governance.js +10 -6
  19. package/console/dist/server/routes/owner-decisions.d.ts +3 -3
  20. package/console/dist/server/routes/owner-decisions.js +1 -1
  21. package/console/dist/server/routes/owner-identity.d.ts +4 -5
  22. package/console/dist/server/routes/owner-identity.js +4 -4
  23. package/console/dist/server/routes/rule-candidate-bindings.js +1 -1
  24. package/console/dist/server/routes/update.js +24 -6
  25. package/console/dist/server/utils/request-guard.d.ts +35 -0
  26. package/console/dist/server/utils/request-guard.js +81 -0
  27. package/console/dist/server/utils/response.d.ts +0 -1
  28. package/console/dist/server/utils/response.js +0 -3
  29. package/console/dist/web/assets/app.css +95 -167
  30. package/console/dist/web/assets/app.js +32 -37
  31. package/core/dist/runtime/activation/activation-control-types.d.ts +3 -0
  32. package/core/dist/runtime/activation/activation-control-types.d.ts.map +1 -1
  33. package/core/dist/runtime/activation/ledger-identity.d.ts.map +1 -1
  34. package/core/dist/runtime/activation/ledger-identity.js +5 -0
  35. package/core/dist/runtime/activation/ledger-identity.js.map +1 -1
  36. package/core/dist/runtime/activation/prompt-activation-reader-contract.d.ts +6 -0
  37. package/core/dist/runtime/activation/prompt-activation-reader-contract.d.ts.map +1 -1
  38. package/core/dist/runtime/activation/prompt-activation-reader-contract.js +105 -7
  39. package/core/dist/runtime/activation/prompt-activation-reader-contract.js.map +1 -1
  40. package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts.map +1 -1
  41. package/core/dist/runtime/activation/rulecode-owner-decision-service.js +3 -2
  42. package/core/dist/runtime/activation/rulecode-owner-decision-service.js.map +1 -1
  43. package/core/dist/runtime/activation/sqlite-activation-safety-store.d.ts.map +1 -1
  44. package/core/dist/runtime/activation/sqlite-activation-safety-store.js +26 -13
  45. package/core/dist/runtime/activation/sqlite-activation-safety-store.js.map +1 -1
  46. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
  47. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js +22 -8
  48. package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js.map +1 -1
  49. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.d.ts.map +1 -1
  50. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js +10 -1
  51. package/core/dist/runtime/adapter/principle-tree-ledger-adapter.js.map +1 -1
  52. package/core/dist/runtime/adapter/structured-output-repair.d.ts +17 -2
  53. package/core/dist/runtime/adapter/structured-output-repair.d.ts.map +1 -1
  54. package/core/dist/runtime/adapter/structured-output-repair.js +26 -5
  55. package/core/dist/runtime/adapter/structured-output-repair.js.map +1 -1
  56. package/core/dist/runtime/governance-experience-contract.d.ts +12 -12
  57. package/core/dist/runtime/governance-experience-contract.d.ts.map +1 -1
  58. package/core/dist/runtime/governance-experience-contract.js +0 -2
  59. package/core/dist/runtime/governance-experience-contract.js.map +1 -1
  60. package/core/dist/runtime/governance-experience.d.ts.map +1 -1
  61. package/core/dist/runtime/governance-experience.js +8 -16
  62. package/core/dist/runtime/governance-experience.js.map +1 -1
  63. package/core/dist/runtime/internalization/approved-rule-revision.d.ts.map +1 -1
  64. package/core/dist/runtime/internalization/approved-rule-revision.js +2 -1
  65. package/core/dist/runtime/internalization/approved-rule-revision.js.map +1 -1
  66. package/core/dist/runtime/internalization/pitask-metadata.d.ts +1 -1
  67. package/core/dist/runtime/internalization/pitask-metadata.d.ts.map +1 -1
  68. package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts +13 -0
  69. package/core/dist/runtime/internalization/rollout-reviewer-runner.d.ts.map +1 -1
  70. package/core/dist/runtime/internalization/rollout-reviewer-runner.js +28 -4
  71. package/core/dist/runtime/internalization/rollout-reviewer-runner.js.map +1 -1
  72. package/core/dist/runtime/internalization/scribe-runner.d.ts.map +1 -1
  73. package/core/dist/runtime/internalization/scribe-runner.js +25 -3
  74. package/core/dist/runtime/internalization/scribe-runner.js.map +1 -1
  75. package/core/dist/runtime/recovery-sweep-service.d.ts +7 -0
  76. package/core/dist/runtime/recovery-sweep-service.d.ts.map +1 -1
  77. package/core/dist/runtime/recovery-sweep-service.js +1 -0
  78. package/core/dist/runtime/recovery-sweep-service.js.map +1 -1
  79. package/core/dist/runtime/signal-collector/types.d.ts +6 -0
  80. package/core/dist/runtime/signal-collector/types.d.ts.map +1 -1
  81. package/core/dist/runtime/signal-collector/types.js.map +1 -1
  82. package/core/dist/runtime/store/context/promoted-evidence-reader.d.ts +59 -0
  83. package/core/dist/runtime/store/context/promoted-evidence-reader.d.ts.map +1 -0
  84. package/core/dist/runtime/store/context/promoted-evidence-reader.js +201 -0
  85. package/core/dist/runtime/store/context/promoted-evidence-reader.js.map +1 -0
  86. package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
  87. package/core/dist/runtime/store/context/sqlite-context-assembler.js +43 -2
  88. package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
  89. package/core/dist/runtime/store/sqlite-connection.d.ts.map +1 -1
  90. package/core/dist/runtime/store/sqlite-connection.js +96 -37
  91. package/core/dist/runtime/store/sqlite-connection.js.map +1 -1
  92. package/core/dist/runtime/types/rule-candidate-binding.d.ts +1 -1
  93. package/core/dist/runtime/types/rule-candidate-binding.d.ts.map +1 -1
  94. package/core/package.json +1 -1
  95. package/dist/index.js +34 -0
  96. package/dist/index.js.map +1 -1
  97. package/dist/installer.d.ts +49 -0
  98. package/dist/installer.d.ts.map +1 -1
  99. package/dist/installer.js +118 -78
  100. package/dist/installer.js.map +1 -1
  101. package/dist/installers/index.d.ts +31 -0
  102. package/dist/installers/index.d.ts.map +1 -1
  103. package/dist/installers/index.js +76 -3
  104. package/dist/installers/index.js.map +1 -1
  105. package/dist/mvp-config.js +1 -1
  106. package/dist/mvp-config.js.map +1 -1
  107. package/dist/update/data-compatibility.d.ts.map +1 -1
  108. package/dist/update/data-compatibility.js +3 -1
  109. package/dist/update/data-compatibility.js.map +1 -1
  110. package/dist/update/release-manager.d.ts +6 -1
  111. package/dist/update/release-manager.d.ts.map +1 -1
  112. package/dist/update/release-manager.js +56 -3
  113. package/dist/update/release-manager.js.map +1 -1
  114. package/host-runtime/dist/active-principle-prompt.js +1 -0
  115. package/host-runtime/dist/adaptive-decision-protocol.d.ts +36 -8
  116. package/host-runtime/dist/adaptive-decision-protocol.js +79 -20
  117. package/host-runtime/dist/adaptive-selection.js +6 -1
  118. package/host-runtime/dist/cli-recovery-probe.d.ts +42 -1
  119. package/host-runtime/dist/cli-recovery-probe.js +16 -3
  120. package/host-runtime/dist/conversation-ingestion/pipeline.d.ts +0 -29
  121. package/host-runtime/dist/conversation-ingestion/pipeline.js +39 -2
  122. package/host-runtime/dist/governance-signal-admission.js +12 -0
  123. package/host-runtime/dist/prompt-activation-deliverability.d.ts +2 -0
  124. package/host-runtime/dist/prompt-activation-deliverability.js +2 -0
  125. package/host-runtime/dist/prompt-injection-status.js +1 -0
  126. package/host-runtime/package.json +1 -1
  127. package/install-layout/dist/mcp-binding-contract.js +5 -0
  128. package/install-layout/package.json +1 -1
  129. package/package.json +3 -3
  130. package/pd-cli/dist/commands/candidate.d.ts.map +1 -1
  131. package/pd-cli/dist/commands/candidate.js +117 -3
  132. package/pd-cli/dist/commands/candidate.js.map +1 -1
  133. package/pd-cli/dist/commands/console.d.ts +0 -4
  134. package/pd-cli/dist/commands/console.d.ts.map +1 -1
  135. package/pd-cli/dist/commands/console.js +8 -63
  136. package/pd-cli/dist/commands/console.js.map +1 -1
  137. package/pd-cli/dist/commands/runtime-activation.d.ts.map +1 -1
  138. package/pd-cli/dist/commands/runtime-activation.js +4 -8
  139. package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
  140. package/pd-cli/dist/commands/runtime-recovery-failed-tasks.d.ts.map +1 -1
  141. package/pd-cli/dist/commands/runtime-recovery-failed-tasks.js +114 -63
  142. package/pd-cli/dist/commands/runtime-recovery-failed-tasks.js.map +1 -1
  143. package/pd-cli/dist/program.d.ts.map +1 -1
  144. package/pd-cli/dist/program.js +0 -8
  145. package/pd-cli/dist/program.js.map +1 -1
  146. package/pd-cli/dist/services/console-launcher.d.ts +13 -15
  147. package/pd-cli/dist/services/console-launcher.d.ts.map +1 -1
  148. package/pd-cli/dist/services/console-launcher.js +3 -85
  149. package/pd-cli/dist/services/console-launcher.js.map +1 -1
  150. package/pd-cli/package.json +1 -1
  151. package/pd-mcp-server/dist/version.d.ts +1 -1
  152. package/pd-mcp-server/dist/version.js +1 -1
  153. package/pd-mcp-server/package.json +1 -1
  154. package/plugin/dist/bundle.js +469 -452
  155. package/plugin/dist/core/mcp-binding.d.ts +3 -1
  156. package/plugin/dist/core/signal-collector-host.d.ts +19 -1
  157. package/plugin/dist/openclaw.plugin.json +1 -1
  158. package/plugin/mcp/launcher.cjs +85 -0
  159. package/plugin/openclaw.plugin.json +1 -1
  160. package/plugin/package.json +1 -1
  161. package/release-manager/dist/installer.js +118 -78
  162. package/release-manager/dist/installers/index.js +76 -3
  163. package/release-manager/dist/mvp-config.js +1 -1
  164. package/release-manager/dist/update/release-manager.js +56 -3
  165. package/release-manager/package.json +1 -1
  166. package/workbuddy-adapter/package.json +1 -1
  167. package/workbuddy-adapter/plugin/mcp/launcher.cjs +85 -0
  168. package/console/dist/server/config/AuthConfig.d.ts +0 -14
  169. package/console/dist/server/config/AuthConfig.js +0 -42
@@ -5,8 +5,9 @@
5
5
  *
6
6
  * 最小获授权事实入口:Owner 可以对一个已存在的 Behavior Episode 提交
7
7
  * 明确的结果观察/反馈。安全模型(复用 owner-decisions 的模式):
8
- * - 全局 console token 认证由 server/index.ts 统一强制;
9
- * - Owner 身份从 server-side auth context 推导,body 中的身份字段一律
8
+ * - 来源守卫(Host/Origin/Sec-Fetch-Site/JSON Content-Type)由
9
+ * server/index.ts 统一强制;
10
+ * - Owner 身份从服务端身份解析结果推导,body 中的身份字段一律
10
11
  * 不信任 —— actorId 由服务端写入,请求方无法自称;
11
12
  * - 封闭字段集:任何 runtime 证明字段(runtime_verified / proof /
12
13
  * activation 决策等)都不存在于此 contract,LLM/Agent 无法伪装成
@@ -65,7 +65,7 @@ export async function handleEvidenceOutcomesRoute(req, res, ctx) {
65
65
  }
66
66
  // 身份门槛与 owner-decisions 一致:没有已验证 Owner 身份就拒绝写。
67
67
  if (!ctx.ownerIdentity) {
68
- sendError(res, 403, 'owner_authentication_required', 'Recording an Owner outcome requires a verified Owner identity (console token auth enabled and owner identity resolved).');
68
+ sendError(res, 403, 'owner_authentication_required', 'Recording an Owner outcome requires a registered Owner identity (owner identity configured and resolved).');
69
69
  return;
70
70
  }
71
71
  let rawBody;
@@ -316,7 +316,7 @@ async function dispatchRecovery(workspaceDir, taskId, force) {
316
316
  httpStatus: 409,
317
317
  errorCode: 'owner_decision_required',
318
318
  message: 'This task awaits an Owner decision (accept current / revise once / reject). Recover is not a governance exit and was refused.',
319
- nextAction: 'Open the Console governance focus (#/focus) and resolve the decision there.',
319
+ nextAction: 'Open the Console governance workbench (#/workbench) and resolve the decision there.',
320
320
  },
321
321
  };
322
322
  }
@@ -379,6 +379,58 @@ function optionalString(obj, key) {
379
379
  const value = obj[key];
380
380
  return typeof value === 'string' ? value : null;
381
381
  }
382
+ /** `detail` may itself be a JSON document; expose its useful fields without inventing them. */
383
+ function detailFields(detail) {
384
+ if (detail === null)
385
+ return { missingFields: [], nextAction: null };
386
+ try {
387
+ const parsed = JSON.parse(detail);
388
+ if (!isRecord(parsed))
389
+ return { missingFields: [], nextAction: null };
390
+ return {
391
+ missingFields: toStringArray(parsed.missingFields),
392
+ nextAction: optionalString(parsed, 'nextAction'),
393
+ };
394
+ }
395
+ catch {
396
+ return { missingFields: [], nextAction: null };
397
+ }
398
+ }
399
+ function projectHumanReview(value) {
400
+ const record = asRecord(value);
401
+ if (!record)
402
+ return null;
403
+ const detail = optionalString(record, 'detail');
404
+ const { missingFields, nextAction } = detailFields(detail);
405
+ return {
406
+ reasonCode: optionalString(record, 'reasonCode'),
407
+ detail,
408
+ missingFields,
409
+ nextAction,
410
+ sourceRunId: optionalString(record, 'sourceRunId'),
411
+ sourceArtifactId: optionalString(record, 'sourceArtifactId'),
412
+ createdAt: optionalString(record, 'createdAt'),
413
+ };
414
+ }
415
+ function projectIdentityPreflight(value) {
416
+ const record = asRecord(value);
417
+ if (!record)
418
+ return null;
419
+ const generatedRaw = Object.hasOwn(record, 'generated') ? record.generated : null;
420
+ return {
421
+ status: optionalString(record, 'status'),
422
+ reasonCode: optionalString(record, 'reasonCode') ?? optionalString(record, 'reason'),
423
+ detail: optionalString(record, 'detail') ?? optionalString(record, 'message'),
424
+ nextAction: optionalString(record, 'nextAction'),
425
+ stage: optionalString(record, 'stage'),
426
+ generated: typeof generatedRaw === 'boolean' ? generatedRaw : null,
427
+ };
428
+ }
429
+ function evidenceLine(label, value) {
430
+ if (value === null || value.trim() === '')
431
+ return [];
432
+ return [`${label}: ${value.length > 500 ? `${value.slice(0, 500)}…` : value}`];
433
+ }
382
434
  function projectionFromFailure(failed) {
383
435
  const { attemptCount } = failed;
384
436
  const { maxAttempts } = failed;
@@ -421,17 +473,48 @@ function projectFailureDiagnostics(diagnosticJson) {
421
473
  : outputFailure
422
474
  ? toStringArray(outputFailure.validatorErrors)
423
475
  : [];
476
+ const piMetadata = Object.hasOwn(envelope, 'pi_metadata') ? asRecord(envelope.pi_metadata) : null;
477
+ const humanReview = piMetadata ? projectHumanReview(piMetadata.humanReviewContext) : null;
478
+ const identityPreflight = Object.hasOwn(envelope, 'identityPreflight')
479
+ ? projectIdentityPreflight(envelope.identityPreflight)
480
+ : null;
481
+ const evidenceSummary = [
482
+ ...evidenceLine('humanReview.reasonCode', humanReview?.reasonCode ?? null),
483
+ ...evidenceLine('humanReview.detail', humanReview?.detail ?? null),
484
+ ...evidenceLine('humanReview.missingFields', humanReview && humanReview.missingFields.length > 0 ? humanReview.missingFields.join(', ') : null),
485
+ ...evidenceLine('identityPreflight', identityPreflight
486
+ ? JSON.stringify({
487
+ status: identityPreflight.status,
488
+ reasonCode: identityPreflight.reasonCode,
489
+ detail: identityPreflight.detail,
490
+ stage: identityPreflight.stage,
491
+ generated: identityPreflight.generated,
492
+ })
493
+ : null),
494
+ ...evidenceLine('terminal_failure', terminal ? JSON.stringify(terminal) : null),
495
+ ...evidenceLine('validator_error', effectiveValidatorErrors[effectiveValidatorErrors.length - 1] ?? null),
496
+ ...evidenceLine('failed_stage', failedStage ? JSON.stringify({
497
+ stageTaskId: failedStage.stageTaskId,
498
+ stageTaskKind: failedStage.stageTaskKind,
499
+ errorCategory: failedStage.errorCategory,
500
+ }) : null),
501
+ ].slice(0, 8);
424
502
  const projection = {
425
503
  terminalReason: terminal ? optionalString(terminal, 'reason') : null,
426
504
  terminalErrorCategory: terminal ? optionalString(terminal, 'errorCategory') : null,
427
505
  validatorErrors: effectiveValidatorErrors,
428
506
  failedStage: failedStage ? projectionFromFailure(failedStage) : null,
507
+ humanReview,
508
+ identityPreflight,
509
+ evidenceSummary,
429
510
  };
430
511
  // Nothing to say: behave as if the server never sent the block.
431
512
  if (projection.terminalReason === null
432
513
  && projection.terminalErrorCategory === null
433
514
  && projection.validatorErrors.length === 0
434
- && projection.failedStage === null) {
515
+ && projection.failedStage === null
516
+ && projection.humanReview === null
517
+ && projection.identityPreflight === null) {
435
518
  return null;
436
519
  }
437
520
  return projection;
@@ -9,13 +9,16 @@ export interface GovernanceExperienceContext {
9
9
  }
10
10
  /**
11
11
  * Owner identity evidence for the governance experience snapshot. Mirrors the
12
- * activations authority wiring in server/index.ts (authConfig.isEnabled() +
13
- * PD_OWNER_ID + PD_OWNER_CREDENTIAL_ID) — the two must stay in sync; the route
14
- * tests lock the mapping.
12
+ * activations authority wiring in server/index.ts (PD_OWNER_ID +
13
+ * PD_OWNER_CREDENTIAL_ID) — the two must stay in sync; the route tests lock
14
+ * the mapping.
15
+ *
16
+ * The wire enum keeps both historical values (D2), but the Console has no
17
+ * application-level credential any more, so `authenticationMode` is always
18
+ * `no_auth`. Readiness now depends only on whether an Owner identity is
19
+ * registered.
15
20
  */
16
- export declare function resolveOwnerConfigSnapshot(authConfig: {
17
- isEnabled(): boolean;
18
- }, identity: OwnerIdentityResolved): OwnerConfigSnapshot;
21
+ export declare function resolveOwnerConfigSnapshot(identity: OwnerIdentityResolved): OwnerConfigSnapshot;
19
22
  /**
20
23
  * GET /api/governance/experience — read-only Governance Experience Snapshot
21
24
  * v1.5.1 (PRI-585).
@@ -21,19 +21,23 @@ function getExperienceCollector(workspaceDir) {
21
21
  }
22
22
  /**
23
23
  * Owner identity evidence for the governance experience snapshot. Mirrors the
24
- * activations authority wiring in server/index.ts (authConfig.isEnabled() +
25
- * PD_OWNER_ID + PD_OWNER_CREDENTIAL_ID) — the two must stay in sync; the route
26
- * tests lock the mapping.
24
+ * activations authority wiring in server/index.ts (PD_OWNER_ID +
25
+ * PD_OWNER_CREDENTIAL_ID) — the two must stay in sync; the route tests lock
26
+ * the mapping.
27
+ *
28
+ * The wire enum keeps both historical values (D2), but the Console has no
29
+ * application-level credential any more, so `authenticationMode` is always
30
+ * `no_auth`. Readiness now depends only on whether an Owner identity is
31
+ * registered.
27
32
  */
28
- export function resolveOwnerConfigSnapshot(authConfig, identity) {
29
- const authEnabled = authConfig.isEnabled();
33
+ export function resolveOwnerConfigSnapshot(identity) {
30
34
  const ownerIdentityConfiguration = identity.source === 'invalid_env' || identity.error !== undefined
31
35
  ? 'invalid'
32
36
  : (identity.source === 'env' || identity.source === 'file') && identity.ownerId && identity.credentialId
33
37
  ? 'configured'
34
38
  : 'missing';
35
39
  return {
36
- authenticationMode: authEnabled ? 'authenticated' : 'no_auth',
40
+ authenticationMode: 'no_auth',
37
41
  ownerIdentityConfiguration,
38
42
  };
39
43
  }
@@ -5,9 +5,9 @@
5
5
  * POST /api/governance/owner-decisions/:taskId/resolve — Owner 裁决
6
6
  *
7
7
  * 安全模型(SPEC §28/§29):
8
- * - 全局 console token 认证由 server/index.ts 统一强制;
9
- * - 身份从 server-side auth context 推导(configured_owner 优先,其次
10
- * console operator),body 里的身份字段一律不信任;
8
+ * - 来源守卫(Host/Origin/Sec-Fetch-Site/JSON Content-Type)由
9
+ * server/index.ts 统一强制;
10
+ * - 身份从服务端身份解析结果推导,body 里的身份字段一律不信任;
11
11
  * - effectiveDecision / eligibility 全部服务端重读 durable facts 判定;
12
12
  * - stale 防护: reviewKey + expected* 事实快照逐字段比对(409)。
13
13
  */
@@ -183,7 +183,7 @@ export async function handleOwnerDecisionsRoute(req, res, ctx) {
183
183
  }
184
184
  if (!ownerIdentity) {
185
185
  sendError(res, 403, 'owner_authentication_required', 'Owner decisions require an authenticated Console and a configured Owner identity.', {
186
- nextAction: 'Configure the Console token and Owner identity, then retry from Governance Focus.',
186
+ nextAction: 'Configure the Owner identity, then retry from Governance Focus.',
187
187
  });
188
188
  return;
189
189
  }
@@ -9,8 +9,9 @@
9
9
  *
10
10
  * Registration (where the identity comes from) and governance readiness
11
11
  * (whether Owner governance actions can execute) are DIFFERENT facts: the
12
- * latter additionally requires Console token authentication and is derived
13
- * ONLY by resolveOwnerConfigSnapshot — never re-derived in the UI.
12
+ * latter requires a registered identity (the local OS session is the
13
+ * credential) and is derived ONLY by resolveOwnerConfigSnapshot — never
14
+ * re-derived in the UI.
14
15
  *
15
16
  * Env vars remain the highest-priority source; file registration is the
16
17
  * install-level fallback; a partial env pair is invalid and fails closed
@@ -32,6 +33,4 @@ export interface OwnerIdentityRouteView {
32
33
  /** Canonical governance readiness — the same derivation the governance experience uses. */
33
34
  governance: OwnerConfigSnapshot;
34
35
  }
35
- export declare function handleOwnerIdentityRoute(req: IncomingMessage, res: ServerResponse, homeDir: string, subPath: string, authConfig: {
36
- isEnabled(): boolean;
37
- }): Promise<void>;
36
+ export declare function handleOwnerIdentityRoute(req: IncomingMessage, res: ServerResponse, homeDir: string, subPath: string): Promise<void>;
@@ -15,7 +15,7 @@ async function readJson(req) {
15
15
  return JSON.parse(Buffer.concat(chunks).toString('utf-8'));
16
16
  }
17
17
  /* eslint-disable @typescript-eslint/max-params */
18
- export async function handleOwnerIdentityRoute(req, res, homeDir, subPath, authConfig) {
18
+ export async function handleOwnerIdentityRoute(req, res, homeDir, subPath) {
19
19
  if (subPath !== '' && subPath !== '/') {
20
20
  sendError(res, 404, 'not_found', 'Unknown owner identity endpoint.', { nextAction: 'Use GET / POST / DELETE /api/owner-identity.' });
21
21
  return;
@@ -32,7 +32,7 @@ export async function handleOwnerIdentityRoute(req, res, homeDir, subPath, authC
32
32
  fileRecord: file?.record ?? null,
33
33
  ...(file?.error === undefined ? {} : { fileError: file.error }),
34
34
  ...(envIdentityActive ? { fileRecordSkipped: 'env_identity' } : {}),
35
- governance: resolveOwnerConfigSnapshot(authConfig, resolved),
35
+ governance: resolveOwnerConfigSnapshot(resolved),
36
36
  };
37
37
  sendSuccess(res, view);
38
38
  return;
@@ -58,7 +58,7 @@ export async function handleOwnerIdentityRoute(req, res, homeDir, subPath, authC
58
58
  sendSuccess(res, {
59
59
  record: result.record,
60
60
  source: 'file',
61
- governance: resolveOwnerConfigSnapshot(authConfig, resolved),
61
+ governance: resolveOwnerConfigSnapshot(resolved),
62
62
  });
63
63
  return;
64
64
  }
@@ -72,7 +72,7 @@ export async function handleOwnerIdentityRoute(req, res, homeDir, subPath, authC
72
72
  sendSuccess(res, {
73
73
  ok: true,
74
74
  source: 'none',
75
- governance: resolveOwnerConfigSnapshot(authConfig, resolved),
75
+ governance: resolveOwnerConfigSnapshot(resolved),
76
76
  });
77
77
  return;
78
78
  }
@@ -39,7 +39,7 @@ function failure(res, result) {
39
39
  export async function handleRuleCandidateBindingsRoute(req, res, ctx) {
40
40
  // Auth precedes model construction and body parsing: a refused caller cannot create state.
41
41
  if (!ctx.ownerIdentity) {
42
- sendError(res, 403, 'owner_authentication_required', '请先完成控制台认证并配置 Owner 身份。', { nextAction: '在设置中确认 Owner 身份后重试。' });
42
+ sendError(res, 403, 'owner_authentication_required', '请先配置 Owner 身份。', { nextAction: '在设置中确认 Owner 身份后重试。' });
43
43
  return;
44
44
  }
45
45
  const model = new RuleCandidateBindingConsoleModel(ctx.workspaceDir);
@@ -138,26 +138,44 @@ async function applyFullUpdate(authority, res, workspaceDir) {
138
138
  parsed.message = val;
139
139
  else if (key === 'nextAction' && typeof val === 'string')
140
140
  parsed.nextAction = val;
141
+ else if (key === 'result' && typeof val === 'object' && val !== null && !Array.isArray(val)) {
142
+ const nested = val;
143
+ parsed.result = {
144
+ ...(typeof nested.kind === 'string' ? { kind: nested.kind } : {}),
145
+ ...(typeof nested.reason === 'string' ? { reason: nested.reason } : {}),
146
+ ...(typeof nested.note === 'string' ? { note: nested.note } : {}),
147
+ ...(typeof nested.nextAction === 'string' ? { nextAction: nested.nextAction } : {}),
148
+ };
149
+ }
141
150
  }
142
151
  }
143
152
  }
144
153
  catch {
145
154
  // keep the empty shape; the message below stays generic
146
155
  }
147
- if (parsed.ok === false) {
156
+ const isNoUpdate = parsed.result?.kind === 'no_update';
157
+ if (parsed.ok === false || isNoUpdate) {
158
+ const refusalReason = isNoUpdate
159
+ ? parsed.result?.reason ?? 'update_refused'
160
+ : parsed.reason ?? 'bootstrap_executor_refused';
161
+ const refusalMessage = isNoUpdate
162
+ ? parsed.result?.note ?? 'The update was refused without a runtime change.'
163
+ : parsed.message ?? 'The bootstrap executor refused the update.';
164
+ const refusalNextAction = (isNoUpdate ? parsed.result?.nextAction : parsed.nextAction)
165
+ ?? 'No runtime change was made. Resolve the reported cause, then retry.';
148
166
  appendGovernedUpdateHistory(workspaceDir, {
149
167
  fromVersion, toVersion: fromVersion, success: false, kind: 'refusal',
150
- reason: parsed.reason ?? 'bootstrap_executor_refused', authority: 'release-manager',
151
- nextAction: parsed.nextAction ?? 'No runtime change was made. Resolve the reported cause, then retry.',
168
+ reason: refusalReason, authority: 'release-manager',
169
+ nextAction: refusalNextAction,
152
170
  });
153
171
  sendSuccess(res, {
154
172
  success: false,
155
173
  refusal: true,
156
174
  state: 'update_blocked',
157
- reason: parsed.reason ?? 'bootstrap_executor_refused',
158
- message: parsed.message ?? 'The bootstrap executor refused the update.',
175
+ reason: refusalReason,
176
+ message: refusalMessage,
159
177
  requiresRestart: false,
160
- nextAction: parsed.nextAction ?? 'No runtime change was made. Resolve the reported cause, then retry.',
178
+ nextAction: refusalNextAction,
161
179
  });
162
180
  return;
163
181
  }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Request-origin guard for the credential-less console.
3
+ *
4
+ * The OS session is the trust boundary for *local* clients, but a browser page
5
+ * served from another origin can still reach `127.0.0.1:<port>`:
6
+ *
7
+ * - cross-site `fetch`/form POSTs are "simple requests" and reach the server
8
+ * even though the response is unreadable (CSRF);
9
+ * - DNS rebinding makes an attacker origin look same-origin, which also lets
10
+ * it read responses.
11
+ *
12
+ * The guard therefore enforces two independent facts and lets non-browser
13
+ * clients through unchanged:
14
+ *
15
+ * - `Host` must be a loopback literal (defeats rebinding);
16
+ * - when the browser tells us the provenance (`Origin` / `Sec-Fetch-Site`), it
17
+ * must be this console's own origin (defeats cross-site CSRF);
18
+ * - no `Origin` and no `Sec-Fetch-Site` means a non-browser client and is
19
+ * allowed — that is how the CLI, installer probes and scripts keep working.
20
+ *
21
+ * State-changing requests with a body must also be JSON: that keeps the
22
+ * "simple request" form/text submission path closed even if a future browser
23
+ * omits the provenance headers.
24
+ */
25
+ import type { IncomingMessage } from 'node:http';
26
+ export interface RequestGuardRejection {
27
+ status: number;
28
+ error: string;
29
+ message: string;
30
+ nextAction: string;
31
+ }
32
+ /**
33
+ * Returns `null` when the request may proceed, or a structured rejection.
34
+ */
35
+ export declare function guardConsoleApiRequest(req: IncomingMessage): RequestGuardRejection | null;
@@ -0,0 +1,81 @@
1
+ const LOOPBACK_HOSTNAMES = new Set(['127.0.0.1', 'localhost', '::1']);
2
+ const MUTATING_METHODS = new Set(['POST', 'PUT', 'PATCH']);
3
+ function stripBrackets(hostname) {
4
+ return hostname.replace(/^\[(.+)\]$/, '$1');
5
+ }
6
+ function loopbackHostOf(url) {
7
+ const hostname = stripBrackets(url.hostname.toLowerCase());
8
+ return LOOPBACK_HOSTNAMES.has(hostname) ? hostname : null;
9
+ }
10
+ function forbidden(reason) {
11
+ return {
12
+ status: 403,
13
+ error: reason,
14
+ message: 'Cross-origin requests are not accepted by the local Console.',
15
+ nextAction: 'Open the Console from its own address; browser extensions and remote pages cannot drive it.',
16
+ };
17
+ }
18
+ /**
19
+ * Returns `null` when the request may proceed, or a structured rejection.
20
+ */
21
+ export function guardConsoleApiRequest(req) {
22
+ const hostHeader = typeof req.headers.host === 'string' ? req.headers.host : '';
23
+ if (hostHeader.length > 0) {
24
+ try {
25
+ if (loopbackHostOf(new URL(`http://${hostHeader}`)) === null) {
26
+ return {
27
+ status: 403,
28
+ error: 'forbidden_host',
29
+ message: 'Requests must target the local Console address.',
30
+ nextAction: 'Use the loopback address the Console printed at startup (127.0.0.1 or localhost).',
31
+ };
32
+ }
33
+ }
34
+ catch {
35
+ return {
36
+ status: 403,
37
+ error: 'forbidden_host',
38
+ message: 'Requests must target the local Console address.',
39
+ nextAction: 'Use the loopback address the Console printed at startup (127.0.0.1 or localhost).',
40
+ };
41
+ }
42
+ }
43
+ const { origin } = req.headers;
44
+ if (typeof origin === 'string' && origin.length > 0) {
45
+ let parsed;
46
+ try {
47
+ parsed = new URL(origin);
48
+ }
49
+ catch {
50
+ return forbidden('forbidden_origin');
51
+ }
52
+ if (loopbackHostOf(parsed) === null) {
53
+ return forbidden('forbidden_origin');
54
+ }
55
+ // Same-origin means the browser's page and this request share host:port.
56
+ // `Origin: null` (file:, sandboxed frames) never reaches here as a match.
57
+ if (hostHeader.length > 0 && parsed.host.toLowerCase() !== hostHeader.toLowerCase()) {
58
+ return forbidden('forbidden_origin');
59
+ }
60
+ }
61
+ const secFetchSite = req.headers['sec-fetch-site'];
62
+ if (typeof secFetchSite === 'string' && secFetchSite.length > 0) {
63
+ if (secFetchSite !== 'same-origin' && secFetchSite !== 'none') {
64
+ return forbidden('forbidden_origin');
65
+ }
66
+ }
67
+ const method = (req.method ?? 'GET').toUpperCase();
68
+ if (MUTATING_METHODS.has(method)) {
69
+ const contentLength = Number(req.headers['content-length'] ?? '0');
70
+ const contentType = String(req.headers['content-type'] ?? '').toLowerCase();
71
+ if (contentLength > 0 && !contentType.startsWith('application/json')) {
72
+ return {
73
+ status: 415,
74
+ error: 'unsupported_media_type',
75
+ message: 'Console write endpoints require an application/json request body.',
76
+ nextAction: 'Send the request body as JSON with Content-Type: application/json.',
77
+ };
78
+ }
79
+ }
80
+ return null;
81
+ }
@@ -13,6 +13,5 @@ export declare function sendJson(res: ServerResponse, statusCode: number, payloa
13
13
  export declare function sendSuccess<T>(res: ServerResponse, data: T): void;
14
14
  export declare function sendError(res: ServerResponse, statusCode: number, error: string, message?: string, extras?: Record<string, unknown>): void;
15
15
  export declare function sendNotFound(res: ServerResponse, message?: string): void;
16
- export declare function sendUnauthorized(res: ServerResponse, message?: string): void;
17
16
  export declare function sendMethodNotAllowed(res: ServerResponse): void;
18
17
  export declare function sendBadRequest(res: ServerResponse, message: string): void;
@@ -50,9 +50,6 @@ export function sendError(res, statusCode, error, message, extras) {
50
50
  export function sendNotFound(res, message = 'Not found') {
51
51
  sendError(res, 404, 'not_found', message);
52
52
  }
53
- export function sendUnauthorized(res, message = 'Unauthorized') {
54
- sendError(res, 401, 'unauthorized', message);
55
- }
56
53
  export function sendMethodNotAllowed(res) {
57
54
  sendError(res, 405, 'method_not_allowed', 'Method not allowed');
58
55
  }