create-principles-disciple 1.152.4 → 1.153.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 (149) hide show
  1. package/_release/product-identity.json +2 -2
  2. package/agent-skill/pd-setup/SKILL.md +70 -0
  3. package/codex-adapter/dist/background-selection.d.ts +9 -0
  4. package/codex-adapter/dist/background-selection.js +142 -0
  5. package/codex-adapter/dist/ingestion/adaptive-append-state.d.ts +209 -0
  6. package/codex-adapter/dist/ingestion/adaptive-append-state.js +544 -0
  7. package/codex-adapter/dist/pd-hook.js +329 -5
  8. package/codex-adapter/package.json +1 -1
  9. package/console/dist/server/config/pd-config-store.d.ts +11 -15
  10. package/console/dist/server/config/pd-config-store.js +92 -17
  11. package/console/dist/server/models/AdaptiveActivationConsoleModel.d.ts +43 -4
  12. package/console/dist/server/models/AdaptiveActivationConsoleModel.js +36 -7
  13. package/console/dist/server/routes/config.js +34 -8
  14. package/console/dist/web/assets/app.css +6 -0
  15. package/console/dist/web/assets/app.js +22 -22
  16. package/core/dist/runtime/activation/sqlite-approval-store.d.ts.map +1 -1
  17. package/core/dist/runtime/activation/sqlite-approval-store.js +7 -1
  18. package/core/dist/runtime/activation/sqlite-approval-store.js.map +1 -1
  19. package/core/dist/runtime/config/pd-config-feature-flags.d.ts +10 -0
  20. package/core/dist/runtime/config/pd-config-feature-flags.d.ts.map +1 -1
  21. package/core/dist/runtime/config/pd-config-feature-flags.js +14 -0
  22. package/core/dist/runtime/config/pd-config-feature-flags.js.map +1 -1
  23. package/core/dist/runtime/config/pd-config-types.d.ts +9 -0
  24. package/core/dist/runtime/config/pd-config-types.d.ts.map +1 -1
  25. package/core/dist/runtime/config/pd-config-types.js.map +1 -1
  26. package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
  27. package/core/dist/runtime/config/pd-config-validate.js +10 -2
  28. package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
  29. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
  30. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +13 -2
  31. package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js.map +1 -1
  32. package/core/dist/runtime/intent/intent-doc.d.ts +22 -0
  33. package/core/dist/runtime/intent/intent-doc.d.ts.map +1 -1
  34. package/core/dist/runtime/intent/intent-doc.js +79 -0
  35. package/core/dist/runtime/intent/intent-doc.js.map +1 -1
  36. package/core/dist/runtime/intent/intent-friction-block.d.ts +7 -0
  37. package/core/dist/runtime/intent/intent-friction-block.d.ts.map +1 -1
  38. package/core/dist/runtime/intent/intent-friction-block.js +34 -1
  39. package/core/dist/runtime/intent/intent-friction-block.js.map +1 -1
  40. package/core/dist/runtime/intent/intent-snapshot.d.ts +44 -5
  41. package/core/dist/runtime/intent/intent-snapshot.d.ts.map +1 -1
  42. package/core/dist/runtime/intent/intent-snapshot.js +83 -15
  43. package/core/dist/runtime/intent/intent-snapshot.js.map +1 -1
  44. package/core/dist/runtime/intent/strategic-conflict-gate.d.ts +19 -0
  45. package/core/dist/runtime/intent/strategic-conflict-gate.d.ts.map +1 -1
  46. package/core/dist/runtime/intent/strategic-conflict-gate.js +94 -26
  47. package/core/dist/runtime/intent/strategic-conflict-gate.js.map +1 -1
  48. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts +22 -11
  49. package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts.map +1 -1
  50. package/core/dist/runtime/internalization/diag-rootcause-runner.js +101 -28
  51. package/core/dist/runtime/internalization/diag-rootcause-runner.js.map +1 -1
  52. package/core/dist/runtime/internalization/dreamer-prompt-builder.d.ts.map +1 -1
  53. package/core/dist/runtime/internalization/dreamer-prompt-builder.js +1 -0
  54. package/core/dist/runtime/internalization/dreamer-prompt-builder.js.map +1 -1
  55. package/core/dist/runtime/internalization/dreamer-runner.d.ts +9 -2
  56. package/core/dist/runtime/internalization/dreamer-runner.d.ts.map +1 -1
  57. package/core/dist/runtime/internalization/dreamer-runner.js +11 -1
  58. package/core/dist/runtime/internalization/dreamer-runner.js.map +1 -1
  59. package/core/dist/runtime/internalization/evaluator-runner.d.ts.map +1 -1
  60. package/core/dist/runtime/internalization/evaluator-runner.js +7 -0
  61. package/core/dist/runtime/internalization/evaluator-runner.js.map +1 -1
  62. package/core/dist/runtime/internalization/formation-context.d.ts +16 -0
  63. package/core/dist/runtime/internalization/formation-context.d.ts.map +1 -1
  64. package/core/dist/runtime/internalization/formation-context.js +109 -8
  65. package/core/dist/runtime/internalization/formation-context.js.map +1 -1
  66. package/core/dist/runtime/internalization/index.d.ts +2 -2
  67. package/core/dist/runtime/internalization/index.d.ts.map +1 -1
  68. package/core/dist/runtime/internalization/index.js +1 -1
  69. package/core/dist/runtime/internalization/index.js.map +1 -1
  70. package/core/dist/runtime/internalization/intent-contract.d.ts +55 -4
  71. package/core/dist/runtime/internalization/intent-contract.d.ts.map +1 -1
  72. package/core/dist/runtime/internalization/intent-contract.js +111 -30
  73. package/core/dist/runtime/internalization/intent-contract.js.map +1 -1
  74. package/core/dist/runtime/internalization/philosopher-runner.d.ts +9 -2
  75. package/core/dist/runtime/internalization/philosopher-runner.d.ts.map +1 -1
  76. package/core/dist/runtime/internalization/philosopher-runner.js +11 -1
  77. package/core/dist/runtime/internalization/philosopher-runner.js.map +1 -1
  78. package/core/dist/runtime/internalization/scribe-runner.d.ts.map +1 -1
  79. package/core/dist/runtime/internalization/scribe-runner.js +17 -7
  80. package/core/dist/runtime/internalization/scribe-runner.js.map +1 -1
  81. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.d.ts +10 -0
  82. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.d.ts.map +1 -1
  83. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.js +15 -4
  84. package/core/dist/runtime/store/intent/sqlite-intent-decision-store.js.map +1 -1
  85. package/core/dist/telemetry-event.d.ts +2 -2
  86. package/core/dist/telemetry-event.d.ts.map +1 -1
  87. package/core/dist/telemetry-event.js +6 -0
  88. package/core/dist/telemetry-event.js.map +1 -1
  89. package/core/package.json +1 -1
  90. package/dist/agent-skill.d.ts +59 -0
  91. package/dist/agent-skill.d.ts.map +1 -0
  92. package/dist/agent-skill.js +198 -0
  93. package/dist/agent-skill.js.map +1 -0
  94. package/dist/i18n.d.ts.map +1 -1
  95. package/dist/i18n.js +12 -0
  96. package/dist/i18n.js.map +1 -1
  97. package/dist/index.d.ts +3 -1
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/index.js +171 -3
  100. package/dist/index.js.map +1 -1
  101. package/dist/install-summary.d.ts +52 -0
  102. package/dist/install-summary.d.ts.map +1 -1
  103. package/dist/install-summary.js +104 -0
  104. package/dist/install-summary.js.map +1 -1
  105. package/dist/update/release-metadata-publisher.d.ts +3 -1
  106. package/dist/update/release-metadata-publisher.d.ts.map +1 -1
  107. package/dist/update/release-metadata-publisher.js +33 -2
  108. package/dist/update/release-metadata-publisher.js.map +1 -1
  109. package/dist/update/trust-metadata.d.ts +21 -0
  110. package/dist/update/trust-metadata.d.ts.map +1 -1
  111. package/dist/update/trust-metadata.js +192 -4
  112. package/dist/update/trust-metadata.js.map +1 -1
  113. package/host-runtime/dist/adaptive-background-append.d.ts +70 -0
  114. package/host-runtime/dist/adaptive-background-append.js +165 -0
  115. package/host-runtime/dist/index.d.ts +1 -0
  116. package/host-runtime/dist/index.js +5 -0
  117. package/host-runtime/package.json +1 -1
  118. package/package.json +3 -2
  119. package/pd-cli/dist/commands/health-console.d.ts +21 -0
  120. package/pd-cli/dist/commands/health-console.d.ts.map +1 -0
  121. package/pd-cli/dist/commands/health-console.js +106 -0
  122. package/pd-cli/dist/commands/health-console.js.map +1 -0
  123. package/pd-cli/dist/commands/health.d.ts +159 -0
  124. package/pd-cli/dist/commands/health.d.ts.map +1 -1
  125. package/pd-cli/dist/commands/health.js +162 -2
  126. package/pd-cli/dist/commands/health.js.map +1 -1
  127. package/pd-cli/dist/commands/mcp-probe.d.ts +48 -0
  128. package/pd-cli/dist/commands/mcp-probe.d.ts.map +1 -0
  129. package/pd-cli/dist/commands/mcp-probe.js +479 -0
  130. package/pd-cli/dist/commands/mcp-probe.js.map +1 -0
  131. package/pd-cli/dist/commands/runtime-internalization-run-once.js +2 -2
  132. package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
  133. package/pd-cli/dist/program.d.ts.map +1 -1
  134. package/pd-cli/dist/program.js +57 -0
  135. package/pd-cli/dist/program.js.map +1 -1
  136. package/pd-cli/dist/services/console-launcher.d.ts +3 -0
  137. package/pd-cli/dist/services/console-launcher.d.ts.map +1 -1
  138. package/pd-cli/dist/services/console-launcher.js +3 -2
  139. package/pd-cli/dist/services/console-launcher.js.map +1 -1
  140. package/pd-cli/package.json +1 -1
  141. package/plugin/dist/bundle.js +533 -449
  142. package/plugin/dist/openclaw.plugin.json +1 -1
  143. package/plugin/openclaw.plugin.json +1 -1
  144. package/plugin/package.json +1 -1
  145. package/release-manager/dist/i18n.js +12 -0
  146. package/release-manager/dist/update/trust-metadata.js +192 -4
  147. package/release-manager/package.json +2 -1
  148. package/workbuddy-adapter/dist/pd-hook.js +37 -3
  149. package/workbuddy-adapter/package.json +1 -1
