@principles/host-runtime 0.10.1 → 0.10.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.
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** The exact prefix (fullwidth colon) defined by SPEC §6.4. */
|
|
2
|
+
export declare const OWNER_STATEMENT_PREFIX = "PD\u8BB0\u5F55\u75DB\u82E6\uFF1A";
|
|
3
|
+
/** SPEC §6.1: reject instead of truncating the Owner's intent. */
|
|
4
|
+
export declare const MAX_OWNER_STATEMENT_CHARS = 500;
|
|
5
|
+
export type OwnerStatementPrefixParse = {
|
|
6
|
+
matched: false;
|
|
7
|
+
} | {
|
|
8
|
+
matched: true;
|
|
9
|
+
text: string | null;
|
|
10
|
+
reason?: 'statement_empty' | 'statement_too_long';
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Deterministic prefix parse of the CURRENT user prompt. `text === null` means
|
|
14
|
+
* the prefix matched but the remainder was empty/blank — an explicit request
|
|
15
|
+
* with no content is a bounded rejection, never a fabricated statement.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseOwnerStatementPrefix(prompt: unknown): OwnerStatementPrefixParse;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** The exact prefix (fullwidth colon) defined by SPEC §6.4. */
|
|
2
|
+
export const OWNER_STATEMENT_PREFIX = 'PD记录痛苦:';
|
|
3
|
+
/** SPEC §6.1: reject instead of truncating the Owner's intent. */
|
|
4
|
+
export const MAX_OWNER_STATEMENT_CHARS = 500;
|
|
5
|
+
/**
|
|
6
|
+
* Deterministic prefix parse of the CURRENT user prompt. `text === null` means
|
|
7
|
+
* the prefix matched but the remainder was empty/blank — an explicit request
|
|
8
|
+
* with no content is a bounded rejection, never a fabricated statement.
|
|
9
|
+
*/
|
|
10
|
+
export function parseOwnerStatementPrefix(prompt) {
|
|
11
|
+
if (typeof prompt !== 'string')
|
|
12
|
+
return { matched: false };
|
|
13
|
+
if (!prompt.startsWith(OWNER_STATEMENT_PREFIX))
|
|
14
|
+
return { matched: false };
|
|
15
|
+
const remainder = prompt.slice(OWNER_STATEMENT_PREFIX.length).trim();
|
|
16
|
+
if (remainder.length === 0)
|
|
17
|
+
return { matched: true, text: null, reason: 'statement_empty' };
|
|
18
|
+
if (remainder.length > MAX_OWNER_STATEMENT_CHARS)
|
|
19
|
+
return { matched: true, text: null, reason: 'statement_too_long' };
|
|
20
|
+
return { matched: true, text: remainder };
|
|
21
|
+
}
|
|
@@ -63,7 +63,7 @@ export declare function evaluateCorrectionSignal(input: {
|
|
|
63
63
|
export type GovernanceSignalKind = 'user_correction' | 'tool_failure';
|
|
64
64
|
export interface GovernanceCorrectionCandidate {
|
|
65
65
|
readonly kind: 'user_correction';
|
|
66
|
-
readonly hostKind: 'codex';
|
|
66
|
+
readonly hostKind: 'codex' | 'workbuddy';
|
|
67
67
|
readonly logicalObservationKey: string;
|
|
68
68
|
readonly rolloutIdentity: string;
|
|
69
69
|
readonly rootSessionId: string;
|
|
@@ -72,7 +72,7 @@ export interface GovernanceCorrectionCandidate {
|
|
|
72
72
|
readonly observedAt: string;
|
|
73
73
|
/**
|
|
74
74
|
* SPEC-CODEX-PAIN-CLOSURE-001 CR-02/CR-07: the text is an EXPLICIT Owner
|
|
75
|
-
* statement (
|
|
75
|
+
* statement (native current-user `PD记录痛苦:` prefix). Explicit submissions bypass the
|
|
76
76
|
* STRONG+high-precision keyword gate — the Owner's explicit request is the
|
|
77
77
|
* signal; nothing is inferred. Rate limiting and the unique observation-key
|
|
78
78
|
* dedup still apply unchanged.
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
import fs from 'node:fs';
|
|
35
35
|
import path from 'node:path';
|
|
36
36
|
import Database from 'better-sqlite3';
|
|
37
|
-
import { collectSync, CORRECTION_SEED_KEYWORDS, buildToolFailureObservation, evaluateTriage, evaluateTriggerController, resolveSourceKind, PainToPrincipleService, PrincipleTreeLedgerAdapter, RuntimeStateManager, createDiagnosticianTaskId, disposePainSignalBridgesForWorkspace, sanitizeString, MAX_EVIDENCE_VALUE_CHARS, } from '@principles/core/runtime-v2';
|
|
37
|
+
import { collectSync, CORRECTION_SEED_KEYWORDS, buildToolFailureObservation, evaluateTriage, evaluateTriggerController, resolveSourceKind, PainToPrincipleService, PrincipleTreeLedgerAdapter, RuntimeStateManager, createDiagnosticianTaskId, disposePainSignalBridgesForWorkspace, sanitizeString, boundCorrectionEvidenceText, MAX_EVIDENCE_VALUE_CHARS, } from '@principles/core/runtime-v2';
|
|
38
38
|
import { deriveProductionCorrectionPainIdentity, deriveProductionToolPainIdentity, hasProductionPainSchema, PRODUCTION_WRITE_TOOLS, } from './production-pain-evidence.js';
|
|
39
39
|
import { promoteGovernanceEvidence, ensureGovernanceSchema } from './governance-observation-store.js';
|
|
40
40
|
import { loadPdConfigForPlugin } from './pd-config.js';
|
|
@@ -385,7 +385,7 @@ function tryConsumeRateLimit({ db, rootSessionId, ruleVersion, now }) {
|
|
|
385
385
|
}
|
|
386
386
|
function insertCorrectionPain({ db, candidate, workspaceDir, painId, detection, nowIso }) {
|
|
387
387
|
const reason = candidate.explicitOwnerStatement === true
|
|
388
|
-
? 'Codex explicit owner statement (PD记录痛苦 prefix)
|
|
388
|
+
? `${candidate.hostKind === 'workbuddy' ? 'WorkBuddy' : 'Codex'} explicit owner statement (PD记录痛苦 prefix)`
|
|
389
389
|
: detection !== undefined && detection.matchedTerms.length > 0
|
|
390
390
|
? `User correction detected: ${detection.matchedTerms.join(', ')}`
|
|
391
391
|
: 'User correction detected';
|
|
@@ -433,13 +433,19 @@ function taskSubmissionPayload(candidate, workspaceDir, reason) {
|
|
|
433
433
|
reason: reason || 'User correction detected',
|
|
434
434
|
score: GOVERNANCE_STRONG_PAIN_SCORE,
|
|
435
435
|
sessionId: candidate.rootSessionId,
|
|
436
|
-
hostKind:
|
|
437
|
-
|
|
436
|
+
hostKind: candidate.hostKind,
|
|
437
|
+
// WorkBuddy explicit intake has no transcript observation to promote.
|
|
438
|
+
// The classified Owner statement is its input basis, not a pseudo-trace.
|
|
439
|
+
evidence: candidate.hostKind === 'workbuddy' && candidate.explicitOwnerStatement === true
|
|
440
|
+
? []
|
|
441
|
+
: [{ sourceRef: `governance_observation:${candidate.logicalObservationKey}`, note: sanitizeString(candidate.text, workspaceDir) }],
|
|
438
442
|
// SPEC-CODEX-PAIN-CLOSURE-001 CR-02 (merged from main): an explicit
|
|
439
443
|
// Owner statement rides as classified correction evidence — never
|
|
440
444
|
// summarized by an AI, never inside evidence[] pseudo-trace entries.
|
|
441
445
|
...(candidate.explicitOwnerStatement === true
|
|
442
|
-
? { correctionEvidence:
|
|
446
|
+
? { correctionEvidence: candidate.hostKind === 'workbuddy'
|
|
447
|
+
? { text: boundCorrectionEvidenceText({ text: candidate.text, classification: 'owner_statement', channel: 'workbuddy_explicit_prefix' }, workspaceDir).text, classification: 'owner_statement', channel: 'workbuddy_explicit_prefix' }
|
|
448
|
+
: { text: sanitizeString(candidate.text, workspaceDir), classification: 'owner_statement', channel: 'codex_explicit_prefix' } }
|
|
443
449
|
: {}),
|
|
444
450
|
};
|
|
445
451
|
return JSON.stringify(payload);
|
|
@@ -632,8 +638,8 @@ function admitToolFailure({ db, candidate, workspaceDir, nowIso }) {
|
|
|
632
638
|
return { disposition: 'admitted', kind: 'tool_failure', logicalObservationKey: candidate.logicalObservationKey, canonicalPainId: painId, duplicate, ruleVersion: null };
|
|
633
639
|
}
|
|
634
640
|
function admitOne({ db, candidate, workspaceDir, now, nowIso, keywordStore, onDegradation }) {
|
|
635
|
-
if (candidate.hostKind !== 'codex') {
|
|
636
|
-
return { ok: false, reason: 'unsupported_host_kind', nextAction: 'governance signal admission
|
|
641
|
+
if (candidate.hostKind !== 'codex' && !(candidate.hostKind === 'workbuddy' && candidate.kind === 'user_correction' && candidate.explicitOwnerStatement === true)) {
|
|
642
|
+
return { ok: false, reason: 'unsupported_host_kind', nextAction: 'governance signal admission accepts Codex observations or explicit WorkBuddy Owner statements' };
|
|
637
643
|
}
|
|
638
644
|
const marker = db.prepare('SELECT * FROM governance_signal_admissions WHERE logical_observation_key = ?').get(candidate.logicalObservationKey);
|
|
639
645
|
if (isRecord(marker)) {
|
|
@@ -710,7 +716,8 @@ function isGovernanceTaskPayload(value) {
|
|
|
710
716
|
const correctionEvidence = own(value, 'correctionEvidence');
|
|
711
717
|
const hasOwnerStatement = isRecord(correctionEvidence)
|
|
712
718
|
&& own(correctionEvidence, 'classification') === 'owner_statement'
|
|
713
|
-
&& own(correctionEvidence, 'channel') === 'codex_explicit_prefix'
|
|
719
|
+
&& (own(correctionEvidence, 'channel') === 'codex_explicit_prefix' && hostKind === 'codex'
|
|
720
|
+
|| own(correctionEvidence, 'channel') === 'workbuddy_explicit_prefix' && hostKind === 'workbuddy')
|
|
714
721
|
&& typeof own(correctionEvidence, 'text') === 'string'
|
|
715
722
|
&& own(correctionEvidence, 'text').length > 0;
|
|
716
723
|
if (correctionEvidence !== undefined && !hasOwnerStatement)
|
package/dist/index.d.ts
CHANGED
|
@@ -88,3 +88,4 @@ export declare function createProductionHostRuntime(options?: Partial<Pick<HostR
|
|
|
88
88
|
export * from './behavior-example-pack-assembler.js';
|
|
89
89
|
export * from './behavior-history.js';
|
|
90
90
|
export * from './workspace-behavior-evidence.js';
|
|
91
|
+
export * from './explicit-owner-statement-prefix.js';
|
package/dist/index.js
CHANGED
|
@@ -268,3 +268,4 @@ export function createProductionHostRuntime(options = {}) {
|
|
|
268
268
|
export * from './behavior-example-pack-assembler.js';
|
|
269
269
|
export * from './behavior-history.js';
|
|
270
270
|
export * from './workspace-behavior-evidence.js';
|
|
271
|
+
export * from './explicit-owner-statement-prefix.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principles/host-runtime",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "Shared host-neutral orchestration for Principles Disciple MVP-Core hook paths.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"lint": "eslint \"src/**/*.ts\""
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@principles/core": "^1.293.
|
|
34
|
+
"@principles/core": "^1.293.4",
|
|
35
35
|
"@principles/install-layout": "^0.4.0",
|
|
36
36
|
"better-sqlite3": "^13.0.3",
|
|
37
37
|
"js-yaml": "^5.4.3"
|