create-principles-disciple 1.149.0 → 1.150.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_release/product-identity.json +1 -1
- package/codex-adapter/dist/ingestion/ingestion.d.ts +9 -7
- package/codex-adapter/dist/ingestion/ingestion.js +68 -144
- package/codex-adapter/dist/ingestion/transcript-decoder.d.ts +35 -44
- package/codex-adapter/dist/ingestion/transcript-decoder.js +23 -84
- package/codex-adapter/dist/ingestion/transcript-source.d.ts +29 -0
- package/codex-adapter/dist/ingestion/transcript-source.js +65 -0
- package/codex-adapter/dist/pd-hook.d.ts +27 -1
- package/codex-adapter/dist/pd-hook.js +88 -7
- package/codex-adapter/dist/worker/workspace-worker.d.ts +15 -0
- package/codex-adapter/dist/worker/workspace-worker.js +7 -36
- package/codex-adapter/package.json +1 -1
- package/console/dist/server/index.js +14 -0
- package/console/dist/server/models/ActivationsConsoleModel.d.ts +3 -17
- package/console/dist/server/models/ActivationsConsoleModel.js +5 -44
- package/console/dist/server/routes/diagnostician.d.ts +50 -0
- package/console/dist/server/routes/diagnostician.js +388 -0
- package/console/dist/server/routes/examiner-eligibility.d.ts +73 -0
- package/console/dist/server/routes/examiner-eligibility.js +326 -0
- package/console/dist/server/routes/examiner.js +66 -8
- package/console/dist/web/assets/app.css +40 -0
- package/console/dist/web/assets/app.js +30 -30
- package/core/dist/host/host-installer.d.ts +7 -0
- package/core/dist/host/host-installer.d.ts.map +1 -1
- package/core/dist/host/host-installer.js.map +1 -1
- package/core/dist/runtime/activation/index.d.ts +3 -3
- package/core/dist/runtime/activation/index.d.ts.map +1 -1
- package/core/dist/runtime/activation/index.js +1 -1
- package/core/dist/runtime/activation/index.js.map +1 -1
- package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts +25 -1
- package/core/dist/runtime/activation/promotion-readiness-evaluator.d.ts.map +1 -1
- package/core/dist/runtime/activation/promotion-readiness-evaluator.js +58 -1
- package/core/dist/runtime/activation/promotion-readiness-evaluator.js.map +1 -1
- package/core/dist/runtime/activation/promotion-readiness-reader.d.ts.map +1 -1
- package/core/dist/runtime/activation/promotion-readiness-reader.js +4 -2
- package/core/dist/runtime/activation/promotion-readiness-reader.js.map +1 -1
- package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts +28 -0
- package/core/dist/runtime/activation/rulecode-owner-decision-service.d.ts.map +1 -1
- package/core/dist/runtime/activation/rulecode-owner-decision-service.js +2 -0
- package/core/dist/runtime/activation/rulecode-owner-decision-service.js.map +1 -1
- package/core/dist/runtime/admission-gate.d.ts +8 -1
- package/core/dist/runtime/admission-gate.d.ts.map +1 -1
- package/core/dist/runtime/admission-gate.js +2 -1
- package/core/dist/runtime/admission-gate.js.map +1 -1
- package/core/dist/runtime/config/pd-config-defaults.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-defaults.js +20 -2
- package/core/dist/runtime/config/pd-config-defaults.js.map +1 -1
- package/core/dist/runtime/config/pd-config-effective.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-effective.js +5 -2
- package/core/dist/runtime/config/pd-config-effective.js.map +1 -1
- package/core/dist/runtime/config/pd-config-validate.d.ts.map +1 -1
- package/core/dist/runtime/config/pd-config-validate.js +18 -0
- package/core/dist/runtime/config/pd-config-validate.js.map +1 -1
- package/core/dist/runtime/context-payload.d.ts +48 -3
- package/core/dist/runtime/context-payload.d.ts.map +1 -1
- package/core/dist/runtime/context-payload.js +38 -0
- package/core/dist/runtime/context-payload.js.map +1 -1
- package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts +8 -2
- package/core/dist/runtime/diagnostician/rootcause-prompt-builder.d.ts.map +1 -1
- package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js +28 -2
- package/core/dist/runtime/diagnostician/rootcause-prompt-builder.js.map +1 -1
- package/core/dist/runtime/diagnostician-candidate.d.ts +24 -0
- package/core/dist/runtime/diagnostician-candidate.d.ts.map +1 -0
- package/core/dist/runtime/diagnostician-candidate.js +55 -0
- package/core/dist/runtime/diagnostician-candidate.js.map +1 -0
- package/core/dist/runtime/evidence-guards.d.ts +10 -4
- package/core/dist/runtime/evidence-guards.d.ts.map +1 -1
- package/core/dist/runtime/evidence-guards.js +12 -5
- package/core/dist/runtime/evidence-guards.js.map +1 -1
- package/core/dist/runtime/evolution/evolution-types.d.ts +4 -4
- package/core/dist/runtime/evolution/evolution-types.d.ts.map +1 -1
- package/core/dist/runtime/evolution/evolution-types.js +1 -0
- package/core/dist/runtime/evolution/evolution-types.js.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-contract.d.ts.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-contract.js +14 -0
- package/core/dist/runtime/feature-flags/feature-flag-contract.js.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-lifecycle.d.ts.map +1 -1
- package/core/dist/runtime/feature-flags/feature-flag-lifecycle.js +16 -0
- package/core/dist/runtime/feature-flags/feature-flag-lifecycle.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 +6 -1
- package/core/dist/runtime/index.js.map +1 -1
- package/core/dist/runtime/internalization/index.d.ts +1 -0
- package/core/dist/runtime/internalization/index.d.ts.map +1 -1
- package/core/dist/runtime/internalization/index.js +2 -0
- package/core/dist/runtime/internalization/index.js.map +1 -1
- package/core/dist/runtime/internalization/rule-host-contracts.d.ts +10 -0
- package/core/dist/runtime/internalization/rule-host-contracts.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rule-host-evaluator.js +10 -10
- package/core/dist/runtime/internalization/rule-host-evaluator.js.map +1 -1
- package/core/dist/runtime/internalization/rule-host-input-builder.d.ts +7 -6
- package/core/dist/runtime/internalization/rule-host-input-builder.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rule-host-input-builder.js +6 -2
- package/core/dist/runtime/internalization/rule-host-input-builder.js.map +1 -1
- package/core/dist/runtime/internalization/rule-host-result-normalizer.d.ts +33 -0
- package/core/dist/runtime/internalization/rule-host-result-normalizer.d.ts.map +1 -0
- package/core/dist/runtime/internalization/rule-host-result-normalizer.js +61 -0
- package/core/dist/runtime/internalization/rule-host-result-normalizer.js.map +1 -0
- package/core/dist/runtime/internalization/rule-host-validator.d.ts.map +1 -1
- package/core/dist/runtime/internalization/rule-host-validator.js +17 -0
- package/core/dist/runtime/internalization/rule-host-validator.js.map +1 -1
- package/core/dist/runtime/pain-ingress-payload.d.ts +27 -2
- package/core/dist/runtime/pain-ingress-payload.d.ts.map +1 -1
- package/core/dist/runtime/pain-ingress-payload.js +45 -3
- package/core/dist/runtime/pain-ingress-payload.js.map +1 -1
- package/core/dist/runtime/pain-ingress.d.ts +4 -2
- package/core/dist/runtime/pain-ingress.d.ts.map +1 -1
- package/core/dist/runtime/pain-ingress.js +23 -3
- package/core/dist/runtime/pain-ingress.js.map +1 -1
- package/core/dist/runtime/pain-severity.d.ts +14 -0
- package/core/dist/runtime/pain-severity.d.ts.map +1 -0
- package/core/dist/runtime/pain-severity.js +14 -0
- package/core/dist/runtime/pain-severity.js.map +1 -0
- package/core/dist/runtime/pain-signal-bridge.d.ts +17 -3
- package/core/dist/runtime/pain-signal-bridge.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-bridge.js +6 -0
- package/core/dist/runtime/pain-signal-bridge.js.map +1 -1
- package/core/dist/runtime/pain-signal-observability.d.ts.map +1 -1
- package/core/dist/runtime/pain-signal-observability.js +3 -2
- package/core/dist/runtime/pain-signal-observability.js.map +1 -1
- package/core/dist/runtime/pain-submit-capability.d.ts +164 -0
- package/core/dist/runtime/pain-submit-capability.d.ts.map +1 -0
- package/core/dist/runtime/pain-submit-capability.js +442 -0
- package/core/dist/runtime/pain-submit-capability.js.map +1 -0
- package/core/dist/runtime/pain-to-principle-service.d.ts +4 -0
- package/core/dist/runtime/pain-to-principle-service.d.ts.map +1 -1
- package/core/dist/runtime/pain-to-principle-service.js +2 -0
- package/core/dist/runtime/pain-to-principle-service.js.map +1 -1
- package/core/dist/runtime/stalled-diagnostician-task-read-model.d.ts +56 -10
- package/core/dist/runtime/stalled-diagnostician-task-read-model.d.ts.map +1 -1
- package/core/dist/runtime/stalled-diagnostician-task-read-model.js +80 -4
- package/core/dist/runtime/stalled-diagnostician-task-read-model.js.map +1 -1
- package/core/dist/runtime/store/context/sqlite-context-assembler.d.ts.map +1 -1
- package/core/dist/runtime/store/context/sqlite-context-assembler.js +11 -0
- package/core/dist/runtime/store/context/sqlite-context-assembler.js.map +1 -1
- package/core/dist/runtime/store/run/memory-run-store.d.ts +10 -0
- package/core/dist/runtime/store/run/memory-run-store.d.ts.map +1 -1
- package/core/dist/runtime/store/run/memory-run-store.js +21 -0
- package/core/dist/runtime/store/run/memory-run-store.js.map +1 -1
- package/core/dist/runtime/store/run/run-store.d.ts +12 -0
- package/core/dist/runtime/store/run/run-store.d.ts.map +1 -1
- package/core/dist/runtime/store/run/sqlite-run-store.d.ts +1 -0
- package/core/dist/runtime/store/run/sqlite-run-store.d.ts.map +1 -1
- package/core/dist/runtime/store/run/sqlite-run-store.js +14 -0
- package/core/dist/runtime/store/run/sqlite-run-store.js.map +1 -1
- package/core/dist/runtime/task-status.d.ts +9 -0
- package/core/dist/runtime/task-status.d.ts.map +1 -1
- package/core/dist/runtime/task-status.js +7 -1
- package/core/dist/runtime/task-status.js.map +1 -1
- package/core/dist/runtime/types/evidence-chain-contract.d.ts +18 -0
- package/core/dist/runtime/types/evidence-chain-contract.d.ts.map +1 -1
- package/core/dist/runtime/types/evidence-chain-contract.js +37 -7
- package/core/dist/runtime/types/evidence-chain-contract.js.map +1 -1
- package/core/package.json +5 -1
- package/dist/install-summary.d.ts +7 -0
- package/dist/install-summary.d.ts.map +1 -1
- package/dist/install-summary.js +4 -0
- package/dist/install-summary.js.map +1 -1
- package/dist/installer.d.ts +34 -1
- package/dist/installer.d.ts.map +1 -1
- package/dist/installer.js +84 -4
- package/dist/installer.js.map +1 -1
- package/dist/installers/codex-host-installer.d.ts +88 -1
- package/dist/installers/codex-host-installer.d.ts.map +1 -1
- package/dist/installers/codex-host-installer.js +370 -11
- package/dist/installers/codex-host-installer.js.map +1 -1
- package/dist/installers/index.d.ts +23 -0
- package/dist/installers/index.d.ts.map +1 -1
- package/dist/installers/index.js +38 -1
- package/dist/installers/index.js.map +1 -1
- package/dist/installers/legacy-workbuddy-skill.d.ts +59 -0
- package/dist/installers/legacy-workbuddy-skill.d.ts.map +1 -0
- package/dist/installers/legacy-workbuddy-skill.js +168 -0
- package/dist/installers/legacy-workbuddy-skill.js.map +1 -0
- package/dist/installers/workbuddy-host-installer.d.ts.map +1 -1
- package/dist/installers/workbuddy-host-installer.js +7 -0
- package/dist/installers/workbuddy-host-installer.js.map +1 -1
- package/host-runtime/dist/adaptive-priority-provider.d.ts +101 -0
- package/host-runtime/dist/adaptive-priority-provider.js +194 -0
- package/host-runtime/dist/adaptive-selection.d.ts +164 -0
- package/host-runtime/dist/adaptive-selection.js +506 -0
- package/host-runtime/dist/adaptive-skip-decision.d.ts +61 -0
- package/host-runtime/dist/adaptive-skip-decision.js +114 -0
- package/host-runtime/dist/codex-ingestion-consent.d.ts +32 -95
- package/host-runtime/dist/codex-ingestion-consent.js +33 -205
- package/host-runtime/dist/conversation-ingestion/consent.d.ts +124 -0
- package/host-runtime/dist/conversation-ingestion/consent.js +531 -0
- package/host-runtime/dist/conversation-ingestion/index.d.ts +12 -0
- package/host-runtime/dist/conversation-ingestion/index.js +12 -0
- package/host-runtime/dist/conversation-ingestion/pipeline.d.ts +101 -0
- package/host-runtime/dist/conversation-ingestion/pipeline.js +162 -0
- package/host-runtime/dist/conversation-ingestion/source.d.ts +172 -0
- package/host-runtime/dist/conversation-ingestion/source.js +111 -0
- package/host-runtime/dist/conversation-ingestion/text-policy.d.ts +51 -0
- package/host-runtime/dist/conversation-ingestion/text-policy.js +68 -0
- package/host-runtime/dist/diagnostician-auto-run.d.ts +28 -0
- package/host-runtime/dist/diagnostician-auto-run.js +100 -0
- package/host-runtime/dist/governance-observation-store.d.ts +9 -7
- package/host-runtime/dist/governance-observation-store.js +20 -4
- package/host-runtime/dist/host-tool-semantic-resolver.d.ts +42 -1
- package/host-runtime/dist/host-tool-semantic-resolver.js +80 -14
- package/host-runtime/dist/index.d.ts +5 -0
- package/host-runtime/dist/index.js +12 -0
- package/host-runtime/dist/production-rulehost-gate.js +17 -17
- package/host-runtime/dist/rulecode-event-collection.d.ts +31 -0
- package/host-runtime/dist/rulecode-event-collection.js +62 -0
- package/host-runtime/package.json +1 -1
- package/package.json +3 -3
- package/pd-cli/dist/commands/diagnose.d.ts +30 -0
- package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
- package/pd-cli/dist/commands/diagnose.js +75 -0
- package/pd-cli/dist/commands/diagnose.js.map +1 -1
- package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-record.js +5 -4
- package/pd-cli/dist/commands/pain-record.js.map +1 -1
- package/pd-cli/dist/commands/pain-retry.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-retry.js +2 -1
- package/pd-cli/dist/commands/pain-retry.js.map +1 -1
- package/pd-cli/dist/commands/runtime-activation.d.ts +6 -17
- package/pd-cli/dist/commands/runtime-activation.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-activation.js +42 -48
- package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
- package/pd-cli/dist/index.js +1 -0
- package/pd-cli/dist/index.js.map +1 -1
- package/pd-cli/dist/services/delivery-surfaces.js +1 -1
- package/pd-cli/dist/services/delivery-surfaces.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/pd-mcp-server/dist/budget.d.ts +1 -1
- package/pd-mcp-server/dist/budget.js +2 -2
- package/pd-mcp-server/dist/envelope.d.ts +15 -0
- package/pd-mcp-server/dist/envelope.js +49 -1
- package/pd-mcp-server/dist/index.d.ts +2 -0
- package/pd-mcp-server/dist/index.js +6 -0
- package/pd-mcp-server/dist/server.d.ts +83 -14
- package/pd-mcp-server/dist/server.js +251 -4
- package/pd-mcp-server/dist/version.d.ts +1 -1
- package/pd-mcp-server/dist/version.js +1 -1
- package/pd-mcp-server/dist/workspace.d.ts +4 -2
- package/pd-mcp-server/dist/workspace.js +5 -2
- package/pd-mcp-server/package.json +1 -1
- package/plugin/dist/bundle.js +449 -437
- package/plugin/dist/core/evolution-reducer.d.ts +2 -2
- package/plugin/dist/hooks/hook-tool-semantics.d.ts +25 -0
- package/plugin/dist/hooks/pain-ingress-adapter.d.ts +1 -1
- package/plugin/dist/openclaw.plugin.json +1 -1
- package/plugin/dist/rulehost-evidence.js +1 -1
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/release-manager/dist/installer.js +84 -4
- package/release-manager/dist/installers/codex-host-installer.js +370 -11
- package/release-manager/dist/installers/index.js +38 -1
- package/release-manager/dist/installers/legacy-workbuddy-skill.js +168 -0
- package/release-manager/dist/installers/workbuddy-host-installer.js +7 -0
- package/release-manager/package.json +1 -1
- package/workbuddy-adapter/dist/pd-hook.js +20 -4
- package/workbuddy-adapter/package.json +1 -1
- package/workbuddy-adapter/plugin/skills/pd-pain-signal/SKILL.md +123 -20
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* business text (§4.8: no internal details to the Agent).
|
|
19
19
|
*/
|
|
20
20
|
import { type PainRecallCapabilityResult } from '@principles/core/runtime/pain-recall-capability';
|
|
21
|
+
import type { PainSubmitReceipt } from '@principles/core/runtime/pain-submit-capability';
|
|
21
22
|
/** MCP tool result as produced by the handler (single text content block,
|
|
22
23
|
* `structuredContent` intentionally never used — §4.6). The shapes match the
|
|
23
24
|
* SDK's expected result type (mutable content array + index signature). */
|
|
@@ -50,3 +51,17 @@ export declare function assembleResult(envelope: PainRecallCapabilityResult): {
|
|
|
50
51
|
ok: false;
|
|
51
52
|
overBudgetBytes: number;
|
|
52
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* §5.4.3 — assemble a `pd_submit_pain` receipt under the transport budget.
|
|
56
|
+
*
|
|
57
|
+
* Unlike the read tool, an over-budget receipt must never be replaced by a
|
|
58
|
+
* generic failure: the write may have happened. The order is
|
|
59
|
+
* full receipt → minimal receipt (same fields, observability dropped) →
|
|
60
|
+
* explicit statement carrying `taskId`. Only when even "written + taskId"
|
|
61
|
+
* cannot be expressed is `isError: true` allowed — and that message says the
|
|
62
|
+
* outcome is UNKNOWN, never "not created".
|
|
63
|
+
*/
|
|
64
|
+
export declare function assembleSubmitResult(receipt: PainSubmitReceipt, budgetBytes?: number): {
|
|
65
|
+
result: ToolResult;
|
|
66
|
+
degraded: 'none' | 'minimal' | 'untransportable';
|
|
67
|
+
};
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* business text (§4.8: no internal details to the Agent).
|
|
19
19
|
*/
|
|
20
20
|
import { CAPABILITY_SCHEMA_VERSION, OD_A_DISCLOSURE_PROFILE, RECALL_PAIN_CAPABILITY_ID, } from '@principles/core/runtime/pain-recall-capability';
|
|
21
|
-
import { withinBudget } from './budget.js';
|
|
21
|
+
import { RESPONSE_BUDGET_BYTES, withinBudget } from './budget.js';
|
|
22
22
|
export function textResult(text, isError) {
|
|
23
23
|
return isError === undefined
|
|
24
24
|
? { content: [{ type: 'text', text }] }
|
|
@@ -61,3 +61,51 @@ export function assembleResult(envelope) {
|
|
|
61
61
|
}
|
|
62
62
|
return { ok: false, overBudgetBytes: Buffer.byteLength(json, 'utf8') };
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* §5.4.3 — assemble a `pd_submit_pain` receipt under the transport budget.
|
|
66
|
+
*
|
|
67
|
+
* Unlike the read tool, an over-budget receipt must never be replaced by a
|
|
68
|
+
* generic failure: the write may have happened. The order is
|
|
69
|
+
* full receipt → minimal receipt (same fields, observability dropped) →
|
|
70
|
+
* explicit statement carrying `taskId`. Only when even "written + taskId"
|
|
71
|
+
* cannot be expressed is `isError: true` allowed — and that message says the
|
|
72
|
+
* outcome is UNKNOWN, never "not created".
|
|
73
|
+
*/
|
|
74
|
+
export function assembleSubmitResult(receipt, budgetBytes = RESPONSE_BUDGET_BYTES) {
|
|
75
|
+
const isError = receipt.status === 'failed' ? true : undefined;
|
|
76
|
+
const full = JSON.stringify(receipt);
|
|
77
|
+
if (withinBudget(full, budgetBytes)) {
|
|
78
|
+
return { result: textResult(full, isError), degraded: 'none' };
|
|
79
|
+
}
|
|
80
|
+
const minimal = JSON.stringify({
|
|
81
|
+
status: receipt.status,
|
|
82
|
+
painId: receipt.painId,
|
|
83
|
+
taskId: receipt.taskId,
|
|
84
|
+
workspaceDir: receipt.workspaceDir,
|
|
85
|
+
diagnosis: receipt.diagnosis,
|
|
86
|
+
});
|
|
87
|
+
if (withinBudget(minimal, budgetBytes)) {
|
|
88
|
+
return { result: textResult(minimal, isError), degraded: 'minimal' };
|
|
89
|
+
}
|
|
90
|
+
const taskId = receipt.taskId ?? 'unknown';
|
|
91
|
+
const statement = receipt.status === 'submitted' || receipt.status === 'submit_unconfirmed'
|
|
92
|
+
? `Submission status is '${receipt.status}'; taskId is '${taskId}'. The full receipt exceeded the transport budget. Reconcile with \`pd task show ${taskId}\` before any retry.`
|
|
93
|
+
: `Submission status is '${receipt.status}'; taskId is '${taskId}'. The full receipt exceeded the transport budget.`;
|
|
94
|
+
if (withinBudget(statement, budgetBytes)) {
|
|
95
|
+
return { result: textResult(statement), degraded: 'untransportable' };
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
result: textResult(JSON.stringify({
|
|
99
|
+
status: 'unavailable',
|
|
100
|
+
error: {
|
|
101
|
+
code: 'response_budget_exceeded',
|
|
102
|
+
message: 'The receipt could not be expressed within the transport budget; the write outcome is UNKNOWN (it may already have been written). Reconcile before retrying.',
|
|
103
|
+
},
|
|
104
|
+
nextAction: {
|
|
105
|
+
code: 'reconcile',
|
|
106
|
+
message: `Run \`pd task list --kind diagnostician\` and \`pd task show ${taskId}\` before any retry.`,
|
|
107
|
+
},
|
|
108
|
+
}), true),
|
|
109
|
+
degraded: 'untransportable',
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { createPdMcpServer, TOOL_NAME, toolInputSchema } from './server.js';
|
|
2
|
+
export { SUBMIT_TOOL_NAME, SUBMIT_TOOL_DESCRIPTION, submitToolInputJsonSchema, submitToolInputSchema, submitToolProtocolSchema, createMcpPainId, SUBMIT_RECHECK_DEADLINE_MS, } from './server.js';
|
|
3
|
+
export { assembleSubmitResult } from './envelope.js';
|
|
2
4
|
export { resolveWorkspaceBinding, WORKSPACE_DIR_ENV, HOST_ENV } from './workspace.js';
|
|
3
5
|
export { RESPONSE_BUDGET_BYTES, withinBudget, measureTextBytes } from './budget.js';
|
|
4
6
|
export { DEFAULT_DEADLINE_MS, MAX_TRACKED_ORPHANS, runWithDeadline, OrphanLimiter } from './deadline.js';
|
|
@@ -25,6 +25,12 @@ import { resolveWorkspaceBinding } from './workspace.js';
|
|
|
25
25
|
import { combineSinks, createMcpFileLog } from './log-file.js';
|
|
26
26
|
import { createLogger, stderrSink } from './logging.js';
|
|
27
27
|
export { createPdMcpServer, TOOL_NAME, toolInputSchema } from './server.js';
|
|
28
|
+
// `pd_submit_pain` contract surface. Exporting it registers NOTHING: the tool
|
|
29
|
+
// still only exists when `createPdMcpServer({ enableSubmitTool: true })` is
|
|
30
|
+
// passed in code, which is the OG-4 production gate (§6). Process entry
|
|
31
|
+
// (`main` below) never enables it.
|
|
32
|
+
export { SUBMIT_TOOL_NAME, SUBMIT_TOOL_DESCRIPTION, submitToolInputJsonSchema, submitToolInputSchema, submitToolProtocolSchema, createMcpPainId, SUBMIT_RECHECK_DEADLINE_MS, } from './server.js';
|
|
33
|
+
export { assembleSubmitResult } from './envelope.js';
|
|
28
34
|
export { resolveWorkspaceBinding, WORKSPACE_DIR_ENV, HOST_ENV } from './workspace.js';
|
|
29
35
|
export { RESPONSE_BUDGET_BYTES, withinBudget, measureTextBytes } from './budget.js';
|
|
30
36
|
export { DEFAULT_DEADLINE_MS, MAX_TRACKED_ORPHANS, runWithDeadline, OrphanLimiter } from './deadline.js';
|
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PD MCP Server assembly — SPEC-PD-MCP-GATE4-001 §3/§4/§5 (Gate 4-B).
|
|
3
|
-
*
|
|
4
|
-
* One server implementation shared by all three hosts (Codex / OpenClaw /
|
|
5
|
-
* WorkBuddy each spawn their own process around this module). Business data
|
|
6
|
-
* flows EXCLUSIVELY through the Gate 3 Capability public subpath
|
|
7
|
-
* `@principles/core/runtime/pain-recall-capability` — never the read
|
|
8
|
-
* model, never a CLI subprocess, never a second query implementation
|
|
9
|
-
* (§3.2). Core stays MCP-SDK-free (architecture guard test pins this).
|
|
10
|
-
*
|
|
11
|
-
* The single registered tool is the read-only `pd_recall_principle_pains`
|
|
12
|
-
* with an honest `readOnlyHint: true` (a host hint, not an OS boundary).
|
|
13
|
-
*/
|
|
14
1
|
import { McpServer, type StandardSchemaWithJSON } from '@modelcontextprotocol/server';
|
|
15
2
|
import { z } from 'zod';
|
|
16
3
|
import { type PainRecallCapabilityResult } from '@principles/core/runtime/pain-recall-capability';
|
|
4
|
+
import { type PainSubmitReceipt, type SubmittedTaskRecheck } from '@principles/core/runtime/pain-submit-capability';
|
|
17
5
|
import { OrphanLimiter, AdmissionLimiter } from './deadline.js';
|
|
6
|
+
import type { PdMcpHost } from './workspace.js';
|
|
18
7
|
export declare const TOOL_NAME: 'pd_recall_principle_pains';
|
|
19
8
|
export declare const TOOL_DESCRIPTION = "Recall a principle's verifiably-associated historical pain experience (availability-level disclosure only, OD-A v1). Read-only.";
|
|
20
9
|
/** §4.2 input contract: `principleId` (1..200, required) and `limit`
|
|
@@ -54,6 +43,77 @@ export declare const toolInputSchema: z.ZodObject<{
|
|
|
54
43
|
limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
55
44
|
}, z.core.$strict>;
|
|
56
45
|
export type ToolInput = z.infer<typeof toolInputSchema>;
|
|
46
|
+
export declare const SUBMIT_TOOL_NAME: 'pd_submit_pain';
|
|
47
|
+
/** §5.2 — the description is a behavioural instruction to the Agent, not
|
|
48
|
+
* marketing copy. It carries the anchor-first / Owner-consent-first flow and
|
|
49
|
+
* deliberately promises registration only, never that diagnosis will run. */
|
|
50
|
+
export declare const SUBMIT_TOOL_DESCRIPTION = "\u8BB0\u5F55\u4E00\u6761\"\u76F8\u5BF9\u951A\u70B9\u7684\u663E\u8457\u884C\u4E3A\u80CC\u79BB\"\uFF08Pain\uFF09\u3002\n\n\u8C03\u7528\u524D\u5FC5\u987B\u5B8C\u6210\u4E09\u4EF6\u4E8B\uFF1A\n1) \u5148\u786E\u5B9A\u951A\u70B9\uFF1AOwner \u7684\u660E\u786E\u671F\u671B\u3001\u5DF2\u5EFA\u7ACB\u7684\u539F\u5219\u3001\u6216 Agent Instructions/Skill \u7684\u660E\u786E\u8981\u6C42\u3002\n \u539F\u5219\u5FC5\u987B\u7ED9\u51FA id \u4E0E version\uFF1BInstructions \u5FC5\u987B\u7ED9\u51FA\u8DEF\u5F84\u4E0E\u7AE0\u8282\uFF1BOwner \u671F\u671B\u5FC5\u987B\u7ED9\u51FA\u5904\u3002\n2) \u5148\u5411 Owner \u8BF4\u660E\uFF1A\u2460\u951A\u70B9\u53CA\u51FA\u5904 \u2461\u4F60\u5B9E\u9645\u89C2\u5BDF\u5230\u7684\u5177\u4F53\u884C\u4E3A \u2462\u884C\u4E3A\u4E0E\u951A\u70B9\u4E4B\u95F4\u7684\u80CC\u79BB \u2463\u5FC5\u8981\u65F6\u8865\u5145\u4E3A\u4EC0\u4E48\u503C\u5F97\u5173\u6CE8\u6216\u53EF\u80FD\u7684\u5F71\u54CD\u3002\n3) \u53D6\u5F97 Owner \u5728\u672C\u6B21\u5BF9\u8BDD\u4E2D\u7684\u660E\u786E\u540C\u610F\u3002\u672A\u56DE\u590D\u3001\u56DE\u7B54\u4E0D\u660E\u786E\u3001\u6216\u53EA\u8BF4\u4E86\"\u968F\u4FBF\"\u90FD\u4E0D\u7B97\u6388\u6743\u3002\n \u6388\u6743\u53EA\u5BF9\u672C\u6B21\u63D0\u4EA4\u6709\u6548\uFF1BOwner \u4FEE\u6539\u4E86\u5185\u5BB9\u65F6\uFF0C\u63D0\u4EA4\u524D\u5FC5\u987B\u518D\u6B21\u786E\u8BA4\u6700\u7EC8\u7248\u672C\u3002\n \u540E\u53F0/\u65E0\u4EBA\u503C\u5B88 Agent \u4E0D\u5F97\u81EA\u884C\u63D0\u4EA4\u3002\n\n\u7B2C 2 \u6B65\u7684 \u2463 \u662F\u8F85\u52A9\u8BF4\u660E\uFF0C\u4E0D\u662F\u63D0\u4EA4\u6761\u4EF6\uFF1A\u4E0D\u8981\u6C42\u8BC1\u660E\u672A\u6765\u4EFB\u52A1\u4E00\u5B9A\u4F1A\u6539\u53D8\u5224\u65AD\u3001\n\u4E0D\u8981\u6C42\u8BC1\u660E\u4F1A\u91CD\u590D\u53D1\u751F\u3001\u4E0D\u8981\u6C42\u5DF2\u4EA7\u751F\u5B9E\u9645\u635F\u5931\u3001\u4E0D\u8981\u6C42\u8BC1\u660E\u957F\u671F\u590D\u7528\u4EF7\u503C\u3002\n\u65E0\u6CD5\u8BC1\u660E\u4E0A\u8FF0\u4EFB\u4F55\u4E00\u9879\uFF0C\u90FD\u4E0D\u5F97\u6210\u4E3A\u62D2\u7EDD\u8BB0\u5F55\u8FD9\u6761 Pain \u7684\u7406\u7531\u2014\u2014\u5B83\u4EEC\u53EA\u5E2E\u52A9 Owner\n\u5224\u65AD\u6CE8\u610F\u529B\u4F18\u5148\u7EA7\uFF0C\u4E0D\u5C5E\u4E8E Pain \u662F\u5426\u6210\u7ACB\u7684\u6761\u4EF6\uFF0C\u4E5F\u4E0D\u5C5E\u4E8E\u63D0\u4EA4\u95E8\u69DB\u3002\n\nPain \u662F\u5426\u6210\u7ACB\u53EA\u770B\u4E09\u9879\uFF1A\u660E\u786E\u951A\u70B9 + \u5177\u4F53\u884C\u4E3A + \u76F8\u5BF9\u951A\u70B9\u7684\u663E\u8457\u80CC\u79BB\u3002\n\n\u4E0D\u8981\u63D0\u4EA4\uFF1A\u5206\u6570\u3001\u4E25\u91CD\u5EA6\u3001\u4F18\u5148\u7EA7\u3001\u4F1A\u8BDD ID\u3001\u5BA1\u6279\u4EE4\u724C\u3001\u63A8\u6D4B\u7684 painType\u3001\n\u6216\u4EFB\u4F55\u4F60\u65E0\u6CD5\u7ED9\u51FA\u51FA\u5904\u7684\"\u951A\u70B9\"\u3002\n\n\u5982\u679C\u65E0\u6CD5\u786E\u5B9A\u951A\u70B9\u6216\u65E0\u6CD5\u8BF4\u660E\u5177\u4F53\u884C\u4E3A\uFF0C\u4E0D\u8981\u8C03\u7528\u672C\u5DE5\u5177\uFF1B\u5148\u5411 Owner \u6F84\u6E05\u3002";
|
|
51
|
+
/** §5.3 — JSON Schema first; every undeclared property (score, severity,
|
|
52
|
+
* approved, sessionId, paths, metadata) is rejected at the protocol stage. */
|
|
53
|
+
export declare const submitToolInputJsonSchema: {
|
|
54
|
+
readonly type: 'object';
|
|
55
|
+
readonly properties: {
|
|
56
|
+
readonly reason: {
|
|
57
|
+
readonly type: 'string';
|
|
58
|
+
readonly minLength: 1;
|
|
59
|
+
readonly maxLength: 2000;
|
|
60
|
+
readonly description: '按六项顺序组织:锚点、锚点来源与引用等级、观察到的行为、背离、为什么值得记录、上下文。';
|
|
61
|
+
};
|
|
62
|
+
readonly anchorType: {
|
|
63
|
+
readonly type: 'string';
|
|
64
|
+
readonly enum: readonly ['owner_expectation', 'established_principle', 'agent_instruction'];
|
|
65
|
+
readonly description: '锚点类型。无法归类时不要提交。';
|
|
66
|
+
};
|
|
67
|
+
readonly anchorRef: {
|
|
68
|
+
readonly type: 'string';
|
|
69
|
+
readonly minLength: 1;
|
|
70
|
+
readonly maxLength: 300;
|
|
71
|
+
readonly description: '原则:<id>@<version>;Instructions:<path>#<section>;Owner 期望:本次对话中的出处。';
|
|
72
|
+
};
|
|
73
|
+
readonly painType: {
|
|
74
|
+
readonly type: 'string';
|
|
75
|
+
readonly enum: readonly ['principle_deviation', 'tool_failure', 'subagent_error', 'user_frustration'];
|
|
76
|
+
readonly description: '可选。锚点式 Pain 默认是 principle_deviation;只有你能明确归类时才填写其他值,不要猜测。';
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
readonly required: readonly ['reason', 'anchorType', 'anchorRef'];
|
|
80
|
+
readonly additionalProperties: false;
|
|
81
|
+
};
|
|
82
|
+
export declare const submitToolProtocolSchema: StandardSchemaWithJSON<unknown, unknown>;
|
|
83
|
+
/** §5.3.2 — zod re-validation, kept in lockstep with the JSON Schema above. */
|
|
84
|
+
export declare const submitToolInputSchema: z.ZodObject<{
|
|
85
|
+
reason: z.ZodString;
|
|
86
|
+
anchorType: z.ZodEnum<{
|
|
87
|
+
agent_instruction: "agent_instruction";
|
|
88
|
+
established_principle: "established_principle";
|
|
89
|
+
owner_expectation: "owner_expectation";
|
|
90
|
+
}>;
|
|
91
|
+
anchorRef: z.ZodString;
|
|
92
|
+
painType: z.ZodOptional<z.ZodEnum<{
|
|
93
|
+
principle_deviation: "principle_deviation";
|
|
94
|
+
subagent_error: "subagent_error";
|
|
95
|
+
tool_failure: "tool_failure";
|
|
96
|
+
user_frustration: "user_frustration";
|
|
97
|
+
}>>;
|
|
98
|
+
}, z.core.$strict>;
|
|
99
|
+
export type SubmitToolInput = z.infer<typeof submitToolInputSchema>;
|
|
100
|
+
/** §5.7 — the bounded read-back after a write timeout (upper bound 1s). */
|
|
101
|
+
export declare const SUBMIT_RECHECK_DEADLINE_MS: 1000;
|
|
102
|
+
export declare function createMcpPainId(nowMs?: number, randomHex?: () => string): string;
|
|
103
|
+
/** The submit capability entry — injectable for adapter-contract tests;
|
|
104
|
+
* production always uses the real Core capability. */
|
|
105
|
+
export type SubmitCapabilityCall = (input: {
|
|
106
|
+
readonly workspaceDir: string;
|
|
107
|
+
readonly painId: string;
|
|
108
|
+
readonly taskId: string;
|
|
109
|
+
readonly submission: SubmitToolInput;
|
|
110
|
+
}) => Promise<PainSubmitReceipt>;
|
|
111
|
+
/** Bounded read-back entry — injectable for timeout tests. */
|
|
112
|
+
export type SubmitRecheckCall = (input: {
|
|
113
|
+
readonly workspaceDir: string;
|
|
114
|
+
readonly painId: string;
|
|
115
|
+
readonly taskId: string;
|
|
116
|
+
}) => Promise<SubmittedTaskRecheck>;
|
|
57
117
|
/** The capability entry the server calls — injectable for adapter-contract
|
|
58
118
|
* tests; production always uses the real Gate 3 Facade. */
|
|
59
119
|
export type CapabilityCall = (input: {
|
|
@@ -63,10 +123,19 @@ export type CapabilityCall = (input: {
|
|
|
63
123
|
}) => Promise<PainRecallCapabilityResult>;
|
|
64
124
|
export interface PdMcpServerOptions {
|
|
65
125
|
readonly workspaceDir: string;
|
|
66
|
-
readonly host?:
|
|
126
|
+
readonly host?: PdMcpHost | null;
|
|
67
127
|
readonly deadlineMs?: number;
|
|
68
128
|
readonly callCapability?: CapabilityCall;
|
|
69
129
|
readonly logSink?: (line: string) => void;
|
|
130
|
+
/** OG-4 gate (§5.1.1): registers the write tool ONLY when this is
|
|
131
|
+
* explicitly `true`. Default `false`; no env var or feature flag can change
|
|
132
|
+
* it. Production stays recall-only until OG-4 authorization exists. */
|
|
133
|
+
readonly enableSubmitTool?: boolean;
|
|
134
|
+
/** Submit capability entry (tests / future wiring). Defaults to the real
|
|
135
|
+
* Core capability bound to `<workspaceDir>/.state`. */
|
|
136
|
+
readonly callSubmitCapability?: SubmitCapabilityCall;
|
|
137
|
+
/** Bounded read-back entry used after a write timeout (§5.7). */
|
|
138
|
+
readonly recheckSubmitTask?: SubmitRecheckCall;
|
|
70
139
|
}
|
|
71
140
|
export interface PdMcpServerHandle {
|
|
72
141
|
readonly mcpServer: McpServer;
|
|
@@ -8,14 +8,19 @@
|
|
|
8
8
|
* model, never a CLI subprocess, never a second query implementation
|
|
9
9
|
* (§3.2). Core stays MCP-SDK-free (architecture guard test pins this).
|
|
10
10
|
*
|
|
11
|
-
* The single
|
|
12
|
-
*
|
|
11
|
+
* The single read tool is `pd_recall_principle_pains` (`readOnlyHint: true`).
|
|
12
|
+
* The write tool `pd_submit_pain` exists only when the caller explicitly sets
|
|
13
|
+
* `enableSubmitTool: true` — the OG-4 production governance gate
|
|
14
|
+
* (SPEC-PD-AGENT-PAIN-INGRESS-001 §5.1.1). No env var or feature flag can turn
|
|
15
|
+
* it on: a deployment must opt in in code and carry the OG-4 record.
|
|
13
16
|
*/
|
|
17
|
+
import { randomBytes } from 'node:crypto';
|
|
14
18
|
import { McpServer, fromJsonSchema } from '@modelcontextprotocol/server';
|
|
15
19
|
import { z } from 'zod';
|
|
16
20
|
import { recallPrinciplePainsCapability, } from '@principles/core/runtime/pain-recall-capability';
|
|
21
|
+
import { buildRefusedSubmitReceipt, buildUnconfirmedSubmitReceipt, buildReconciledSubmitReceipt, deriveSubmitTaskId, recheckSubmittedTask, } from '@principles/core/runtime/pain-submit-capability';
|
|
17
22
|
import { runWithDeadline, OrphanLimiter, AdmissionLimiter, DEFAULT_DEADLINE_MS } from './deadline.js';
|
|
18
|
-
import { assembleResult, adapterFailureEnvelope, textResult } from './envelope.js';
|
|
23
|
+
import { assembleResult, assembleSubmitResult, adapterFailureEnvelope, textResult, } from './envelope.js';
|
|
19
24
|
import { withinBudget } from './budget.js';
|
|
20
25
|
import { createLogger, sanitizeErrorKind, stderrSink } from './logging.js';
|
|
21
26
|
import { SERVER_NAME, SERVER_VERSION } from './version.js';
|
|
@@ -46,6 +51,81 @@ export const toolInputSchema = z.strictObject({
|
|
|
46
51
|
principleId: z.string().min(1).max(200),
|
|
47
52
|
limit: z.number().int().min(1).max(10).optional().default(3),
|
|
48
53
|
});
|
|
54
|
+
// ── pd_submit_pain — OG-4 gated write tool ─────────────────────────────────
|
|
55
|
+
export const SUBMIT_TOOL_NAME = 'pd_submit_pain';
|
|
56
|
+
/** §5.2 — the description is a behavioural instruction to the Agent, not
|
|
57
|
+
* marketing copy. It carries the anchor-first / Owner-consent-first flow and
|
|
58
|
+
* deliberately promises registration only, never that diagnosis will run. */
|
|
59
|
+
export const SUBMIT_TOOL_DESCRIPTION = `记录一条"相对锚点的显著行为背离"(Pain)。
|
|
60
|
+
|
|
61
|
+
调用前必须完成三件事:
|
|
62
|
+
1) 先确定锚点:Owner 的明确期望、已建立的原则、或 Agent Instructions/Skill 的明确要求。
|
|
63
|
+
原则必须给出 id 与 version;Instructions 必须给出路径与章节;Owner 期望必须给出处。
|
|
64
|
+
2) 先向 Owner 说明:①锚点及出处 ②你实际观察到的具体行为 ③行为与锚点之间的背离 ④必要时补充为什么值得关注或可能的影响。
|
|
65
|
+
3) 取得 Owner 在本次对话中的明确同意。未回复、回答不明确、或只说了"随便"都不算授权。
|
|
66
|
+
授权只对本次提交有效;Owner 修改了内容时,提交前必须再次确认最终版本。
|
|
67
|
+
后台/无人值守 Agent 不得自行提交。
|
|
68
|
+
|
|
69
|
+
第 2 步的 ④ 是辅助说明,不是提交条件:不要求证明未来任务一定会改变判断、
|
|
70
|
+
不要求证明会重复发生、不要求已产生实际损失、不要求证明长期复用价值。
|
|
71
|
+
无法证明上述任何一项,都不得成为拒绝记录这条 Pain 的理由——它们只帮助 Owner
|
|
72
|
+
判断注意力优先级,不属于 Pain 是否成立的条件,也不属于提交门槛。
|
|
73
|
+
|
|
74
|
+
Pain 是否成立只看三项:明确锚点 + 具体行为 + 相对锚点的显著背离。
|
|
75
|
+
|
|
76
|
+
不要提交:分数、严重度、优先级、会话 ID、审批令牌、推测的 painType、
|
|
77
|
+
或任何你无法给出出处的"锚点"。
|
|
78
|
+
|
|
79
|
+
如果无法确定锚点或无法说明具体行为,不要调用本工具;先向 Owner 澄清。`;
|
|
80
|
+
/** §5.3 — JSON Schema first; every undeclared property (score, severity,
|
|
81
|
+
* approved, sessionId, paths, metadata) is rejected at the protocol stage. */
|
|
82
|
+
export const submitToolInputJsonSchema = {
|
|
83
|
+
type: 'object',
|
|
84
|
+
properties: {
|
|
85
|
+
reason: {
|
|
86
|
+
type: 'string',
|
|
87
|
+
minLength: 1,
|
|
88
|
+
maxLength: 2000,
|
|
89
|
+
description: '按六项顺序组织:锚点、锚点来源与引用等级、观察到的行为、背离、为什么值得记录、上下文。',
|
|
90
|
+
},
|
|
91
|
+
anchorType: {
|
|
92
|
+
type: 'string',
|
|
93
|
+
enum: ['owner_expectation', 'established_principle', 'agent_instruction'],
|
|
94
|
+
description: '锚点类型。无法归类时不要提交。',
|
|
95
|
+
},
|
|
96
|
+
anchorRef: {
|
|
97
|
+
type: 'string',
|
|
98
|
+
minLength: 1,
|
|
99
|
+
maxLength: 300,
|
|
100
|
+
description: '原则:<id>@<version>;Instructions:<path>#<section>;Owner 期望:本次对话中的出处。',
|
|
101
|
+
},
|
|
102
|
+
painType: {
|
|
103
|
+
type: 'string',
|
|
104
|
+
enum: ['principle_deviation', 'tool_failure', 'subagent_error', 'user_frustration'],
|
|
105
|
+
description: '可选。锚点式 Pain 默认是 principle_deviation;只有你能明确归类时才填写其他值,不要猜测。',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
required: ['reason', 'anchorType', 'anchorRef'],
|
|
109
|
+
additionalProperties: false,
|
|
110
|
+
};
|
|
111
|
+
export const submitToolProtocolSchema = fromJsonSchema(submitToolInputJsonSchema);
|
|
112
|
+
/** §5.3.2 — zod re-validation, kept in lockstep with the JSON Schema above. */
|
|
113
|
+
export const submitToolInputSchema = z.strictObject({
|
|
114
|
+
reason: z.string().min(1).max(2000),
|
|
115
|
+
anchorType: z.enum(['owner_expectation', 'established_principle', 'agent_instruction']),
|
|
116
|
+
anchorRef: z.string().min(1).max(300),
|
|
117
|
+
painType: z.enum(['principle_deviation', 'tool_failure', 'subagent_error', 'user_frustration']).optional(),
|
|
118
|
+
});
|
|
119
|
+
/** §5.7 — the bounded read-back after a write timeout (upper bound 1s). */
|
|
120
|
+
export const SUBMIT_RECHECK_DEADLINE_MS = 1000;
|
|
121
|
+
/** Handler-generated identity, known BEFORE any write: `mcp_<epoch_ms>_<8-hex>`
|
|
122
|
+
* (§5.4.1). Never derived from a session, host or model input. */
|
|
123
|
+
function defaultRandomHex() {
|
|
124
|
+
return randomBytes(4).toString('hex');
|
|
125
|
+
}
|
|
126
|
+
export function createMcpPainId(nowMs = Date.now(), randomHex = defaultRandomHex) {
|
|
127
|
+
return `mcp_${nowMs}_${randomHex()}`;
|
|
128
|
+
}
|
|
49
129
|
/** §4.8 Adapter 执行失败 row (timeout / exception / saturated / shutting
|
|
50
130
|
* down) — one sanitized `tool_execution_failed` envelope, isError: true. */
|
|
51
131
|
function executionFailedResult(message) {
|
|
@@ -74,12 +154,34 @@ function resultTextBytes(result) {
|
|
|
74
154
|
* explicit isError mapping. Nothing here writes to stdout.
|
|
75
155
|
*/
|
|
76
156
|
export function createPdMcpServer(options) {
|
|
77
|
-
const { workspaceDir, host = null, deadlineMs = DEFAULT_DEADLINE_MS, callCapability = recallPrinciplePainsCapability, logSink = stderrSink, } = options;
|
|
157
|
+
const { workspaceDir, host = null, deadlineMs = DEFAULT_DEADLINE_MS, callCapability = recallPrinciplePainsCapability, logSink = stderrSink, enableSubmitTool = false, callSubmitCapability, recheckSubmitTask = recheckSubmittedTask, } = options;
|
|
158
|
+
const submitCall = callSubmitCapability;
|
|
159
|
+
if (enableSubmitTool === true && submitCall === undefined) {
|
|
160
|
+
// Fail closed instead of silently falling back to resolveRuntimeConfig(),
|
|
161
|
+
// the deprecated .state/workflows.yaml resolver (PRI-393 forbids it on
|
|
162
|
+
// production execution paths). The host wrapper that opts in must bind the
|
|
163
|
+
// real Core capability to an effective `.pd/config.yaml` config.
|
|
164
|
+
throw new Error('pd_submit_pain requires an injected callSubmitCapability bound to an effective PD config; ' +
|
|
165
|
+
'the MCP server must not resolve runtime config through the deprecated workflows.yaml path.');
|
|
166
|
+
}
|
|
78
167
|
const orphans = new OrphanLimiter();
|
|
79
168
|
const admissions = new AdmissionLimiter();
|
|
80
169
|
let shuttingDown = false;
|
|
81
170
|
const mcpServer = new McpServer({ name: SERVER_NAME, version: SERVER_VERSION });
|
|
82
171
|
const log = createLogger(logSink, { host: host ?? 'unspecified' });
|
|
172
|
+
/** One structured `tool_call` line for the submit path (§5.5 step 11). Only
|
|
173
|
+
* scalars: status, error code, byte size, degradation — never Pain text. */
|
|
174
|
+
function logSubmitCall(input) {
|
|
175
|
+
log(input.level ?? 'info', 'tool_call', {
|
|
176
|
+
toolName: SUBMIT_TOOL_NAME,
|
|
177
|
+
durationMs: Date.now() - input.startedAt,
|
|
178
|
+
status: input.status,
|
|
179
|
+
errorCode: input.errorCode,
|
|
180
|
+
responseBytes: resultTextBytes(input.result),
|
|
181
|
+
truncated: false,
|
|
182
|
+
...(input.degraded === undefined ? {} : { degraded: input.degraded }),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
83
185
|
mcpServer.registerTool(TOOL_NAME, {
|
|
84
186
|
description: TOOL_DESCRIPTION,
|
|
85
187
|
// Static type-interop shim ONLY: our zod 4.6.7 type instantiation does
|
|
@@ -218,6 +320,151 @@ export function createPdMcpServer(options) {
|
|
|
218
320
|
});
|
|
219
321
|
return timedOut;
|
|
220
322
|
});
|
|
323
|
+
// ── pd_submit_pain — registered ONLY behind the explicit OG-4 gate ────────
|
|
324
|
+
if (enableSubmitTool === true && submitCall !== undefined) {
|
|
325
|
+
mcpServer.registerTool(SUBMIT_TOOL_NAME, {
|
|
326
|
+
description: SUBMIT_TOOL_DESCRIPTION,
|
|
327
|
+
// Same static interop shim as the recall tool; runtime validation is
|
|
328
|
+
// the SDK's JSON-Schema pass plus the zod parse inside the handler.
|
|
329
|
+
inputSchema: submitToolProtocolSchema,
|
|
330
|
+
// §5.1 — the write capability must not inherit the read tool's hint.
|
|
331
|
+
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
332
|
+
}, async (rawInput) => {
|
|
333
|
+
const startedAt = Date.now();
|
|
334
|
+
if (shuttingDown) {
|
|
335
|
+
const refusedResult = shuttingDownResult();
|
|
336
|
+
logSubmitCall({
|
|
337
|
+
startedAt,
|
|
338
|
+
result: refusedResult,
|
|
339
|
+
status: 'unavailable',
|
|
340
|
+
errorCode: 'shutting_down',
|
|
341
|
+
level: 'warn',
|
|
342
|
+
});
|
|
343
|
+
return refusedResult;
|
|
344
|
+
}
|
|
345
|
+
if (!admissions.tryAcquire()) {
|
|
346
|
+
// Not attempted: no write was started, so the generic failure text is
|
|
347
|
+
// faithful here (unlike a timeout after the write began).
|
|
348
|
+
const saturated = executionFailedResult('The server is already executing the maximum number of concurrent calls; retry shortly.');
|
|
349
|
+
logSubmitCall({
|
|
350
|
+
startedAt,
|
|
351
|
+
result: saturated,
|
|
352
|
+
status: 'unavailable',
|
|
353
|
+
errorCode: 'saturated',
|
|
354
|
+
level: 'warn',
|
|
355
|
+
});
|
|
356
|
+
return saturated;
|
|
357
|
+
}
|
|
358
|
+
// §5.5 step 3 — zod re-validation. Synchronous and before any write.
|
|
359
|
+
let submission;
|
|
360
|
+
try {
|
|
361
|
+
submission = submitToolInputSchema.parse(rawInput);
|
|
362
|
+
}
|
|
363
|
+
catch {
|
|
364
|
+
admissions.release();
|
|
365
|
+
const receipt = buildRefusedSubmitReceipt({
|
|
366
|
+
painId: null,
|
|
367
|
+
taskId: null,
|
|
368
|
+
workspaceDir,
|
|
369
|
+
code: 'invalid_input',
|
|
370
|
+
message: 'The request violates the pd_submit_pain input contract (reason 1..2000, anchorType in enum, anchorRef 1..300, no extra fields). Nothing was written.',
|
|
371
|
+
nextAction: 'Fix the arguments and retry. If no anchor is available, do not submit — clarify with the Owner first.',
|
|
372
|
+
});
|
|
373
|
+
const assembled = assembleSubmitResult(receipt);
|
|
374
|
+
logSubmitCall({
|
|
375
|
+
startedAt,
|
|
376
|
+
result: assembled.result,
|
|
377
|
+
status: receipt.status,
|
|
378
|
+
errorCode: 'invalid_input',
|
|
379
|
+
degraded: assembled.degraded,
|
|
380
|
+
level: 'warn',
|
|
381
|
+
});
|
|
382
|
+
return assembled.result;
|
|
383
|
+
}
|
|
384
|
+
// §5.5 step 5 — identity exists BEFORE the write, so a timeout can be
|
|
385
|
+
// reconciled by id instead of guessing (§5.7).
|
|
386
|
+
const painId = createMcpPainId();
|
|
387
|
+
const taskId = deriveSubmitTaskId(painId);
|
|
388
|
+
const outcome = await runWithDeadline(async () => {
|
|
389
|
+
try {
|
|
390
|
+
const receipt = await submitCall({ workspaceDir, painId, taskId, submission });
|
|
391
|
+
return { kind: 'receipt', receipt };
|
|
392
|
+
}
|
|
393
|
+
catch (err) {
|
|
394
|
+
// The capability promises not to throw; if it does, the outcome
|
|
395
|
+
// after identity assignment is unknown, never "failed".
|
|
396
|
+
return { kind: 'exception', errorKind: sanitizeErrorKind(err) };
|
|
397
|
+
}
|
|
398
|
+
finally {
|
|
399
|
+
admissions.release();
|
|
400
|
+
}
|
|
401
|
+
}, deadlineMs, (orphaned) => orphans.register(orphaned));
|
|
402
|
+
if (outcome.ok) {
|
|
403
|
+
if (outcome.value.kind === 'receipt') {
|
|
404
|
+
const assembled = assembleSubmitResult(outcome.value.receipt);
|
|
405
|
+
logSubmitCall({
|
|
406
|
+
startedAt,
|
|
407
|
+
result: assembled.result,
|
|
408
|
+
status: outcome.value.receipt.status,
|
|
409
|
+
errorCode: outcome.value.receipt.error?.code ?? 'none',
|
|
410
|
+
degraded: assembled.degraded,
|
|
411
|
+
level: outcome.value.receipt.status === 'failed' ? 'error' : 'info',
|
|
412
|
+
});
|
|
413
|
+
return assembled.result;
|
|
414
|
+
}
|
|
415
|
+
const unconfirmed = buildUnconfirmedSubmitReceipt({
|
|
416
|
+
painId,
|
|
417
|
+
taskId,
|
|
418
|
+
workspaceDir,
|
|
419
|
+
message: 'The submission threw unexpectedly after the identity was assigned; the write outcome is unknown (it may already have been written).',
|
|
420
|
+
});
|
|
421
|
+
const assembled = assembleSubmitResult(unconfirmed);
|
|
422
|
+
logSubmitCall({
|
|
423
|
+
startedAt,
|
|
424
|
+
result: assembled.result,
|
|
425
|
+
status: unconfirmed.status,
|
|
426
|
+
errorCode: `unexpected_${outcome.value.errorKind}`,
|
|
427
|
+
degraded: assembled.degraded,
|
|
428
|
+
level: 'error',
|
|
429
|
+
});
|
|
430
|
+
return assembled.result;
|
|
431
|
+
}
|
|
432
|
+
// §5.7 — write deadline exceeded. One bounded read-back, then report.
|
|
433
|
+
// Never a plain failure, never an automatic resubmission.
|
|
434
|
+
const recheck = await runWithDeadline(() => recheckSubmitTask({ workspaceDir, painId, taskId }), SUBMIT_RECHECK_DEADLINE_MS);
|
|
435
|
+
if (recheck.ok && recheck.value === 'found') {
|
|
436
|
+
const reconciled = buildReconciledSubmitReceipt({ painId, taskId, workspaceDir });
|
|
437
|
+
const assembled = assembleSubmitResult(reconciled);
|
|
438
|
+
logSubmitCall({
|
|
439
|
+
startedAt,
|
|
440
|
+
result: assembled.result,
|
|
441
|
+
status: reconciled.status,
|
|
442
|
+
errorCode: 'deadline_exceeded_reconciled',
|
|
443
|
+
degraded: assembled.degraded,
|
|
444
|
+
level: 'warn',
|
|
445
|
+
});
|
|
446
|
+
return assembled.result;
|
|
447
|
+
}
|
|
448
|
+
const unconfirmed = buildUnconfirmedSubmitReceipt({
|
|
449
|
+
painId,
|
|
450
|
+
taskId,
|
|
451
|
+
workspaceDir,
|
|
452
|
+
message: recheck.ok && recheck.value === 'not_found'
|
|
453
|
+
? `The submission exceeded the ${deadlineMs} ms deadline and the bounded read-back did not find task '${taskId}'. It may still be written; do not resubmit blindly.`
|
|
454
|
+
: `The submission exceeded the ${deadlineMs} ms deadline and the bounded read-back could not determine whether task '${taskId}' was written.`,
|
|
455
|
+
});
|
|
456
|
+
const assembled = assembleSubmitResult(unconfirmed);
|
|
457
|
+
logSubmitCall({
|
|
458
|
+
startedAt,
|
|
459
|
+
result: assembled.result,
|
|
460
|
+
status: unconfirmed.status,
|
|
461
|
+
errorCode: 'deadline_exceeded_unconfirmed',
|
|
462
|
+
degraded: assembled.degraded,
|
|
463
|
+
level: 'warn',
|
|
464
|
+
});
|
|
465
|
+
return assembled.result;
|
|
466
|
+
});
|
|
467
|
+
}
|
|
221
468
|
return {
|
|
222
469
|
mcpServer,
|
|
223
470
|
orphans,
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* package.json. A unit test pins it to package.json so the two cannot drift.
|
|
8
8
|
*/
|
|
9
9
|
export declare const SERVER_NAME: 'pd-mcp-server';
|
|
10
|
-
export declare const SERVER_VERSION: '0.
|
|
10
|
+
export declare const SERVER_VERSION: '0.4.0';
|
|
11
11
|
/** The only MCP SDK family/version this server is released against
|
|
12
12
|
* (Gate 4-A freeze, PD_MCP_GATE4A_REALITY_CHECK §3). Exact pin — no ranges. */
|
|
13
13
|
export declare const MCP_SDK_PIN: '@modelcontextprotocol/server@2.4.0';
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* package.json. A unit test pins it to package.json so the two cannot drift.
|
|
8
8
|
*/
|
|
9
9
|
export const SERVER_NAME = 'pd-mcp-server';
|
|
10
|
-
export const SERVER_VERSION = '0.
|
|
10
|
+
export const SERVER_VERSION = '0.4.0';
|
|
11
11
|
/** The only MCP SDK family/version this server is released against
|
|
12
12
|
* (Gate 4-A freeze, PD_MCP_GATE4A_REALITY_CHECK §3). Exact pin — no ranges. */
|
|
13
13
|
export const MCP_SDK_PIN = '@modelcontextprotocol/server@2.4.0';
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export declare const WORKSPACE_DIR_ENV: 'PD_MCP_WORKSPACE_DIR';
|
|
2
2
|
export declare const HOST_ENV: 'PD_MCP_HOST';
|
|
3
|
-
export
|
|
3
|
+
export type PdMcpHost = 'codex' | 'openclaw' | 'workbuddy';
|
|
4
|
+
export declare const KNOWN_HOSTS: readonly PdMcpHost[];
|
|
5
|
+
export declare function isKnownHost(value: unknown): value is PdMcpHost;
|
|
4
6
|
export interface WorkspaceBinding {
|
|
5
7
|
readonly workspaceDir: string;
|
|
6
|
-
readonly host:
|
|
8
|
+
readonly host: PdMcpHost | null;
|
|
7
9
|
}
|
|
8
10
|
export type WorkspaceBindingFailureCode = 'workspace_env_missing' | 'workspace_not_absolute' | 'workspace_unreadable' | 'workspace_not_directory' | 'host_invalid';
|
|
9
11
|
export type WorkspaceBindingResolution = {
|
|
@@ -18,6 +18,9 @@ import * as path from 'path';
|
|
|
18
18
|
export const WORKSPACE_DIR_ENV = 'PD_MCP_WORKSPACE_DIR';
|
|
19
19
|
export const HOST_ENV = 'PD_MCP_HOST';
|
|
20
20
|
export const KNOWN_HOSTS = ['codex', 'openclaw', 'workbuddy'];
|
|
21
|
+
export function isKnownHost(value) {
|
|
22
|
+
return typeof value === 'string' && KNOWN_HOSTS.includes(value);
|
|
23
|
+
}
|
|
21
24
|
/**
|
|
22
25
|
* Resolve and validate the launch-time workspace binding from a process env
|
|
23
26
|
* (injected for testability; production passes `process.env`). Checks, in
|
|
@@ -68,7 +71,7 @@ export function resolveWorkspaceBinding(env) {
|
|
|
68
71
|
}
|
|
69
72
|
const host = env[HOST_ENV];
|
|
70
73
|
if (host !== undefined) {
|
|
71
|
-
if (
|
|
74
|
+
if (!isKnownHost(host)) {
|
|
72
75
|
return {
|
|
73
76
|
ok: false,
|
|
74
77
|
reason: 'host marker is not one of the known PD hosts',
|
|
@@ -78,5 +81,5 @@ export function resolveWorkspaceBinding(env) {
|
|
|
78
81
|
};
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
|
-
return { ok: true, binding: { workspaceDir: path.resolve(raw), host:
|
|
84
|
+
return { ok: true, binding: { workspaceDir: path.resolve(raw), host: isKnownHost(host) ? host : null } };
|
|
82
85
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/pd-mcp-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Principles Disciple MCP Server — the single shared MCP server implementation for the three PD hosts (Codex, OpenClaw, WorkBuddy). Read-only pain recall through the Gate 3 Capability (SPEC-PD-MCP-GATE4-001).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|