@@ -799,7 +799,13 @@ const ADAPTIVE_ACTIVATION_FLAG_NAMES = new Set([
799
799
  'host.openclaw.adaptive_activation',
800
800
  'host.workbuddy.adaptive_activation',
801
801
  ]);
802
- const CODEX_ADAPTIVE_ACTIVATION_FLAG = 'host.codex.adaptive_activation';
802
+ export const ADAPTIVE_ACTIVATION_HOST_FLAGS = {
803
+ codex: 'host.codex.adaptive_activation',
804
+ workbuddy: 'host.workbuddy.adaptive_activation',
805
+ };
806
+ export function isAdaptiveActivationHost(value) {
807
+ return value === 'codex' || value === 'workbuddy';
808
+ }
803
809
  /**
804
810
  * The ONE team-confirmed Decisions combination the Console offers on first
805
811
  * setup. The endpoint/model/provider/credential-variable are frozen: the entry
@@ -815,7 +821,7 @@ export const ADAPTIVE_ACTIVATION_SERVICE_PRESET = {
815
821
  /** Frozen EXACT response-model allowlist from the accepted real runs. */
816
822
  responseModels: ['respan/span-01-lite:free', 'respan/span-01-lite-20260925'],
817
823
  };
818
- const ADAPTIVE_ACTIVATION_UPDATE_KEYS = new Set(['enabled', 'service']);
824
+ const ADAPTIVE_ACTIVATION_UPDATE_KEYS = new Set(['enabled', 'service', 'host', 'timing']);
819
825
  function isConfiguredSection(section) {
820
826
  return section !== undefined
821
827
  && typeof section.endpoint === 'string' && section.endpoint.length > 0
@@ -893,35 +899,66 @@ function readRawConfigForUpdate(workspaceDir) {
893
899
  /**
894
900
  * Write the workspace's Adaptive Activation settings.
895
901
  *
896
- * Supported payload (both fields optional, at least one required):
897
- * { enabled?: boolean; service?: 'decisions-openrouter-respan' }
902
+ * Supported payload (at least one of enabled/service required):
903
+ * { enabled?: boolean; service?: 'decisions-openrouter-respan';
904
+ * host?: 'codex' | 'workbuddy' }
898
905
  *
899
906
  * Guarantees:
900
907
  * - ZERO network: saving a configuration never sends a scoring request;
901
908
  * - append-only v1: a non-empty `replaceableActivationIds` refuses BOTH a
902
909
  * service write and `enabled: true`, while `enabled: false` always works;
903
910
  * - the service section is workspace-scoped and shared with the other hosts,
904
- * so it is not rewritten from this Codex entry while another host has
911
+ * so it is not rewritten while ANOTHER host (relative to `host`) has
905
912
  * Adaptive enabled;
913
+ * - `host` selects ONE existing switch; enabling never touches a second one.
914
+ * Omitting it keeps the original Codex behaviour (PRI-1196 compatible).
906
915
  * - enable requires a complete section — it is never "enabled but unusable".
907
916
  */
917
+ function workbuddyIntegrationDisabled() {
918
+ return {
919
+ ok: false,
920
+ statusCode: 409,
921
+ error: 'adaptive_workbuddy_host_disabled',
922
+ message: 'WorkBuddy integration is disabled for this workspace.',
923
+ nextAction: 'Enable the WorkBuddy host integration before enabling Adaptive Activation.',
924
+ };
925
+ }
908
926
  export function updateAdaptiveActivationSettings(workspaceDir, payload) {
909
927
  if (!isRecord(payload)) {
910
- return { ok: false, statusCode: 400, error: 'bad_request', message: 'Body must be a JSON object with enabled and/or service fields' };
928
+ return { ok: false, statusCode: 400, error: 'bad_request', message: 'Body must be a JSON object with enabled, service and/or timing fields' };
911
929
  }
912
930
  for (const key of Object.keys(payload)) {
913
931
  if (!ADAPTIVE_ACTIVATION_UPDATE_KEYS.has(key)) {
914
- return { ok: false, statusCode: 400, error: 'unknown_field', message: `Unknown field '${key}'. Supported fields: enabled, service` };
932
+ return { ok: false, statusCode: 400, error: 'unknown_field', message: `Unknown field '${key}'. Supported fields: enabled, service, host, timing` };
915
933
  }
916
934
  }
935
+ const requestedHost = payload.host;
936
+ if (requestedHost !== undefined && !isAdaptiveActivationHost(requestedHost)) {
937
+ return { ok: false, statusCode: 400, error: 'unknown_host', message: `Unknown Adaptive host '${String(requestedHost)}'. Supported hosts: codex, workbuddy` };
938
+ }
939
+ const host = isAdaptiveActivationHost(requestedHost) ? requestedHost : 'codex';
940
+ const hostFlag = ADAPTIVE_ACTIVATION_HOST_FLAGS[host];
917
941
  const hasEnabled = Object.hasOwn(payload, 'enabled');
918
942
  const hasService = Object.hasOwn(payload, 'service');
919
- if (!hasEnabled && !hasService) {
920
- return { ok: false, statusCode: 400, error: 'bad_request', message: 'Nothing to update: send enabled and/or service' };
943
+ const hasTiming = Object.hasOwn(payload, 'timing');
944
+ if (hasTiming && host !== 'codex') {
945
+ return { ok: false, statusCode: 400, error: 'adaptive_timing_unsupported_host', message: 'Selection timing is configurable only for Codex.' };
946
+ }
947
+ if (!hasEnabled && !hasService && !hasTiming) {
948
+ return { ok: false, statusCode: 400, error: 'bad_request', message: 'Nothing to update: send enabled, service and/or timing' };
921
949
  }
922
950
  if (hasEnabled && typeof payload.enabled !== 'boolean') {
923
951
  return { ok: false, statusCode: 400, error: 'bad_request', message: `enabled must be a boolean. Got: ${typeof payload.enabled}` };
924
952
  }
953
+ if (hasTiming && payload.timing !== 'sync' && payload.timing !== 'background') {
954
+ return {
955
+ ok: false,
956
+ statusCode: 400,
957
+ error: 'bad_request',
958
+ message: `timing must be 'sync' or 'background'. Got: ${String(payload.timing)}`,
959
+ nextAction: "Send { timing: 'sync' } (decide before the first request) or { timing: 'background' } (send Native first, append later in the turn)",
960
+ };
961
+ }
925
962
  if (hasService && payload.service !== ADAPTIVE_ACTIVATION_SERVICE_PRESET.id) {
926
963
  return {
927
964
  ok: false,
@@ -937,6 +974,9 @@ export function updateAdaptiveActivationSettings(workspaceDir, payload) {
937
974
  return { ok: false, ...rawRead.failure };
938
975
  }
939
976
  const { configPath, rawConfig, featuresSection, config } = rawRead;
977
+ if (host === 'workbuddy' && enableRequested && config.features['host.workbuddy']?.enabled !== true) {
978
+ return workbuddyIntegrationDisabled();
979
+ }
940
980
  const currentSection = config.adaptiveActivation;
941
981
  const replaceableIds = currentSection?.replaceableActivationIds ?? [];
942
982
  if (replaceableIds.length > 0 && (hasService || enableRequested)) {
@@ -950,14 +990,16 @@ export function updateAdaptiveActivationSettings(workspaceDir, payload) {
950
990
  nextAction: 'Keep the existing configuration unchanged (disable is still allowed), or remove adaptiveActivation.replaceableActivationIds in .pd/config.yaml to switch to append-only.',
951
991
  };
952
992
  }
953
- const otherHostAaEnabled = ['host.openclaw.adaptive_activation', 'host.workbuddy.adaptive_activation']
954
- .filter((name) => config.features[name]?.enabled === true);
993
+ // "Other host" is relative to the SELECTED entry: a WorkBuddy save must not
994
+ // be blocked by its own flag, but must still be blocked by Codex/OpenClaw.
995
+ const otherHostAaEnabled = ['host.codex.adaptive_activation', 'host.openclaw.adaptive_activation', 'host.workbuddy.adaptive_activation']
996
+ .filter((name) => name !== hostFlag && config.features[name]?.enabled === true);
955
997
  if (hasService && otherHostAaEnabled.length > 0) {
956
998
  return {
957
999
  ok: false,
958
1000
  statusCode: 409,
959
1001
  error: 'shared_service_config_locked',
960
- message: `Another host in this workspace already has Adaptive enabled (${otherHostAaEnabled.join(', ')}). The Decisions service configuration is shared per workspace and cannot be rewritten from the Codex entry.`,
1002
+ message: `Another host in this workspace already has Adaptive enabled (${otherHostAaEnabled.join(', ')}). The Decisions service configuration is shared per workspace and cannot be rewritten from the ${host} entry.`,
961
1003
  nextAction: 'Disable the other host Adaptive flag in .pd/config.yaml first, then save the service configuration here.',
962
1004
  };
963
1005
  }
@@ -977,16 +1019,38 @@ export function updateAdaptiveActivationSettings(workspaceDir, payload) {
977
1019
  nextAction: `Save the '${ADAPTIVE_ACTIVATION_SERVICE_PRESET.id}' service preset first, or add adaptiveActivation: {endpoint, model, apiKeyEnv} to .pd/config.yaml.`,
978
1020
  };
979
1021
  }
1022
+ // PRI-1196: selection timing belongs to the SAME section as the service.
1023
+ // Writing it without a usable service would create an invalid section, and
1024
+ // 'background' with a replacement configuration would contradict the
1025
+ // append-only guarantee of the async mode.
1026
+ if (hasTiming && !isConfiguredSection(effectiveSection)) {
1027
+ return {
1028
+ ok: false,
1029
+ statusCode: 400,
1030
+ error: 'adaptive_activation_not_configured',
1031
+ message: 'Cannot save the selection timing: no complete adaptiveActivation section (endpoint, model, apiKeyEnv) is configured in this workspace.',
1032
+ nextAction: `Save the '${ADAPTIVE_ACTIVATION_SERVICE_PRESET.id}' service preset first, then choose the timing.`,
1033
+ };
1034
+ }
1035
+ if (hasTiming && payload.timing === 'background' && replaceableIds.length > 0) {
1036
+ return {
1037
+ ok: false,
1038
+ statusCode: 409,
1039
+ error: 'append_only_conflict',
1040
+ message: `Background timing is append-only and cannot be combined with adaptiveActivation.replaceableActivationIds (${replaceableIds.join(', ')}).`,
1041
+ nextAction: 'Remove adaptiveActivation.replaceableActivationIds in .pd/config.yaml to use background timing, or keep the synchronous timing.',
1042
+ };
1043
+ }
980
1044
  // Merge — preserve unrelated sections and every other feature entry.
981
1045
  const nextFeatures = { ...featuresSection };
982
1046
  if (hasEnabled) {
983
- const existingEntry = Object.hasOwn(nextFeatures, CODEX_ADAPTIVE_ACTIVATION_FLAG)
984
- ? nextFeatures[CODEX_ADAPTIVE_ACTIVATION_FLAG]
1047
+ const existingEntry = Object.hasOwn(nextFeatures, hostFlag)
1048
+ ? nextFeatures[hostFlag]
985
1049
  : undefined;
986
1050
  const category = (isRecord(existingEntry) && Object.hasOwn(existingEntry, 'category') && typeof existingEntry.category === 'string')
987
1051
  ? existingEntry.category
988
- : (DEFAULT_FLAG_CATEGORY.get(CODEX_ADAPTIVE_ACTIVATION_FLAG) ?? 'quiet');
989
- nextFeatures[CODEX_ADAPTIVE_ACTIVATION_FLAG] = { category, enabled: payload.enabled === true, source: 'owner' };
1052
+ : (DEFAULT_FLAG_CATEGORY.get(hostFlag) ?? 'quiet');
1053
+ nextFeatures[hostFlag] = { category, enabled: payload.enabled === true, source: 'owner' };
990
1054
  }
991
1055
  rawConfig.features = nextFeatures;
992
1056
  if (hasService) {
@@ -1002,6 +1066,13 @@ export function updateAdaptiveActivationSettings(workspaceDir, payload) {
1002
1066
  responseModels: [...ADAPTIVE_ACTIVATION_SERVICE_PRESET.responseModels],
1003
1067
  };
1004
1068
  }
1069
+ if (hasTiming) {
1070
+ // Merge into whatever section the service write (if any) just produced.
1071
+ const existingSectionRaw = Object.hasOwn(rawConfig, 'adaptiveActivation') && isRecord(rawConfig.adaptiveActivation)
1072
+ ? rawConfig.adaptiveActivation
1073
+ : {};
1074
+ rawConfig.adaptiveActivation = { ...existingSectionRaw, timing: payload.timing };
1075
+ }
1005
1076
  const validation = validatePdConfig(rawConfig);
1006
1077
  if (!validation.ok) {
1007
1078
  return {
@@ -1032,7 +1103,8 @@ export function updateAdaptiveActivationSettings(workspaceDir, payload) {
1032
1103
  const confirmed = confirmResult.effective.config;
1033
1104
  return {
1034
1105
  ok: true,
1035
- enabled: confirmed.features[CODEX_ADAPTIVE_ACTIVATION_FLAG]?.enabled === true,
1106
+ host,
1107
+ enabled: confirmed.features[hostFlag]?.enabled === true,
1036
1108
  serviceConfigured: isConfiguredSection(confirmed.adaptiveActivation),
1037
1109
  };
1038
1110
  }
@@ -1089,6 +1161,9 @@ export function updateFeatureFlag(workspaceDir, featureName, enabled) {
1089
1161
  // mode. The generic toggle must not be able to cross that boundary
1090
1162
  // (the dedicated Adaptive entry refuses the same combination).
1091
1163
  if (enabled === true && ADAPTIVE_ACTIVATION_FLAG_NAMES.has(featureName)) {
1164
+ if (featureName === ADAPTIVE_ACTIVATION_HOST_FLAGS.workbuddy && rawRead.config.features['host.workbuddy']?.enabled !== true) {
1165
+ return workbuddyIntegrationDisabled();
1166
+ }
1092
1167
  const replaceableIds = rawRead.config.adaptiveActivation?.replaceableActivationIds ?? [];
1093
1168
  if (replaceableIds.length > 0) {
1094
1169
  return {
@@ -1,5 +1,5 @@
1
1
  import { type AdaptiveInjectionRecord } from '@principles/host-runtime';
2
- import { type AdaptiveServicePresetId } from '../config/pd-config-store.js';
2
+ import { type AdaptiveActivationHost, type AdaptiveServicePresetId } from '../config/pd-config-store.js';
3
3
  export type AdaptiveCandidateEmptyState = 'ok' | 'zero' | 'prompt_disabled' | 'db_missing' | 'read_failed';
4
4
  /**
5
5
  * Evidence tri-state. `unknown` exists so a failed read can NEVER be reported
@@ -23,6 +23,21 @@ export interface AdaptiveEvidenceView {
23
23
  }
24
24
  export interface AdaptiveActivationView {
25
25
  workspaceDir: string;
26
+ /**
27
+ * PRI-1127: the ONE host this view is scoped to. Every switch, log read and
28
+ * last-turn result below belongs to this host's existing flag — never to a
29
+ * second truth and never to another workspace.
30
+ */
31
+ host: {
32
+ kind: AdaptiveActivationHost;
33
+ /** Existing workspace flag id, shown so the Owner knows what is toggled. */
34
+ flag: string;
35
+ enabled: boolean;
36
+ serviceConfigured: boolean;
37
+ saved: boolean;
38
+ integrationEnabled?: boolean;
39
+ };
40
+ /** Kept for the original Codex card contract — always Codex's REAL state. */
26
41
  codex: {
27
42
  /** The existing switch — `host.codex.adaptive_activation`. */
28
43
  enabled: boolean;
@@ -30,6 +45,11 @@ export interface AdaptiveActivationView {
30
45
  serviceConfigured: boolean;
31
46
  /** Enabled AND service configured — what "已保存" means. */
32
47
  saved: boolean;
48
+ /**
49
+ * PRI-1196: when the decision runs relative to the first request.
50
+ * Absent in config = `sync` (historical behavior).
51
+ */
52
+ timing: 'sync' | 'background';
33
53
  };
34
54
  service: {
35
55
  presetId: AdaptiveServicePresetId;
@@ -49,8 +69,8 @@ export interface AdaptiveActivationView {
49
69
  */
50
70
  replaceableActivationIds: string[];
51
71
  appendOnlyEligible: boolean;
52
- /** Other hosts sharing the same workspace-scoped service config. */
53
- otherHostAaEnabled: ('openclaw' | 'workbuddy')[];
72
+ /** Other hosts sharing the same workspace-scoped service config (excluding the selected host). */
73
+ otherHostAaEnabled: ('openclaw' | 'codex' | 'workbuddy')[];
54
74
  candidates: {
55
75
  /** Candidates the assembly could actually draw from. */
56
76
  validCount: number;
@@ -63,6 +83,23 @@ export interface AdaptiveActivationView {
63
83
  emptyState: AdaptiveCandidateEmptyState;
64
84
  };
65
85
  lastRecord: AdaptiveInjectionRecord | null;
86
+ /**
87
+ * PRI-1127: the result fields the page was missing. Derived ONLY from the
88
+ * SAME recorded injection event — no re-derivation, no model-output guess.
89
+ * `runId` is the host's real current-turn identity (WorkBuddy generation_id,
90
+ * Codex turn_id); `appendedActivationId` is the FINAL assembly basis;
91
+ * `independentRequestSent` is whether a scoring request actually left the
92
+ * process this turn. Delivery itself is NEVER claimed by the Console: it is
93
+ * confirmed by independent model-request evidence (engine-level capture).
94
+ */
95
+ lastRound: {
96
+ runId: string | null;
97
+ appendedActivationId: string | null;
98
+ activationIds: string[];
99
+ independentRequestSent: boolean;
100
+ /** Match keys this record was selected by — workspace + host + same turn. */
101
+ matchedBy: readonly ['workspace', 'host', 'turn'];
102
+ } | null;
66
103
  /**
67
104
  * Tri-state evidence for the last turn. `lastRecord === null` alone says
68
105
  * nothing — always branch on this status, never on the record's absence.
@@ -73,7 +110,9 @@ export interface AdaptiveActivationView {
73
110
  export declare function adaptiveActivationStateDir(workspaceDir: string): string;
74
111
  export declare class AdaptiveActivationConsoleModel {
75
112
  private readonly workspaceDir;
76
- constructor(workspaceDir: string);
113
+ /** Scopes EVERY read below: config switch, injection events and last turn. */
114
+ private readonly hostKind;
115
+ constructor(workspaceDir: string, hostKind?: AdaptiveActivationHost);
77
116
  private stateDir;
78
117
  getView(): Promise<AdaptiveActivationView>;
79
118
  }
@@ -17,7 +17,7 @@
17
17
  import path from 'node:path';
18
18
  import { readAdaptiveInjectionRecords, readPromptActivationCandidates, } from '@principles/host-runtime';
19
19
  import { pdProviderCredentials } from '@principles/core/runtime';
20
- import { loadPdConfig, ADAPTIVE_ACTIVATION_SERVICE_PRESET } from '../config/pd-config-store.js';
20
+ import { loadPdConfig, ADAPTIVE_ACTIVATION_SERVICE_PRESET, ADAPTIVE_ACTIVATION_HOST_FLAGS, } from '../config/pd-config-store.js';
21
21
  const UNKNOWN_EVIDENCE = {
22
22
  status: 'unknown',
23
23
  reason: 'logs_unreadable',
@@ -63,8 +63,11 @@ export function adaptiveActivationStateDir(workspaceDir) {
63
63
  }
64
64
  export class AdaptiveActivationConsoleModel {
65
65
  workspaceDir;
66
- constructor(workspaceDir) {
66
+ /** Scopes EVERY read below: config switch, injection events and last turn. */
67
+ hostKind;
68
+ constructor(workspaceDir, hostKind = 'codex') {
67
69
  this.workspaceDir = workspaceDir;
70
+ this.hostKind = hostKind;
68
71
  }
69
72
  stateDir() {
70
73
  return adaptiveActivationStateDir(this.workspaceDir);
@@ -74,6 +77,8 @@ export class AdaptiveActivationConsoleModel {
74
77
  const config = loaded.ok ? loaded.effective.config : loaded.defaults.config;
75
78
  const section = config.adaptiveActivation;
76
79
  const flags = config.features;
80
+ const hostFlag = ADAPTIVE_ACTIVATION_HOST_FLAGS[this.hostKind];
81
+ const hostEnabled = flags[hostFlag]?.enabled === true;
77
82
  const codexEnabled = flags['host.codex.adaptive_activation']?.enabled === true;
78
83
  const serviceConfigured = section !== undefined
79
84
  && typeof section.endpoint === 'string' && section.endpoint.length > 0
@@ -101,7 +106,8 @@ export class AdaptiveActivationConsoleModel {
101
106
  const report = readAdaptiveInjectionRecords({
102
107
  stateDir: this.stateDir(),
103
108
  workspaceDir: this.workspaceDir,
104
- hostKind: 'codex',
109
+ // PRI-1127: NEVER read another host's (or another workspace's) result.
110
+ hostKind: this.hostKind,
105
111
  limit: 1,
106
112
  });
107
113
  lastRecord = report.records[0] ?? null;
@@ -113,17 +119,33 @@ export class AdaptiveActivationConsoleModel {
113
119
  // internal filesystem location.
114
120
  evidence = { ...UNKNOWN_EVIDENCE };
115
121
  }
122
+ // Exclude the SELECTED host: its own flag is the switch on this card, not
123
+ // a competing owner of the shared service section.
116
124
  const otherHostAaEnabled = [];
117
- if (flags['host.openclaw.adaptive_activation']?.enabled === true)
118
- otherHostAaEnabled.push('openclaw');
119
- if (flags['host.workbuddy.adaptive_activation']?.enabled === true)
120
- otherHostAaEnabled.push('workbuddy');
125
+ const sharedHostChecks = [
126
+ ['openclaw', 'host.openclaw.adaptive_activation'],
127
+ ['codex', 'host.codex.adaptive_activation'],
128
+ ['workbuddy', 'host.workbuddy.adaptive_activation'],
129
+ ];
130
+ for (const [kind, flag] of sharedHostChecks) {
131
+ if (kind !== this.hostKind && flags[flag]?.enabled === true)
132
+ otherHostAaEnabled.push(kind);
133
+ }
121
134
  return {
122
135
  workspaceDir: this.workspaceDir,
136
+ host: {
137
+ kind: this.hostKind,
138
+ flag: hostFlag,
139
+ enabled: hostEnabled,
140
+ serviceConfigured,
141
+ saved: hostEnabled && serviceConfigured,
142
+ ...(this.hostKind === 'workbuddy' ? { integrationEnabled: flags['host.workbuddy']?.enabled === true } : {}),
143
+ },
123
144
  codex: {
124
145
  enabled: codexEnabled,
125
146
  serviceConfigured,
126
147
  saved: codexEnabled && serviceConfigured,
148
+ timing: section?.timing === 'background' ? 'background' : 'sync',
127
149
  },
128
150
  service: {
129
151
  presetId: ADAPTIVE_ACTIVATION_SERVICE_PRESET.id,
@@ -145,6 +167,13 @@ export class AdaptiveActivationConsoleModel {
145
167
  emptyState: classifyEmptyState(candidates),
146
168
  },
147
169
  lastRecord,
170
+ lastRound: lastRecord === null ? null : {
171
+ runId: lastRecord.runId,
172
+ appendedActivationId: lastRecord.appendedActivationId,
173
+ activationIds: [...lastRecord.activationIds],
174
+ independentRequestSent: lastRecord.scored,
175
+ matchedBy: ['workspace', 'host', 'turn'],
176
+ },
148
177
  evidence,
149
178
  };
150
179
  }
@@ -22,10 +22,35 @@
22
22
  */
23
23
  import { pdProviderCatalog, pdProviderCredentials, probeProviderConnection, } from '@principles/core/runtime';
24
24
  import { sendSuccess, sendError, sendNotFound, sendMethodNotAllowed, sendBadRequest, sendJson } from '../utils/response.js';
25
- import { getConfigSummary, getConfigCatalog, updateAgentBinding, updateDefaultRuntime, checkReadiness, getPrinciplesOutputLanguage, updatePrinciplesOutputLanguage, updateFeatureFlag, updateAdaptiveActivationSettings, createRuntimeProfile, updateRuntimeProfile, deleteRuntimeProfile, } from '../config/pd-config-store.js';
25
+ import { getConfigSummary, getConfigCatalog, updateAgentBinding, updateDefaultRuntime, checkReadiness, getPrinciplesOutputLanguage, updatePrinciplesOutputLanguage, updateFeatureFlag, updateAdaptiveActivationSettings, isAdaptiveActivationHost, createRuntimeProfile, updateRuntimeProfile, deleteRuntimeProfile, } from '../config/pd-config-store.js';
26
26
  import { AdaptiveActivationConsoleModel } from '../models/AdaptiveActivationConsoleModel.js';
27
27
  // ── Constants ────────────────────────────────────────────────────────────────
28
28
  const MAX_BODY_SIZE = 1024 * 64; // 64 KB — generous for config binding updates
29
+ /**
30
+ * PRI-1127: resolve the ONE host this request is scoped to.
31
+ *
32
+ * Review fix: for a PATCH the BODY is the write authority. `updateAdaptive
33
+ * ActivationSettings` defaults to codex when the body has no `host`, so falling
34
+ * back to a query-string host here would make the re-read show a DIFFERENT host
35
+ * than the switch that was just written. GET has no body and uses the query.
36
+ * Unknown values fall back to `codex` for reads; writes are rejected up front
37
+ * by the settings writer itself.
38
+ */
39
+ function adaptiveHostFor(req, body) {
40
+ if (body !== undefined) {
41
+ let fromBody;
42
+ if (typeof body === 'object' && body !== null && !Array.isArray(body) && Object.hasOwn(body, 'host')) {
43
+ fromBody = body.host;
44
+ }
45
+ return isAdaptiveActivationHost(fromBody) ? fromBody : 'codex';
46
+ }
47
+ let fromQuery = null;
48
+ try {
49
+ fromQuery = new URL(req.url ?? '/', 'http://localhost').searchParams.get('host');
50
+ }
51
+ catch { /* malformed URL: keep the default host */ }
52
+ return isAdaptiveActivationHost(fromQuery) ? fromQuery : 'codex';
53
+ }
29
54
  // ── Request Body Reader ──────────────────────────────────────────────────────
30
55
  function readBody(req) {
31
56
  return new Promise((resolve, reject) => {
@@ -82,13 +107,14 @@ export async function handleConfigRoute(req, res, ctx) {
82
107
  sendSuccess(res, { ...summary, ...(errors ? { errors } : {}) });
83
108
  return;
84
109
  }
85
- // GET/PATCH /adaptive-activation — Codex desktop Adaptive Activation entry.
86
- // Workspace-scoped: the model reads THIS workspace's config, candidates and
87
- // injection events; the writer touches the same config path. Saving never
110
+ // GET/PATCH /adaptive-activation — append-only Adaptive Activation entry.
111
+ // Workspace- AND host-scoped (PRI-1127): the model reads THIS workspace's
112
+ // config, candidates and THIS host's injection events; the writer touches the
113
+ // same config path and ONLY the selected host's existing switch. Saving never
88
114
  // sends a scoring request (zero network in this handler).
89
115
  if (subPath === '/adaptive-activation') {
90
116
  if (method === 'GET') {
91
- const model = new AdaptiveActivationConsoleModel(workspaceDir);
117
+ const model = new AdaptiveActivationConsoleModel(workspaceDir, adaptiveHostFor(req));
92
118
  sendSuccess(res, await model.getView());
93
119
  return;
94
120
  }
@@ -111,9 +137,9 @@ export async function handleConfigRoute(req, res, ctx) {
111
137
  sendError(res, result.statusCode, result.error, result.message, result.nextAction ? { nextAction: result.nextAction } : undefined);
112
138
  return;
113
139
  }
114
- // Re-read the full view so the UI can show the CONFIRMED persisted state
115
- // (and the same workspace's candidates/last record) in one response.
116
- const model = new AdaptiveActivationConsoleModel(workspaceDir);
140
+ // Re-read the full view FOR THE SAME HOST so the UI shows the CONFIRMED
141
+ // persisted state and that host's own last record in one response.
142
+ const model = new AdaptiveActivationConsoleModel(workspaceDir, adaptiveHostFor(req, body));
117
143
  sendSuccess(res, await model.getView());
118
144
  return;
119
145
  }
@@ -1880,6 +1880,9 @@
1880
1880
  .p-0 {
1881
1881
  padding: 0px;
1882
1882
  }
1883
+ .p-0\.5 {
1884
+ padding: calc(var(--spacing) * 0.5);
1885
+ }
1883
1886
  .p-1 {
1884
1887
  padding: var(--spacing);
1885
1888
  }
@@ -1913,6 +1916,9 @@
1913
1916
  .px-2 {
1914
1917
  padding-inline: calc(var(--spacing) * 2);
1915
1918
  }
1919
+ .px-2\.5 {
1920
+ padding-inline: calc(var(--spacing) * 2.5);
1921
+ }
1916
1922
  .px-3 {
1917
1923
  padding-inline: calc(var(--spacing) * 3);
1918
1924
  }