create-principles-disciple 1.152.3 → 1.152.5
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 +2 -2
- package/console/dist/server/config/pd-config-store.js +9 -3
- package/console/dist/server/index.js +5 -1
- package/console/dist/server/models/AdaptiveActivationConsoleModel.js +3 -1
- package/console/dist/server/models/ApprovalsConsoleModel.d.ts +6 -0
- package/console/dist/server/models/ApprovalsConsoleModel.js +3 -0
- package/console/dist/server/models/ApprovalsGroupedConsoleModel.d.ts +21 -1
- package/console/dist/server/models/ApprovalsGroupedConsoleModel.js +28 -2
- package/console/dist/server/models/IntentDecisionModel.d.ts +6 -1
- package/console/dist/server/models/IntentDecisionModel.js +17 -9
- package/console/dist/server/routes/approvals.js +7 -0
- package/console/dist/server/routes/config.js +172 -0
- package/console/dist/server/routes/intent-decisions.js +19 -1
- package/console/dist/web/assets/app.css +65 -35
- package/console/dist/web/assets/app.js +32 -32
- package/core/dist/runtime/activation/activation-types.d.ts +6 -0
- package/core/dist/runtime/activation/activation-types.d.ts.map +1 -1
- package/core/dist/runtime/activation/activation-types.js.map +1 -1
- package/core/dist/runtime/activation/index.d.ts +2 -1
- 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/ledger-identity.d.ts +8 -0
- package/core/dist/runtime/activation/ledger-identity.d.ts.map +1 -1
- package/core/dist/runtime/activation/ledger-identity.js +20 -1
- package/core/dist/runtime/activation/ledger-identity.js.map +1 -1
- package/core/dist/runtime/activation/sqlite-approval-store.d.ts +18 -0
- package/core/dist/runtime/activation/sqlite-approval-store.d.ts.map +1 -1
- package/core/dist/runtime/activation/sqlite-approval-store.js +146 -20
- package/core/dist/runtime/activation/sqlite-approval-store.js.map +1 -1
- package/core/dist/runtime/adapter/artificer-l2-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/artificer-l2-adapter.js +11 -4
- package/core/dist/runtime/adapter/artificer-l2-adapter.js.map +1 -1
- package/core/dist/runtime/adapter/l2-agent-loop-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/l2-agent-loop-adapter.js +11 -4
- package/core/dist/runtime/adapter/l2-agent-loop-adapter.js.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-catalog.d.ts +42 -0
- package/core/dist/runtime/adapter/pi-ai-catalog.d.ts.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-catalog.js +68 -0
- package/core/dist/runtime/adapter/pi-ai-catalog.js.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-connection-probe.d.ts +45 -0
- package/core/dist/runtime/adapter/pi-ai-connection-probe.d.ts.map +1 -0
- package/core/dist/runtime/adapter/pi-ai-connection-probe.js +321 -0
- package/core/dist/runtime/adapter/pi-ai-connection-probe.js.map +1 -0
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts +18 -1
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.d.ts.map +1 -1
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js +14 -7
- package/core/dist/runtime/adapter/pi-ai-runtime-adapter.js.map +1 -1
- package/core/dist/runtime/config/index.d.ts +2 -0
- package/core/dist/runtime/config/index.d.ts.map +1 -1
- package/core/dist/runtime/config/index.js +1 -0
- package/core/dist/runtime/config/index.js.map +1 -1
- package/core/dist/runtime/config/pd-config-redaction.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-redaction.js +4 -0
- package/core/dist/runtime/config/pd-config-redaction.js.map +1 -1
- package/core/dist/runtime/config/pd-config-types.d.ts +5 -0
- 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-credentials.d.ts +105 -0
- package/core/dist/runtime/config/pd-credentials.d.ts.map +1 -0
- package/core/dist/runtime/config/pd-credentials.js +409 -0
- package/core/dist/runtime/config/pd-credentials.js.map +1 -0
- package/core/dist/runtime/diagnostician/diag-rootcause-output.d.ts +13 -2
- package/core/dist/runtime/diagnostician/diag-rootcause-output.d.ts.map +1 -1
- package/core/dist/runtime/diagnostician/diag-rootcause-output.js.map +1 -1
- package/core/dist/runtime/diagnostician-output.d.ts +1 -1
- package/core/dist/runtime/diagnostician-output.d.ts.map +1 -1
- package/core/dist/runtime/diagnostician-output.js +2 -2
- package/core/dist/runtime/diagnostician-output.js.map +1 -1
- package/core/dist/runtime/index.d.ts +5 -2
- package/core/dist/runtime/index.d.ts.map +1 -1
- package/core/dist/runtime/index.js +11 -1
- package/core/dist/runtime/index.js.map +1 -1
- package/core/dist/runtime/intent/index.d.ts +2 -0
- package/core/dist/runtime/intent/index.d.ts.map +1 -1
- package/core/dist/runtime/intent/index.js +2 -0
- package/core/dist/runtime/intent/index.js.map +1 -1
- package/core/dist/runtime/intent/intent-decision-record.d.ts +51 -3
- package/core/dist/runtime/intent/intent-decision-record.d.ts.map +1 -1
- package/core/dist/runtime/intent/intent-snapshot.d.ts +104 -0
- package/core/dist/runtime/intent/intent-snapshot.d.ts.map +1 -0
- package/core/dist/runtime/intent/intent-snapshot.js +164 -0
- package/core/dist/runtime/intent/intent-snapshot.js.map +1 -0
- package/core/dist/runtime/intent/strategic-conflict-gate.d.ts +70 -0
- package/core/dist/runtime/intent/strategic-conflict-gate.d.ts.map +1 -0
- package/core/dist/runtime/intent/strategic-conflict-gate.js +148 -0
- package/core/dist/runtime/intent/strategic-conflict-gate.js.map +1 -0
- package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts +41 -1
- package/core/dist/runtime/internalization/diag-rootcause-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/diag-rootcause-runner.js +189 -42
- package/core/dist/runtime/internalization/diag-rootcause-runner.js.map +1 -1
- package/core/dist/runtime/internalization/diag-router-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/diag-router-runner.js +10 -0
- package/core/dist/runtime/internalization/diag-router-runner.js.map +1 -1
- package/core/dist/runtime/internalization/dreamer-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime/internalization/dreamer-prompt-builder.js +3 -0
- package/core/dist/runtime/internalization/dreamer-prompt-builder.js.map +1 -1
- package/core/dist/runtime/internalization/formation-context.d.ts +54 -0
- package/core/dist/runtime/internalization/formation-context.d.ts.map +1 -1
- package/core/dist/runtime/internalization/formation-context.js +135 -3
- package/core/dist/runtime/internalization/formation-context.js.map +1 -1
- package/core/dist/runtime/internalization/index.d.ts +2 -2
- package/core/dist/runtime/internalization/index.d.ts.map +1 -1
- package/core/dist/runtime/internalization/index.js +1 -1
- package/core/dist/runtime/internalization/index.js.map +1 -1
- package/core/dist/runtime/internalization/intent-contract.d.ts +107 -0
- package/core/dist/runtime/internalization/intent-contract.d.ts.map +1 -1
- package/core/dist/runtime/internalization/intent-contract.js +315 -4
- package/core/dist/runtime/internalization/intent-contract.js.map +1 -1
- package/core/dist/runtime/internalization/peer-runner-contracts.d.ts +8 -0
- package/core/dist/runtime/internalization/peer-runner-contracts.d.ts.map +1 -1
- package/core/dist/runtime/internalization/peer-runner-contracts.js.map +1 -1
- package/core/dist/runtime/internalization/philosopher-prompt-builder.d.ts +22 -1
- package/core/dist/runtime/internalization/philosopher-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime/internalization/philosopher-prompt-builder.js +22 -3
- package/core/dist/runtime/internalization/philosopher-prompt-builder.js.map +1 -1
- package/core/dist/runtime/internalization/philosopher-runner.d.ts +15 -0
- package/core/dist/runtime/internalization/philosopher-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/philosopher-runner.js +73 -1
- package/core/dist/runtime/internalization/philosopher-runner.js.map +1 -1
- package/core/dist/runtime/internalization/pitask-metadata.d.ts +32 -0
- package/core/dist/runtime/internalization/pitask-metadata.d.ts.map +1 -1
- package/core/dist/runtime/internalization/pitask-metadata.js +44 -0
- package/core/dist/runtime/internalization/pitask-metadata.js.map +1 -1
- package/core/dist/runtime/internalization/scribe-output.d.ts +21 -0
- package/core/dist/runtime/internalization/scribe-output.d.ts.map +1 -1
- package/core/dist/runtime/internalization/scribe-output.js +125 -2
- package/core/dist/runtime/internalization/scribe-output.js.map +1 -1
- package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts +26 -1
- package/core/dist/runtime/internalization/scribe-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime/internalization/scribe-prompt-builder.js +33 -3
- package/core/dist/runtime/internalization/scribe-prompt-builder.js.map +1 -1
- package/core/dist/runtime/internalization/scribe-runner.d.ts +32 -2
- package/core/dist/runtime/internalization/scribe-runner.d.ts.map +1 -1
- package/core/dist/runtime/internalization/scribe-runner.js +105 -7
- package/core/dist/runtime/internalization/scribe-runner.js.map +1 -1
- package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.d.ts +7 -0
- package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.d.ts.map +1 -1
- package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.js +7 -1
- package/core/dist/runtime/store/artifact/sqlite-pi-artifact-store.js.map +1 -1
- package/core/dist/runtime/store/intent/sqlite-intent-decision-store.d.ts +2 -2
- package/core/dist/runtime/store/intent/sqlite-intent-decision-store.d.ts.map +1 -1
- package/core/dist/runtime/store/intent/sqlite-intent-decision-store.js +285 -35
- package/core/dist/runtime/store/intent/sqlite-intent-decision-store.js.map +1 -1
- package/core/dist/runtime/store/sqlite-connection.d.ts.map +1 -1
- package/core/dist/runtime/store/sqlite-connection.js +38 -3
- package/core/dist/runtime/store/sqlite-connection.js.map +1 -1
- package/core/dist/telemetry-event.d.ts +2 -2
- package/core/dist/telemetry-event.d.ts.map +1 -1
- package/core/dist/telemetry-event.js +9 -0
- package/core/dist/telemetry-event.js.map +1 -1
- package/core/package.json +1 -1
- package/dist/installers/codex-host-installer.d.ts.map +1 -1
- package/dist/installers/codex-host-installer.js +9 -12
- package/dist/installers/codex-host-installer.js.map +1 -1
- package/dist/update/release-metadata-publisher.d.ts +3 -1
- package/dist/update/release-metadata-publisher.d.ts.map +1 -1
- package/dist/update/release-metadata-publisher.js +33 -2
- package/dist/update/release-metadata-publisher.js.map +1 -1
- package/dist/update/trust-metadata.d.ts +21 -0
- package/dist/update/trust-metadata.d.ts.map +1 -1
- package/dist/update/trust-metadata.js +192 -4
- package/dist/update/trust-metadata.js.map +1 -1
- package/host-runtime/dist/adaptive-priority-provider.d.ts +1 -1
- package/host-runtime/dist/adaptive-priority-provider.js +4 -3
- package/host-runtime/dist/adaptive-selection.d.ts +1 -1
- package/host-runtime/dist/adaptive-selection.js +2 -1
- package/host-runtime/dist/signal-classifier.js +4 -4
- package/host-runtime/package.json +1 -1
- package/install-layout/dist/mcp-binding-contract.js +4 -15
- package/install-layout/package.json +1 -1
- package/package.json +3 -3
- package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-retry.js +6 -4
- package/pd-cli/dist/commands/pain-retry.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-once.js +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-once.js.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-rulehost.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js +5 -5
- package/pd-cli/dist/commands/runtime-internalization-run-rulehost.js.map +1 -1
- package/pd-cli/dist/commands/runtime.js +6 -6
- package/pd-cli/dist/commands/runtime.js.map +1 -1
- package/pd-cli/dist/services/config-doctor.d.ts.map +1 -1
- package/pd-cli/dist/services/config-doctor.js +5 -4
- package/pd-cli/dist/services/config-doctor.js.map +1 -1
- package/pd-cli/dist/services/runtime-adapter-resolver.d.ts.map +1 -1
- package/pd-cli/dist/services/runtime-adapter-resolver.js +5 -5
- package/pd-cli/dist/services/runtime-adapter-resolver.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/plugin/dist/bundle.js +521 -497
- package/release-manager/dist/installers/codex-host-installer.js +9 -12
- package/release-manager/dist/update/trust-metadata.js +192 -4
- package/release-manager/package.json +1 -1
- package/dist/installers/mcp-binding-shape-mirror.d.ts +0 -27
- package/dist/installers/mcp-binding-shape-mirror.d.ts.map +0 -1
- package/dist/installers/mcp-binding-shape-mirror.js +0 -105
- package/dist/installers/mcp-binding-shape-mirror.js.map +0 -1
- package/release-manager/dist/installers/mcp-binding-shape-mirror.js +0 -105
|
@@ -1222,11 +1222,17 @@ function extractProfileFields(payload, type) {
|
|
|
1222
1222
|
}
|
|
1223
1223
|
/**
|
|
1224
1224
|
* Read raw config file preserving unknown root sections.
|
|
1225
|
-
*
|
|
1225
|
+
*
|
|
1226
|
+
* A missing file is seeded with the complete default config, not `{}`:
|
|
1227
|
+
* `validatePdConfig` requires `version`, `features` and `internalAgents`, so a
|
|
1228
|
+
* profile write to a fresh workspace must start from defaults. Writing an empty
|
|
1229
|
+
* record failed with "missing required field version/features/internalAgents".
|
|
1230
|
+
*
|
|
1226
1231
|
* Treats parsed YAML as unknown (ERR-001).
|
|
1227
|
-
*/
|
|
1232
|
+
*/
|
|
1233
|
+
function readRawConfig(configPath) {
|
|
1228
1234
|
if (!fs.existsSync(configPath)) {
|
|
1229
|
-
return
|
|
1235
|
+
return Object.fromEntries(Object.entries(computeEffectivePdConfig(null).config));
|
|
1230
1236
|
}
|
|
1231
1237
|
const rawContent = fs.readFileSync(configPath, 'utf8');
|
|
1232
1238
|
const rawParsed = yaml.load(rawContent, { schema: yaml.JSON_SCHEMA });
|
|
@@ -203,6 +203,10 @@ function serveFile(res, filePath) {
|
|
|
203
203
|
// recovery probe budget from the same constant (strictly smaller), so a probe
|
|
204
204
|
// can never outlive the request that awaits it.
|
|
205
205
|
export const REQUEST_TIMEOUT_MS = CONSOLE_REQUEST_BUDGET_MS;
|
|
206
|
+
// PRI-1213: the one route that waits on a remote provider. The probe itself is
|
|
207
|
+
// bounded (15s model list + 20s minimal chat, no retries); this only keeps the
|
|
208
|
+
// transport wrapper from 504-ing before that bound is reached.
|
|
209
|
+
const CONNECTION_PROBE_TIMEOUT_MS = 60_000;
|
|
206
210
|
const UPDATE_APPLY_TIMEOUT_MS = 120000;
|
|
207
211
|
// Full update downloads a tarball + copies files — allow 3 min for slow networks.
|
|
208
212
|
// PD_UPDATE_APPLY_FULL_TIMEOUT_MS (ms) overrides it for slow-disk machines:
|
|
@@ -502,7 +506,7 @@ export function handleRequest(services) {
|
|
|
502
506
|
// /api/config/agents/:name/binding, /api/config/readiness/:name
|
|
503
507
|
if (routePath === '/api/config' || routePath.startsWith('/api/config/')) {
|
|
504
508
|
const subPath = routePath.slice('/api/config'.length);
|
|
505
|
-
asyncHandler(() => handleConfigRoute(req, res, { workspaceDir: services.workspaceDir, subPath }))(req, res);
|
|
509
|
+
asyncHandler(() => handleConfigRoute(req, res, { workspaceDir: services.workspaceDir, subPath }), subPath === '/connection-test' ? CONNECTION_PROBE_TIMEOUT_MS : REQUEST_TIMEOUT_MS)(req, res);
|
|
506
510
|
return;
|
|
507
511
|
}
|
|
508
512
|
// CR8: GET /api/lifecycle/principles/:principleId
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import path from 'node:path';
|
|
18
18
|
import { readAdaptiveInjectionRecords, readPromptActivationCandidates, } from '@principles/host-runtime';
|
|
19
|
+
import { pdProviderCredentials } from '@principles/core/runtime';
|
|
19
20
|
import { loadPdConfig, ADAPTIVE_ACTIVATION_SERVICE_PRESET } from '../config/pd-config-store.js';
|
|
20
21
|
const UNKNOWN_EVIDENCE = {
|
|
21
22
|
status: 'unknown',
|
|
@@ -131,7 +132,8 @@ export class AdaptiveActivationConsoleModel {
|
|
|
131
132
|
provider: section?.provider ?? null,
|
|
132
133
|
responseModels: section?.responseModels ?? [],
|
|
133
134
|
apiKeyEnv,
|
|
134
|
-
|
|
135
|
+
// PRI-1213: a key saved in ~/.pd/credentials.yaml is visible to this process too.
|
|
136
|
+
credentialSeenInConsoleProcess: pdProviderCredentials.resolve(apiKeyEnv).value !== null,
|
|
135
137
|
},
|
|
136
138
|
replaceableActivationIds: [...replaceableActivationIds],
|
|
137
139
|
appendOnlyEligible: replaceableActivationIds.length === 0,
|
|
@@ -50,6 +50,12 @@ export type ApproveWithActivationResult = {
|
|
|
50
50
|
} | {
|
|
51
51
|
ok: false;
|
|
52
52
|
error: 'not_found';
|
|
53
|
+
} | {
|
|
54
|
+
ok: false;
|
|
55
|
+
error: 'strategic_conflict_unconfirmed';
|
|
56
|
+
reason: string;
|
|
57
|
+
nextAction: string;
|
|
58
|
+
status?: never;
|
|
53
59
|
} | {
|
|
54
60
|
ok: false;
|
|
55
61
|
error: 'stale_review';
|
|
@@ -256,6 +256,9 @@ export class ApprovalsConsoleModel {
|
|
|
256
256
|
if (!approvalResult.ok) {
|
|
257
257
|
if (approvalResult.error === 'stale_review')
|
|
258
258
|
return approvalResult;
|
|
259
|
+
if (approvalResult.error === 'strategic_conflict_unconfirmed') {
|
|
260
|
+
return { ok: false, error: approvalResult.error, reason: approvalResult.reason, nextAction: approvalResult.nextAction };
|
|
261
|
+
}
|
|
259
262
|
if (approvalResult.error === 'already_decided') {
|
|
260
263
|
return { ok: false, error: 'already_decided', status: approvalResult.status };
|
|
261
264
|
}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { type PromptInjectionTargetHost } from '@principles/host-runtime';
|
|
2
|
+
import type { StrategicConflictView } from '@principles/core/runtime';
|
|
2
3
|
import type { PromptInjectionBudgetStatus } from '../../shared/prompt-injection-contract.js';
|
|
3
|
-
export type ApprovalApproveBlockCode = 'identity_unresolved' | 'artifact_unavailable' | 'budget_exceeded' | 'route_unconfirmed' | 'authority_unreadable' | 'content_unconfirmed'
|
|
4
|
+
export type ApprovalApproveBlockCode = 'identity_unresolved' | 'artifact_unavailable' | 'budget_exceeded' | 'route_unconfirmed' | 'authority_unreadable' | 'content_unconfirmed'
|
|
5
|
+
/**
|
|
6
|
+
* SIA v1.2 (TECH §8.3/§8.5): a CONFIRMED strategic conflict has no effective
|
|
7
|
+
* resolution for this exact contract. Computed by the SAME server function
|
|
8
|
+
* `SqliteApprovalStore.approve()` runs, so the card can never promise an
|
|
9
|
+
* approval the write path refuses.
|
|
10
|
+
*/
|
|
11
|
+
| 'strategic_conflict_unconfirmed';
|
|
4
12
|
export interface ApprovalApproveBlock {
|
|
5
13
|
code: ApprovalApproveBlockCode;
|
|
6
14
|
/** Machine-readable server reason (technical details; not the card copy). */
|
|
@@ -74,6 +82,18 @@ export interface ApprovalGroup {
|
|
|
74
82
|
* an intact sibling approval).
|
|
75
83
|
*/
|
|
76
84
|
revisionReviewUnavailable?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* SIA v1.2: the strategic assessment carried by THIS record's V2 contract
|
|
87
|
+
* (relevance / conflictStatus / conflict targets) plus whether a confirmed
|
|
88
|
+
* conflict is effectively resolved. Absent for V1 artifacts. Read-only
|
|
89
|
+
* projection of the same predicate the approval write path enforces.
|
|
90
|
+
*
|
|
91
|
+
* REVIEW FIX (PR #2652 P1-5): the verdict is per-approval, never per-group.
|
|
92
|
+
* Two pending artifacts in one candidate group can have different conflict
|
|
93
|
+
* states; a group-level copy fenced the sibling with the first artifact's
|
|
94
|
+
* verdict.
|
|
95
|
+
*/
|
|
96
|
+
strategicConflict?: StrategicConflictView;
|
|
77
97
|
}[];
|
|
78
98
|
}
|
|
79
99
|
export interface ApprovalsGroupedResponse {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SqliteConnection, SqliteApprovalQueueStore, SqlitePIArtifactStore, ApprovalQueue, RUNTIME_PRINCIPLE_BUDGET, detectPromptReplacementTarget, computeArtifactDigest, SqliteActivationStateStore, } from '@principles/core/runtime';
|
|
1
|
+
import { SqliteConnection, SqliteApprovalQueueStore, SqlitePIArtifactStore, ApprovalQueue, RUNTIME_PRINCIPLE_BUDGET, detectPromptReplacementTarget, computeArtifactDigest, SqliteActivationStateStore, readStrategicConflictView, } from '@principles/core/runtime';
|
|
2
2
|
import { resolveStateDbPath } from '@principles/core/runtime/storage-paths';
|
|
3
3
|
import { checkPromptArtifactDeliverability, hostRotationCapability, operatorDeclaredBudgetResolution, resolveLivePromptInjectionProjection, RUNTIME_BUDGET_OBSERVATION_STALE_REASON, runtimeBudgetObservationToResolution, selectConsoleRuntimeBudgetFacts, } from '@principles/host-runtime';
|
|
4
4
|
import { PROMPT_BUDGET_HOST_KINDS } from '@principles/core/runtime';
|
|
@@ -285,6 +285,9 @@ export class ApprovalsGroupedConsoleModel {
|
|
|
285
285
|
// or pruned) — those cards have no contentJson, so the UI must degrade
|
|
286
286
|
// visibly instead of rendering the `unlinked:` machine id as a title.
|
|
287
287
|
const artifactUnavailableMap = new Map();
|
|
288
|
+
// SIA v1.2: per-artifact strategic assessment computed read-only with the
|
|
289
|
+
// SAME server predicate the approval write path enforces (TECH §8.5).
|
|
290
|
+
const artifactStrategicMap = new Map();
|
|
288
291
|
const stateDir = path.join(this.workspaceDir, '.state');
|
|
289
292
|
const resolutionDeps = createArtifactPrincipleResolutionDeps(conn, artifactStore, this.workspaceDir);
|
|
290
293
|
for (const approval of allApprovals) {
|
|
@@ -304,6 +307,14 @@ export class ApprovalsGroupedConsoleModel {
|
|
|
304
307
|
else {
|
|
305
308
|
artifactDescriptionMap.set(approval.artifactId, null);
|
|
306
309
|
}
|
|
310
|
+
if (artifact !== null) {
|
|
311
|
+
artifactStrategicMap.set(approval.artifactId, readStrategicConflictView({
|
|
312
|
+
db: conn.getDb(),
|
|
313
|
+
artifactId: artifact.artifactId,
|
|
314
|
+
contentJson: artifact.contentJson,
|
|
315
|
+
artifactDigest: computeArtifactDigest(artifact),
|
|
316
|
+
}));
|
|
317
|
+
}
|
|
307
318
|
if (artifact?.artifactKind === 'principle' && approval.channel === 'prompt' && approval.status === 'pending') {
|
|
308
319
|
const detection = await detectPromptReplacementTarget({
|
|
309
320
|
approvalArtifactId: artifact.artifactId,
|
|
@@ -393,9 +404,23 @@ export class ApprovalsGroupedConsoleModel {
|
|
|
393
404
|
// rejected records are history and must not be retro-labelled.
|
|
394
405
|
// The verdict is attached to the RECORD that was measured: a sibling
|
|
395
406
|
// pending record in the same group must not inherit this fence.
|
|
396
|
-
|
|
407
|
+
// SIA v1.2: a confirmed-but-unresolved strategic conflict blocks ANY
|
|
408
|
+
// channel — the server refuses the write on every approval channel.
|
|
409
|
+
// REVIEW FIX (PR #2652 P1-5): this verdict belongs to THIS approval's
|
|
410
|
+
// artifact; a sibling pending record must never inherit it.
|
|
411
|
+
const recordStrategic = artifactStrategicMap.get(approval.artifactId);
|
|
412
|
+
const strategicView = approval.status === 'pending' ? recordStrategic : undefined;
|
|
413
|
+
const strategicBlock = strategicView !== undefined && !strategicView.resolved
|
|
414
|
+
? {
|
|
415
|
+
code: 'strategic_conflict_unconfirmed',
|
|
416
|
+
reason: strategicView.reason ?? 'no_effective_resolution',
|
|
417
|
+
nextAction: strategicView.nextAction ?? 'resolve the confirmed strategic conflict for this contract, then approve again',
|
|
418
|
+
}
|
|
419
|
+
: undefined;
|
|
420
|
+
const promptBlock = approval.status === 'pending' && approval.channel === 'prompt'
|
|
397
421
|
? artifactApproveBlockMap.get(approval.artifactId)
|
|
398
422
|
: undefined;
|
|
423
|
+
const recordApproveBlock = strategicBlock ?? promptBlock;
|
|
399
424
|
records.push({
|
|
400
425
|
id: approval.approvalId,
|
|
401
426
|
artifactId: approval.artifactId,
|
|
@@ -405,6 +430,7 @@ export class ApprovalsGroupedConsoleModel {
|
|
|
405
430
|
? approval.status
|
|
406
431
|
: 'pending',
|
|
407
432
|
...(recordApproveBlock !== undefined ? { approveBlock: recordApproveBlock } : {}),
|
|
433
|
+
...(recordStrategic !== undefined ? { strategicConflict: recordStrategic } : {}),
|
|
408
434
|
...(revisionReviewUnavailable.has(approval.artifactId) ? { revisionReviewUnavailable: true } : {}),
|
|
409
435
|
});
|
|
410
436
|
}
|
|
@@ -23,6 +23,11 @@ export type IntentDecisionRecordResultModel = {
|
|
|
23
23
|
ok: true;
|
|
24
24
|
record: IntentDecisionRecord;
|
|
25
25
|
created: boolean;
|
|
26
|
+
conflict?: {
|
|
27
|
+
reason: string;
|
|
28
|
+
message: string;
|
|
29
|
+
nextAction: string;
|
|
30
|
+
};
|
|
26
31
|
} | {
|
|
27
32
|
ok: false;
|
|
28
33
|
reason: string;
|
|
@@ -43,7 +48,7 @@ export type FollowUpDispatchResultModel = {
|
|
|
43
48
|
record: IntentDecisionRecord;
|
|
44
49
|
} | {
|
|
45
50
|
ok: false;
|
|
46
|
-
reason: 'decision_not_found' | 'state_db_not_found' | 'intent_decisions_table_missing';
|
|
51
|
+
reason: 'decision_not_found' | 'candidate_already_bound' | 'state_db_not_found' | 'intent_decisions_table_missing';
|
|
47
52
|
nextAction: string;
|
|
48
53
|
};
|
|
49
54
|
export declare class IntentDecisionModel {
|
|
@@ -59,7 +59,9 @@ export class IntentDecisionModel {
|
|
|
59
59
|
try {
|
|
60
60
|
const store = new SqliteIntentDecisionStore(connection);
|
|
61
61
|
const result = await store.record(input);
|
|
62
|
-
return
|
|
62
|
+
return result.conflict === undefined
|
|
63
|
+
? { ok: true, record: result.record, created: result.created }
|
|
64
|
+
: { ok: true, record: result.record, created: result.created, conflict: result.conflict };
|
|
63
65
|
}
|
|
64
66
|
catch (err) {
|
|
65
67
|
if (isMissingTableError(err)) {
|
|
@@ -177,15 +179,21 @@ export class IntentDecisionModel {
|
|
|
177
179
|
const connection = new SqliteConnection({ workspaceDir: this.workspaceDir });
|
|
178
180
|
try {
|
|
179
181
|
const store = new SqliteIntentDecisionStore(connection);
|
|
180
|
-
const
|
|
181
|
-
if (
|
|
182
|
-
return
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
182
|
+
const result = await store.updateFollowUp(id, patch);
|
|
183
|
+
if (!result.ok) {
|
|
184
|
+
return result.reason === 'candidate_already_bound'
|
|
185
|
+
? {
|
|
186
|
+
ok: false,
|
|
187
|
+
reason: 'candidate_already_bound',
|
|
188
|
+
nextAction: result.message + ' Record a new Owner decision for the other candidate instead.',
|
|
189
|
+
}
|
|
190
|
+
: {
|
|
191
|
+
ok: false,
|
|
192
|
+
reason: 'decision_not_found',
|
|
193
|
+
nextAction: 'Intent decision ' + id + ' does not exist. Refresh the page and try again.',
|
|
194
|
+
};
|
|
187
195
|
}
|
|
188
|
-
return { ok: true, record };
|
|
196
|
+
return { ok: true, record: result.record };
|
|
189
197
|
}
|
|
190
198
|
catch (err) {
|
|
191
199
|
if (isMissingTableError(err)) {
|
|
@@ -185,6 +185,13 @@ export async function handleApprovalsRoute(req, res, workspaceDir, subPath) {
|
|
|
185
185
|
// reload and re-judge rather than reject the history.
|
|
186
186
|
sendError(res, 409, 'precheck_stale', `precheck_stale: the approval precheck no longer describes the current material; nothing was written. ${result.reason}`, { reason: 'precheck_stale', nextAction: result.nextAction });
|
|
187
187
|
}
|
|
188
|
+
else if (result.error === 'strategic_conflict_unconfirmed') {
|
|
189
|
+
// SIA v1.2 Phase 3: the server-side gate refused BEFORE any write while
|
|
190
|
+
// a confirmed strategic conflict is unresolved for this exact contract.
|
|
191
|
+
// 422: the request is well-formed but the governance state forbids the
|
|
192
|
+
// write; the approval stays pending and can be retried after resolution.
|
|
193
|
+
sendError(res, 422, 'strategic_conflict_unconfirmed', `Approval refused before any write; the approval remains pending. ${result.reason}`, { reason: 'strategic_conflict_unconfirmed', nextAction: result.nextAction });
|
|
194
|
+
}
|
|
188
195
|
else if (result.error === 'prompt_capacity_refused') {
|
|
189
196
|
// R-B2: refused BEFORE any governance write — the approval stays
|
|
190
197
|
// pending. 422: the request is well-formed but the artifact cannot
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* - ERR-014/ERR-016/ERR-017: Safe serialization for previews
|
|
21
21
|
* - ERR-045: ANY-segment redaction for sensitive keys
|
|
22
22
|
*/
|
|
23
|
+
import { pdProviderCatalog, pdProviderCredentials, probeProviderConnection, } from '@principles/core/runtime';
|
|
23
24
|
import { sendSuccess, sendError, sendNotFound, sendMethodNotAllowed, sendBadRequest, sendJson } from '../utils/response.js';
|
|
24
25
|
import { getConfigSummary, getConfigCatalog, updateAgentBinding, updateDefaultRuntime, checkReadiness, getPrinciplesOutputLanguage, updatePrinciplesOutputLanguage, updateFeatureFlag, updateAdaptiveActivationSettings, createRuntimeProfile, updateRuntimeProfile, deleteRuntimeProfile, } from '../config/pd-config-store.js';
|
|
25
26
|
import { AdaptiveActivationConsoleModel } from '../models/AdaptiveActivationConsoleModel.js';
|
|
@@ -59,6 +60,15 @@ function sendProfileCrudError(res, result) {
|
|
|
59
60
|
sendError(res, result.statusCode, result.error, result.message, result.nextAction ? { nextAction: result.nextAction } : undefined);
|
|
60
61
|
}
|
|
61
62
|
// ── Route Handler ────────────────────────────────────────────────────────────
|
|
63
|
+
function collectReferencedApiKeyEnvs(workspaceDir) {
|
|
64
|
+
const envs = new Set();
|
|
65
|
+
for (const profile of getConfigCatalog(workspaceDir).profiles) {
|
|
66
|
+
if (typeof profile.apiKeyEnv === 'string' && profile.apiKeyEnv !== '') {
|
|
67
|
+
envs.add(profile.apiKeyEnv);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return envs;
|
|
71
|
+
}
|
|
62
72
|
export async function handleConfigRoute(req, res, ctx) {
|
|
63
73
|
const { workspaceDir, subPath } = ctx;
|
|
64
74
|
const method = req.method ?? 'GET';
|
|
@@ -396,6 +406,168 @@ export async function handleConfigRoute(req, res, ctx) {
|
|
|
396
406
|
sendMethodNotAllowed(res);
|
|
397
407
|
return;
|
|
398
408
|
}
|
|
409
|
+
// GET /provider-catalog — PRI-1213 read-only projection of the pi-ai catalog.
|
|
410
|
+
// The console never edits provider endpoints or model lists; it selects.
|
|
411
|
+
if (subPath === '/provider-catalog') {
|
|
412
|
+
if (method !== 'GET') {
|
|
413
|
+
sendMethodNotAllowed(res);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
sendSuccess(res, { providers: pdProviderCatalog.list() });
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
// GET/PUT/DELETE /credentials/:envName — local credentials file (env wins).
|
|
420
|
+
const credentialMatch = /^\/credentials\/([^/]+)$/.exec(subPath);
|
|
421
|
+
if (credentialMatch) {
|
|
422
|
+
let envName;
|
|
423
|
+
try {
|
|
424
|
+
envName = decodeURIComponent(credentialMatch[1] ?? '');
|
|
425
|
+
}
|
|
426
|
+
catch {
|
|
427
|
+
sendBadRequest(res, 'Invalid credential name encoding');
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (!pdProviderCredentials.isValidEnvName(envName)) {
|
|
431
|
+
sendBadRequest(res, 'Credential name must be a valid environment variable name');
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
// Only env names a configured profile actually references may be read or
|
|
435
|
+
// written. Otherwise this endpoint would disclose the last4 of any host
|
|
436
|
+
// environment variable to the browser.
|
|
437
|
+
if (!collectReferencedApiKeyEnvs(workspaceDir).has(envName)) {
|
|
438
|
+
if (method === 'GET') {
|
|
439
|
+
sendSuccess(res, {
|
|
440
|
+
envName,
|
|
441
|
+
configured: false,
|
|
442
|
+
source: 'none',
|
|
443
|
+
error: 'credential_env_not_referenced',
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
sendBadRequest(res, 'Credential env is not referenced by any runtime profile');
|
|
448
|
+
}
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
if (method === 'GET') {
|
|
452
|
+
sendSuccess(res, { envName, ...pdProviderCredentials.status(envName) });
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
if (method === 'PUT') {
|
|
456
|
+
let bodyText;
|
|
457
|
+
try {
|
|
458
|
+
bodyText = await readBody(req);
|
|
459
|
+
}
|
|
460
|
+
catch {
|
|
461
|
+
sendBadRequest(res, 'Request body exceeds maximum allowed size');
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
const body = safeParseBody(bodyText);
|
|
465
|
+
if (body === null) {
|
|
466
|
+
sendBadRequest(res, 'Invalid JSON body');
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (!isObject(body) || !Object.hasOwn(body, 'apiKey') || typeof body.apiKey !== 'string') {
|
|
470
|
+
sendBadRequest(res, 'Body must be a JSON object with a string apiKey field');
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
const saved = pdProviderCredentials.save(envName, body.apiKey);
|
|
474
|
+
if (!saved.ok) {
|
|
475
|
+
// `saved.error` never contains the key; it is a reason + path.
|
|
476
|
+
sendError(res, 500, 'credentials_write_failed', saved.error);
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
const status = pdProviderCredentials.status(envName);
|
|
480
|
+
sendSuccess(res, {
|
|
481
|
+
envName,
|
|
482
|
+
...status,
|
|
483
|
+
filePermissions: saved.permissions,
|
|
484
|
+
// Env wins over the file: surface it so the UI never implies the pasted
|
|
485
|
+
// key is in effect when an environment variable shadows it.
|
|
486
|
+
envOverridesFile: status.source === 'env',
|
|
487
|
+
});
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
if (method === 'DELETE') {
|
|
491
|
+
const deleted = pdProviderCredentials.remove(envName);
|
|
492
|
+
if (!deleted.ok) {
|
|
493
|
+
sendError(res, 500, 'credentials_delete_failed', deleted.error);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
sendSuccess(res, { envName, ...pdProviderCredentials.status(envName), removed: deleted.removed });
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
sendMethodNotAllowed(res);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
// POST /connection-test — optional live check; the only console route that
|
|
503
|
+
// makes outbound provider requests. Budget is bounded by the probe itself.
|
|
504
|
+
if (subPath === '/connection-test') {
|
|
505
|
+
if (method !== 'POST') {
|
|
506
|
+
sendMethodNotAllowed(res);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
let bodyText;
|
|
510
|
+
try {
|
|
511
|
+
bodyText = await readBody(req);
|
|
512
|
+
}
|
|
513
|
+
catch {
|
|
514
|
+
sendBadRequest(res, 'Request body exceeds maximum allowed size');
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
const body = safeParseBody(bodyText);
|
|
518
|
+
if (body === null) {
|
|
519
|
+
sendBadRequest(res, 'Invalid JSON body');
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
if (!isObject(body)) {
|
|
523
|
+
sendBadRequest(res, 'Body must be a JSON object');
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
const { provider, model, apiKeyEnv } = body;
|
|
527
|
+
if (typeof provider !== 'string' || provider.trim() === '' || provider.length > 200) {
|
|
528
|
+
sendBadRequest(res, 'provider must be a non-empty string');
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
if (typeof model !== 'string' || model.trim() === '' || model.length > 200) {
|
|
532
|
+
sendBadRequest(res, 'model must be a non-empty string');
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
if (typeof apiKeyEnv !== 'string' || !pdProviderCredentials.isValidEnvName(apiKeyEnv)) {
|
|
536
|
+
sendBadRequest(res, 'apiKeyEnv must be a valid environment variable name');
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
let baseUrl;
|
|
540
|
+
const { baseUrl: candidateBaseUrl } = body;
|
|
541
|
+
if (Object.hasOwn(body, 'baseUrl') &&
|
|
542
|
+
candidateBaseUrl !== undefined &&
|
|
543
|
+
candidateBaseUrl !== '') {
|
|
544
|
+
if (typeof candidateBaseUrl !== 'string' || candidateBaseUrl.length > 2000) {
|
|
545
|
+
sendBadRequest(res, 'baseUrl must be a string');
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
let parsed;
|
|
549
|
+
try {
|
|
550
|
+
parsed = new URL(candidateBaseUrl);
|
|
551
|
+
}
|
|
552
|
+
catch {
|
|
553
|
+
sendBadRequest(res, 'baseUrl must be a valid URL');
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
557
|
+
sendBadRequest(res, 'baseUrl must use http or https');
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
baseUrl = candidateBaseUrl;
|
|
561
|
+
}
|
|
562
|
+
const result = await probeProviderConnection({
|
|
563
|
+
provider: provider.trim(),
|
|
564
|
+
model: model.trim(),
|
|
565
|
+
apiKeyEnv,
|
|
566
|
+
...(baseUrl !== undefined ? { baseUrl } : {}),
|
|
567
|
+
});
|
|
568
|
+
sendSuccess(res, result);
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
399
571
|
// 404 fallback
|
|
400
572
|
sendNotFound(res, `Route /api/config${subPath} not found`);
|
|
401
573
|
}
|
|
@@ -140,7 +140,7 @@ function validateInput(parsed, res) {
|
|
|
140
140
|
typedRefs.push(ref);
|
|
141
141
|
}
|
|
142
142
|
// Optional string fields — validated only when present (Rule 5: Object.hasOwn)
|
|
143
|
-
const optionalStringFields = ['painId', 'taskId', 'runId', 'intentDocHash', 'note'];
|
|
143
|
+
const optionalStringFields = ['painId', 'taskId', 'runId', 'intentDocHash', 'artifactId', 'candidateId', 'note'];
|
|
144
144
|
const optional = {};
|
|
145
145
|
for (const key of optionalStringFields) {
|
|
146
146
|
if (Object.hasOwn(parsed, key)) {
|
|
@@ -163,6 +163,8 @@ function validateInput(parsed, res) {
|
|
|
163
163
|
taskId: optional.taskId,
|
|
164
164
|
runId: optional.runId,
|
|
165
165
|
intentDocHash: optional.intentDocHash,
|
|
166
|
+
artifactId: optional.artifactId,
|
|
167
|
+
candidateId: optional.candidateId,
|
|
166
168
|
note: optional.note,
|
|
167
169
|
};
|
|
168
170
|
}
|
|
@@ -241,6 +243,13 @@ function sendFollowUpModelFailure(res, result) {
|
|
|
241
243
|
if (result.reason === 'decision_not_found') {
|
|
242
244
|
sendNotFound(res, result.nextAction);
|
|
243
245
|
}
|
|
246
|
+
else if (result.reason === 'candidate_already_bound') {
|
|
247
|
+
// REVIEW FIX (PR #2652 P0-3 / P1-4): the candidate binding is write-once.
|
|
248
|
+
sendError(res, 409, 'candidate_already_bound', result.nextAction, {
|
|
249
|
+
reason: result.reason,
|
|
250
|
+
nextAction: result.nextAction,
|
|
251
|
+
});
|
|
252
|
+
}
|
|
244
253
|
else if (result.reason === 'state_db_not_found') {
|
|
245
254
|
sendError(res, 409, 'workspace_not_initialized', result.reason, {
|
|
246
255
|
reason: result.reason,
|
|
@@ -279,6 +288,15 @@ export async function handleIntentDecisionsRoute(req, res, workspaceDir, subPath
|
|
|
279
288
|
// The `created` flag lets the frontend distinguish a fresh write from a
|
|
280
289
|
// replay (200 vs 201 HTTP status also conveys this).
|
|
281
290
|
const responseData = { record: result.record, created: result.created };
|
|
291
|
+
// REVIEW FIX (PR #2652 P0-3): a replay whose bound contract has changed is
|
|
292
|
+
// NOT a successful replay — the Owner must re-review the new contract.
|
|
293
|
+
if (result.conflict !== undefined) {
|
|
294
|
+
sendError(res, 409, result.conflict.reason, result.conflict.message, {
|
|
295
|
+
reason: result.conflict.reason,
|
|
296
|
+
nextAction: result.conflict.nextAction,
|
|
297
|
+
});
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
282
300
|
if (result.created) {
|
|
283
301
|
// Fresh create → 201 (sendJson with explicit status; sendSuccess is 200-only).
|
|
284
302
|
sendJson(res, 201, { success: true, data: responseData });
|