@principles/host-runtime 4.10.0 → 4.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-pain-authorization.js +6 -1
- package/dist/conversation-ingestion/consent.d.ts +33 -7
- package/dist/conversation-ingestion/consent.js +240 -42
- package/dist/conversation-ingestion/disclosure.d.ts +21 -0
- package/dist/conversation-ingestion/disclosure.js +74 -0
- package/dist/conversation-ingestion/index.d.ts +1 -0
- package/dist/conversation-ingestion/index.js +1 -0
- package/dist/forward-observation.d.ts +29 -0
- package/dist/forward-observation.js +279 -0
- package/dist/governance-signal-admission.d.ts +6 -1
- package/dist/governance-signal-admission.js +77 -11
- package/dist/idle-turn-audit.d.ts +155 -0
- package/dist/idle-turn-audit.js +786 -0
- package/dist/idle-turn-auditor.d.ts +20 -0
- package/dist/idle-turn-auditor.js +249 -0
- package/dist/index.d.ts +11 -5
- package/dist/index.js +38 -8
- package/dist/pain-inbox.d.ts +137 -0
- package/dist/pain-inbox.js +1020 -0
- package/dist/production-pain-evidence.d.ts +2 -2
- package/dist/production-pain-evidence.js +301 -55
- package/dist/signal-stage2-cycle.d.ts +2 -0
- package/dist/signal-stage2-cycle.js +30 -1
- package/dist/source-revocation-sweep.js +38 -0
- package/dist/stage2-context-hydrator.d.ts +46 -0
- package/dist/stage2-context-hydrator.js +221 -0
- package/dist/trajectory-stall-detector.d.ts +124 -0
- package/dist/trajectory-stall-detector.js +583 -0
- package/package.json +3 -3
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* own `.pd/config.yaml`, so it is per-Workspace and Owner-authored — a
|
|
21
21
|
* global install cannot grant it.
|
|
22
22
|
*/
|
|
23
|
+
import fs from 'node:fs';
|
|
23
24
|
import { loadFeatureFlagFromConfig } from './pd-config.js';
|
|
24
25
|
export const AUTO_PAIN_SUBMISSION_FLAG = 'automatic_pain_submission';
|
|
25
26
|
/**
|
|
@@ -28,5 +29,9 @@ export const AUTO_PAIN_SUBMISSION_FLAG = 'automatic_pain_submission';
|
|
|
28
29
|
* resolves false.
|
|
29
30
|
*/
|
|
30
31
|
export function isAutomaticPainSubmissionAuthorized(workspaceDir) {
|
|
31
|
-
|
|
32
|
+
// Fail-closed when the workspace directory itself does not exist.
|
|
33
|
+
if (!fs.existsSync(workspaceDir))
|
|
34
|
+
return false;
|
|
35
|
+
const loaded = loadFeatureFlagFromConfig(workspaceDir, AUTO_PAIN_SUBMISSION_FLAG);
|
|
36
|
+
return loaded.enabled;
|
|
32
37
|
}
|
|
@@ -60,7 +60,7 @@ export type ConversationConsentHostKind = 'codex' | 'workbuddy' | 'openclaw';
|
|
|
60
60
|
* that makes every observed flag/consent combination interpretable.
|
|
61
61
|
*/
|
|
62
62
|
export type ConversationIngestionConsentDecision = 'pending' | 'granted' | 'revoked' | 'failed';
|
|
63
|
-
export type ConversationIngestionConsentDecidedVia = 'pd_codex_setup' | 'codex_plugin_setup' | 'owner_directive';
|
|
63
|
+
export type ConversationIngestionConsentDecidedVia = 'pd_codex_setup' | 'codex_plugin_setup' | 'pd_workbuddy_setup' | 'pd_console' | 'owner_directive';
|
|
64
64
|
export interface ConversationIngestionConsentRecord {
|
|
65
65
|
decision: ConversationIngestionConsentDecision;
|
|
66
66
|
disclosureVersion: string;
|
|
@@ -91,6 +91,16 @@ export type ConversationIngestionConsentWrite = {
|
|
|
91
91
|
reason: string;
|
|
92
92
|
nextAction: string;
|
|
93
93
|
};
|
|
94
|
+
export type GrantConsentIfAbsentOutcome = 'granted' | 'already_granted' | 'preserved_revoked' | 'preserved_existing';
|
|
95
|
+
export type GrantConsentIfAbsentResult = {
|
|
96
|
+
ok: true;
|
|
97
|
+
outcome: GrantConsentIfAbsentOutcome;
|
|
98
|
+
record: ConversationIngestionConsentRecord;
|
|
99
|
+
} | {
|
|
100
|
+
ok: false;
|
|
101
|
+
reason: string;
|
|
102
|
+
nextAction: string;
|
|
103
|
+
};
|
|
94
104
|
/** Health-surface consent state (no captured text, ever). */
|
|
95
105
|
export type ConversationIngestionConsentState = 'granted' | 'revoked' | 'pending' | 'failed' | 'not_present' | 'flag_on_without_grant';
|
|
96
106
|
export declare function getConversationIngestionConsentPath(workspaceDir: string): string;
|
|
@@ -100,12 +110,6 @@ export declare function getConversationIngestionConsentPath(workspaceDir: string
|
|
|
100
110
|
* migration. ENOENT on both is the normal never-asked case.
|
|
101
111
|
*/
|
|
102
112
|
export declare function readConversationIngestionConsent(workspaceDir: string, hostKind: ConversationConsentHostKind): ConversationIngestionConsentRead;
|
|
103
|
-
/**
|
|
104
|
-
* Record an explicit consent decision for one host (the setup flow presents
|
|
105
|
-
* the frozen disclosure before calling this; an owner_directive record cites
|
|
106
|
-
* its evidenceRef). Other hosts' slots are preserved; the flags themselves are
|
|
107
|
-
* intentionally untouched.
|
|
108
|
-
*/
|
|
109
113
|
export declare function recordConversationIngestionConsent(workspaceDir: string, hostKind: ConversationConsentHostKind, input: {
|
|
110
114
|
decision: ConversationIngestionConsentDecision;
|
|
111
115
|
decidedVia: ConversationIngestionConsentDecidedVia;
|
|
@@ -114,6 +118,28 @@ export declare function recordConversationIngestionConsent(workspaceDir: string,
|
|
|
114
118
|
disclosureVersion?: string;
|
|
115
119
|
evidenceRef?: string;
|
|
116
120
|
}): ConversationIngestionConsentWrite;
|
|
121
|
+
/**
|
|
122
|
+
* Atomic conditional consent grant (SPEC-PD-PAIN-DETECTION-UPGRADE-001 W1/W2).
|
|
123
|
+
*
|
|
124
|
+
* Uses the EXACT SAME exclusive lock as `recordConversationIngestionConsent`.
|
|
125
|
+
* Permits ONLY the `not_present → granted` transition:
|
|
126
|
+
* - If the host already has `decision === 'revoked'`, refuses to overwrite and
|
|
127
|
+
* returns `{ ok: true, outcome: 'preserved_revoked', record }`.
|
|
128
|
+
* - If already `granted`, returns `{ ok: true, outcome: 'already_granted', record }`.
|
|
129
|
+
* - If `pending` or `failed`, preserves the existing state and returns
|
|
130
|
+
* `{ ok: true, outcome: 'preserved_existing', record }`.
|
|
131
|
+
* - Preserves all sibling host slots.
|
|
132
|
+
*
|
|
133
|
+
* NOTE (W1): Installers must NOT call this autonomously to fabricate Owner
|
|
134
|
+
* consent; it is only called when an explicit Owner confirmation or verified
|
|
135
|
+
* Owner directive is being recorded without risking a revoke race.
|
|
136
|
+
*/
|
|
137
|
+
export declare function grantConsentIfAbsent(workspaceDir: string, hostKind: ConversationConsentHostKind, input: {
|
|
138
|
+
decidedVia: ConversationIngestionConsentDecidedVia;
|
|
139
|
+
disclosureVersion: string;
|
|
140
|
+
decidedAt?: string;
|
|
141
|
+
evidenceRef?: string;
|
|
142
|
+
}): GrantConsentIfAbsentResult;
|
|
117
143
|
/**
|
|
118
144
|
* Combine the consent record with the ingestion flag into the health-surface
|
|
119
145
|
* state. Every flag×record combination maps to exactly one interpretable
|
|
@@ -56,7 +56,7 @@ function isDecision(value) {
|
|
|
56
56
|
return value === 'granted' || value === 'pending' || value === 'revoked' || value === 'failed';
|
|
57
57
|
}
|
|
58
58
|
function isDecidedVia(value) {
|
|
59
|
-
return value === 'pd_codex_setup' || value === 'codex_plugin_setup' || value === 'owner_directive';
|
|
59
|
+
return value === 'pd_codex_setup' || value === 'codex_plugin_setup' || value === 'pd_workbuddy_setup' || value === 'pd_console' || value === 'owner_directive';
|
|
60
60
|
}
|
|
61
61
|
function isHostKind(value) {
|
|
62
62
|
return value === 'codex' || value === 'workbuddy' || value === 'openclaw';
|
|
@@ -413,7 +413,97 @@ export function readConversationIngestionConsent(workspaceDir, hostKind) {
|
|
|
413
413
|
* its evidenceRef). Other hosts' slots are preserved; the flags themselves are
|
|
414
414
|
* intentionally untouched.
|
|
415
415
|
*/
|
|
416
|
+
const CONSENT_LOCK_STALE_MS = 30_000;
|
|
417
|
+
const CONSENT_LOCK_RETRY_MS = 15;
|
|
418
|
+
const CONSENT_LOCK_MAX_WAIT_MS = 2_000;
|
|
419
|
+
const SLEEP_BUFFER = new Int32Array(new SharedArrayBuffer(4));
|
|
420
|
+
function sleepSync(ms) {
|
|
421
|
+
Atomics.wait(SLEEP_BUFFER, 0, 0, ms);
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Shared exclusive file lock protecting ALL consent-ledger writes
|
|
425
|
+
* (`recordConversationIngestionConsent` and `grantConsentIfAbsent`, W2).
|
|
426
|
+
* Serializes concurrent grant/revoke mutations across processes so sibling
|
|
427
|
+
* host slots and revocation decisions cannot race or clobber each other.
|
|
428
|
+
*/
|
|
429
|
+
function withConsentLedgerLock(filePath, fn) {
|
|
430
|
+
const dir = path.dirname(filePath);
|
|
431
|
+
const lockPath = `${filePath}.lock`;
|
|
432
|
+
try {
|
|
433
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
434
|
+
}
|
|
435
|
+
catch (error) {
|
|
436
|
+
const code = typeof error === 'object' && error !== null && Object.hasOwn(error, 'code')
|
|
437
|
+
? String(error.code)
|
|
438
|
+
: String(error);
|
|
439
|
+
return {
|
|
440
|
+
ok: false,
|
|
441
|
+
reason: `conversation_ingestion_consent_write_failed: ${code.slice(0, 120)}`,
|
|
442
|
+
nextAction: `Check permissions on ${dir}`,
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
const deadline = Date.now() + CONSENT_LOCK_MAX_WAIT_MS;
|
|
446
|
+
let fd = null;
|
|
447
|
+
while (fd === null) {
|
|
448
|
+
try {
|
|
449
|
+
fd = fs.openSync(lockPath, 'wx', 0o600);
|
|
450
|
+
fs.writeSync(fd, JSON.stringify({ pid: process.pid, acquiredAt: new Date().toISOString() }));
|
|
451
|
+
}
|
|
452
|
+
catch (error) {
|
|
453
|
+
const code = typeof error === 'object' && error !== null && Object.hasOwn(error, 'code')
|
|
454
|
+
? String(error.code)
|
|
455
|
+
: String(error);
|
|
456
|
+
if (code !== 'EEXIST') {
|
|
457
|
+
return {
|
|
458
|
+
ok: false,
|
|
459
|
+
reason: `conversation_ingestion_consent_write_failed: ${code.slice(0, 120)}`,
|
|
460
|
+
nextAction: `Check permissions on ${lockPath}`,
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
// Reclaim genuinely stale lock files left by crashed processes.
|
|
464
|
+
try {
|
|
465
|
+
const stat = fs.statSync(lockPath);
|
|
466
|
+
if (Date.now() - stat.mtimeMs > CONSENT_LOCK_STALE_MS) {
|
|
467
|
+
fs.unlinkSync(lockPath);
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
catch {
|
|
472
|
+
// Lock disappeared concurrently; retry immediately.
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
if (Date.now() >= deadline) {
|
|
476
|
+
return {
|
|
477
|
+
ok: false,
|
|
478
|
+
reason: 'conversation_ingestion_consent_lock_timeout: concurrent writer held the consent ledger lock',
|
|
479
|
+
nextAction: `Retry the operation or inspect stale lock file ${lockPath}.`,
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
sleepSync(CONSENT_LOCK_RETRY_MS);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
try {
|
|
486
|
+
return { ok: true, value: fn() };
|
|
487
|
+
}
|
|
488
|
+
finally {
|
|
489
|
+
try {
|
|
490
|
+
fs.closeSync(fd);
|
|
491
|
+
}
|
|
492
|
+
catch { /* ignore */ }
|
|
493
|
+
try {
|
|
494
|
+
fs.unlinkSync(lockPath);
|
|
495
|
+
}
|
|
496
|
+
catch { /* ignore */ }
|
|
497
|
+
}
|
|
498
|
+
}
|
|
416
499
|
export function recordConversationIngestionConsent(workspaceDir, hostKind, input) {
|
|
500
|
+
if (!isHostKind(hostKind)) {
|
|
501
|
+
return {
|
|
502
|
+
ok: false,
|
|
503
|
+
reason: 'conversation_ingestion_consent_input_invalid: unsupported hostKind',
|
|
504
|
+
nextAction: 'Pass one of codex, workbuddy, or openclaw.',
|
|
505
|
+
};
|
|
506
|
+
}
|
|
417
507
|
const errors = [];
|
|
418
508
|
if (input.decidedAt !== undefined && !isIsoTimestamp(input.decidedAt))
|
|
419
509
|
errors.push('decidedAt must be a parseable ISO-8601 string when provided');
|
|
@@ -462,50 +552,158 @@ export function recordConversationIngestionConsent(workspaceDir, hostKind, input
|
|
|
462
552
|
schemaVersion: CONVERSATION_INGESTION_CONSENT_SCHEMA_VERSION,
|
|
463
553
|
};
|
|
464
554
|
const filePath = getConversationIngestionConsentPath(workspaceDir);
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
555
|
+
const locked = withConsentLedgerLock(filePath, () => {
|
|
556
|
+
// Read-modify-write preserving sibling host slots; a malformed existing
|
|
557
|
+
// ledger fails loud rather than being clobbered (rc-3).
|
|
558
|
+
let hosts = {};
|
|
559
|
+
try {
|
|
560
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
561
|
+
const { ledger, errors: parseErrors } = parseLedgerFile(raw);
|
|
562
|
+
if (ledger === null) {
|
|
563
|
+
return {
|
|
564
|
+
ok: false,
|
|
565
|
+
reason: `conversation_ingestion_consent_malformed: ${parseErrors.join('; ').slice(0, 400)}`,
|
|
566
|
+
nextAction: `Fix or delete ${filePath} before recording a new decision (delete = consent returns to not_present).`,
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
hosts = { ...ledger.hosts };
|
|
570
|
+
}
|
|
571
|
+
catch (error) {
|
|
572
|
+
const codeValue = typeof error === 'object' && error !== null && Object.hasOwn(error, 'code')
|
|
573
|
+
? error.code
|
|
574
|
+
: undefined;
|
|
575
|
+
if (codeValue !== 'ENOENT') {
|
|
576
|
+
const code = typeof codeValue === 'string' ? codeValue : String(error);
|
|
577
|
+
return { ok: false, reason: `conversation_ingestion_consent_write_failed: ${code.slice(0, 120)}`, nextAction: `Check permissions on ${filePath}` };
|
|
578
|
+
}
|
|
579
|
+
const migrated = migrateLegacyCodexConsent(workspaceDir);
|
|
580
|
+
if (!migrated.ok)
|
|
581
|
+
return { ok: false, reason: migrated.reason, nextAction: migrated.nextAction };
|
|
582
|
+
if (migrated.record !== null)
|
|
583
|
+
hosts = { codex: migrated.record };
|
|
477
584
|
}
|
|
478
|
-
|
|
585
|
+
const nextHosts = { ...hosts };
|
|
586
|
+
if (hostKind === 'codex')
|
|
587
|
+
nextHosts.codex = record;
|
|
588
|
+
else if (hostKind === 'workbuddy')
|
|
589
|
+
nextHosts.workbuddy = record;
|
|
590
|
+
else
|
|
591
|
+
nextHosts.openclaw = record;
|
|
592
|
+
const written = writeLedgerAtomically(filePath, { hosts: nextHosts });
|
|
593
|
+
if (!written.ok)
|
|
594
|
+
return { ok: false, reason: written.reason, nextAction: written.nextAction };
|
|
595
|
+
return { ok: true, record };
|
|
596
|
+
});
|
|
597
|
+
if (!locked.ok)
|
|
598
|
+
return { ok: false, reason: locked.reason, nextAction: locked.nextAction };
|
|
599
|
+
return locked.value;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Atomic conditional consent grant (SPEC-PD-PAIN-DETECTION-UPGRADE-001 W1/W2).
|
|
603
|
+
*
|
|
604
|
+
* Uses the EXACT SAME exclusive lock as `recordConversationIngestionConsent`.
|
|
605
|
+
* Permits ONLY the `not_present → granted` transition:
|
|
606
|
+
* - If the host already has `decision === 'revoked'`, refuses to overwrite and
|
|
607
|
+
* returns `{ ok: true, outcome: 'preserved_revoked', record }`.
|
|
608
|
+
* - If already `granted`, returns `{ ok: true, outcome: 'already_granted', record }`.
|
|
609
|
+
* - If `pending` or `failed`, preserves the existing state and returns
|
|
610
|
+
* `{ ok: true, outcome: 'preserved_existing', record }`.
|
|
611
|
+
* - Preserves all sibling host slots.
|
|
612
|
+
*
|
|
613
|
+
* NOTE (W1): Installers must NOT call this autonomously to fabricate Owner
|
|
614
|
+
* consent; it is only called when an explicit Owner confirmation or verified
|
|
615
|
+
* Owner directive is being recorded without risking a revoke race.
|
|
616
|
+
*/
|
|
617
|
+
export function grantConsentIfAbsent(workspaceDir, hostKind, input) {
|
|
618
|
+
if (!isHostKind(hostKind)) {
|
|
619
|
+
return {
|
|
620
|
+
ok: false,
|
|
621
|
+
reason: 'conversation_ingestion_consent_input_invalid: unsupported hostKind',
|
|
622
|
+
nextAction: 'Pass one of codex, workbuddy, or openclaw.',
|
|
623
|
+
};
|
|
479
624
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
625
|
+
const errors = [];
|
|
626
|
+
if (input.decidedAt !== undefined && !isIsoTimestamp(input.decidedAt)) {
|
|
627
|
+
errors.push('decidedAt must be a parseable ISO-8601 string when provided');
|
|
628
|
+
}
|
|
629
|
+
if (!isNonShortString(input.disclosureVersion, 40)) {
|
|
630
|
+
errors.push('disclosureVersion must be a short non-empty string');
|
|
631
|
+
}
|
|
632
|
+
if (input.evidenceRef !== undefined && !isNonShortString(input.evidenceRef, 200)) {
|
|
633
|
+
errors.push('evidenceRef must be a non-empty string (≤200 chars) when provided');
|
|
634
|
+
}
|
|
635
|
+
if (input.decidedVia === 'owner_directive' && input.evidenceRef === undefined) {
|
|
636
|
+
errors.push('decidedVia=owner_directive requires an evidenceRef pointing at the decision record');
|
|
637
|
+
}
|
|
638
|
+
if (errors.length > 0) {
|
|
639
|
+
return {
|
|
640
|
+
ok: false,
|
|
641
|
+
reason: 'conversation_ingestion_consent_input_invalid: ' + errors.join('; '),
|
|
642
|
+
nextAction: `Fix the grantConsentIfAbsent arguments for host '${hostKind}' at the call site.`,
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
const filePath = getConversationIngestionConsentPath(workspaceDir);
|
|
646
|
+
const locked = withConsentLedgerLock(filePath, () => {
|
|
647
|
+
let hosts = {};
|
|
648
|
+
try {
|
|
649
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
650
|
+
const { ledger, errors: parseErrors } = parseLedgerFile(raw);
|
|
651
|
+
if (ledger === null) {
|
|
652
|
+
return {
|
|
653
|
+
ok: false,
|
|
654
|
+
reason: `conversation_ingestion_consent_malformed: ${parseErrors.join('; ').slice(0, 400)}`,
|
|
655
|
+
nextAction: `Fix or delete ${filePath} before recording a new decision (delete = consent returns to not_present).`,
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
hosts = { ...ledger.hosts };
|
|
659
|
+
}
|
|
660
|
+
catch (error) {
|
|
661
|
+
const codeValue = typeof error === 'object' && error !== null && Object.hasOwn(error, 'code')
|
|
662
|
+
? error.code
|
|
663
|
+
: undefined;
|
|
664
|
+
if (codeValue !== 'ENOENT') {
|
|
665
|
+
const code = typeof codeValue === 'string' ? codeValue : String(error);
|
|
666
|
+
return { ok: false, reason: `conversation_ingestion_consent_write_failed: ${code.slice(0, 120)}`, nextAction: `Check permissions on ${filePath}` };
|
|
667
|
+
}
|
|
668
|
+
const migrated = migrateLegacyCodexConsent(workspaceDir);
|
|
669
|
+
if (!migrated.ok)
|
|
670
|
+
return { ok: false, reason: migrated.reason, nextAction: migrated.nextAction };
|
|
671
|
+
if (migrated.record !== null)
|
|
672
|
+
hosts = { codex: migrated.record };
|
|
492
673
|
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
674
|
+
const existing = hosts[hostKind];
|
|
675
|
+
if (existing !== undefined) {
|
|
676
|
+
if (existing.decision === 'revoked') {
|
|
677
|
+
return { ok: true, outcome: 'preserved_revoked', record: existing };
|
|
678
|
+
}
|
|
679
|
+
if (existing.decision === 'granted') {
|
|
680
|
+
return { ok: true, outcome: 'already_granted', record: existing };
|
|
681
|
+
}
|
|
682
|
+
return { ok: true, outcome: 'preserved_existing', record: existing };
|
|
683
|
+
}
|
|
684
|
+
const record = {
|
|
685
|
+
decision: 'granted',
|
|
686
|
+
disclosureVersion: input.disclosureVersion,
|
|
687
|
+
decidedAt: input.decidedAt ?? new Date().toISOString(),
|
|
688
|
+
decidedVia: input.decidedVia,
|
|
689
|
+
...(input.evidenceRef !== undefined ? { evidenceRef: input.evidenceRef.slice(0, 200) } : {}),
|
|
690
|
+
schemaVersion: CONVERSATION_INGESTION_CONSENT_SCHEMA_VERSION,
|
|
691
|
+
};
|
|
692
|
+
const nextHosts = { ...hosts };
|
|
693
|
+
if (hostKind === 'codex')
|
|
694
|
+
nextHosts.codex = record;
|
|
695
|
+
else if (hostKind === 'workbuddy')
|
|
696
|
+
nextHosts.workbuddy = record;
|
|
697
|
+
else
|
|
698
|
+
nextHosts.openclaw = record;
|
|
699
|
+
const written = writeLedgerAtomically(filePath, { hosts: nextHosts });
|
|
700
|
+
if (!written.ok)
|
|
701
|
+
return { ok: false, reason: written.reason, nextAction: written.nextAction };
|
|
702
|
+
return { ok: true, outcome: 'granted', record };
|
|
703
|
+
});
|
|
704
|
+
if (!locked.ok)
|
|
705
|
+
return { ok: false, reason: locked.reason, nextAction: locked.nextAction };
|
|
706
|
+
return locked.value;
|
|
509
707
|
}
|
|
510
708
|
/**
|
|
511
709
|
* Combine the consent record with the ingestion flag into the health-surface
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical conversation-ingestion disclosure versions and Owner-facing text.
|
|
3
|
+
*
|
|
4
|
+
* Consent is valid only when it binds to the disclosure text the Owner was
|
|
5
|
+
* actually shown. CLI and Console therefore must share this one module rather
|
|
6
|
+
* than keeping independent version strings or paraphrased disclosure bodies.
|
|
7
|
+
*/
|
|
8
|
+
import { CODEX_INGESTION_DISCLOSURE_VERSION } from '../codex-disclosure.js';
|
|
9
|
+
import type { ConversationConsentHostKind } from './consent.js';
|
|
10
|
+
export { CODEX_INGESTION_DISCLOSURE_VERSION };
|
|
11
|
+
export declare const WORKBUDDY_INGESTION_DISCLOSURE_VERSION = "wb-2026-11-11";
|
|
12
|
+
export declare const OPENCLAW_INGESTION_DISCLOSURE_VERSION = "oc-2026-11-29";
|
|
13
|
+
export declare const CONVERSATION_INGESTION_DISCLOSURE_VERSION_BY_HOST: Readonly<Record<ConversationConsentHostKind, string>>;
|
|
14
|
+
export declare function getWorkbuddyIngestionDisclosureText(): string;
|
|
15
|
+
export declare function getOpenclawIngestionDisclosureText(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Owner-facing disclosure text for one host. The returned text always carries
|
|
18
|
+
* the exact version it represents so the persisted consent record can be
|
|
19
|
+
* audited against what was displayed.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getConversationIngestionDisclosureText(hostKind: ConversationConsentHostKind): string;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical conversation-ingestion disclosure versions and Owner-facing text.
|
|
3
|
+
*
|
|
4
|
+
* Consent is valid only when it binds to the disclosure text the Owner was
|
|
5
|
+
* actually shown. CLI and Console therefore must share this one module rather
|
|
6
|
+
* than keeping independent version strings or paraphrased disclosure bodies.
|
|
7
|
+
*/
|
|
8
|
+
import { CODEX_INGESTION_DISCLOSURE_VERSION, getCodexIngestionDisclosureText, } from '../codex-disclosure.js';
|
|
9
|
+
export { CODEX_INGESTION_DISCLOSURE_VERSION };
|
|
10
|
+
export const WORKBUDDY_INGESTION_DISCLOSURE_VERSION = 'wb-2026-11-11';
|
|
11
|
+
export const OPENCLAW_INGESTION_DISCLOSURE_VERSION = 'oc-2026-11-29';
|
|
12
|
+
export const CONVERSATION_INGESTION_DISCLOSURE_VERSION_BY_HOST = {
|
|
13
|
+
codex: CODEX_INGESTION_DISCLOSURE_VERSION,
|
|
14
|
+
workbuddy: WORKBUDDY_INGESTION_DISCLOSURE_VERSION,
|
|
15
|
+
openclaw: OPENCLAW_INGESTION_DISCLOSURE_VERSION,
|
|
16
|
+
};
|
|
17
|
+
export function getWorkbuddyIngestionDisclosureText() {
|
|
18
|
+
return [
|
|
19
|
+
'PD · WorkBuddy 会话采集授权(' + WORKBUDDY_INGESTION_DISCLOSURE_VERSION + ')',
|
|
20
|
+
'',
|
|
21
|
+
'开启后,PD 会在每次会话结束时读取 WorkBuddy 在本机写下的会话转录',
|
|
22
|
+
'(~/.workbuddy/projects/<项目>/<会话ID>.jsonl),并把以下内容写入本工作区的',
|
|
23
|
+
'trajectory.db(governance_observations 表),供 Pain 诊断与原则内化的数据管道使用:',
|
|
24
|
+
' - 您本人输入的话语(仅 <user_query> 内的文本)',
|
|
25
|
+
' - 助手的可见回复、推理记录、工具调用名称与结果状态',
|
|
26
|
+
'不会采集:宿主注入的 system-reminder 上下文(系统提示、身份文件、工具声明、',
|
|
27
|
+
'连接器状态等)。解码器只从 <user_query> 结构化边界投影 Owner 原话;',
|
|
28
|
+
'无法确认该边界时,该条记录标记为 partial 且不写入原文(fail-closed,宁缺毋滥)。',
|
|
29
|
+
'',
|
|
30
|
+
'采集受三道门约束:host.workbuddy + workbuddy_conversation_ingestion + 本同意记录',
|
|
31
|
+
'(decision=granted)。默认关闭;任一门关闭时 PD 不会打开任何转录文件(零读取)。',
|
|
32
|
+
'',
|
|
33
|
+
'随时可用 `pd workbuddy setup --decline` 撤销;撤销只影响后续采集,',
|
|
34
|
+
'已入库数据按既有的保留策略处理。',
|
|
35
|
+
].join('\n');
|
|
36
|
+
}
|
|
37
|
+
export function getOpenclawIngestionDisclosureText() {
|
|
38
|
+
return [
|
|
39
|
+
'PD · OpenClaw 会话采集授权(' + OPENCLAW_INGESTION_DISCLOSURE_VERSION + ')',
|
|
40
|
+
'',
|
|
41
|
+
'开启后,PD 只在 OpenClaw 主动投递的 hook 事件里接收当前会话内容,',
|
|
42
|
+
'并把以下内容写入本工作区的 trajectory.db,供 Pain 诊断与原则内化使用:',
|
|
43
|
+
' - 您本人输入的话语(user_turns)',
|
|
44
|
+
' - 助手的可见回复(assistant_turns)',
|
|
45
|
+
'',
|
|
46
|
+
'采集受两道门约束,缺一不可(fail-closed):',
|
|
47
|
+
' 1. 宿主配置 plugins.entries.principles-disciple.hooks.allowConversationAccess = true',
|
|
48
|
+
' 2. 本同意记录 decision=granted(pd openclaw setup --accept)',
|
|
49
|
+
'',
|
|
50
|
+
'任一门不满足时,PD 只保留会话轮次事实(不含任何正文),不写入、不读取任何对话正文。',
|
|
51
|
+
'',
|
|
52
|
+
'随时可用 `pd openclaw setup --decline` 撤销;撤销会立即清退已入库正文',
|
|
53
|
+
'(trajectory 轮次、blob、治理观察、signal_confirmations 摘录与 pain 链中的宿主正文),并阻止后续采集。',
|
|
54
|
+
'',
|
|
55
|
+
'共享工作区例外:若同一 workspace 还有其他宿主(如 WorkBuddy)保持授权,',
|
|
56
|
+
'宿主不可归属的轮次/摘录表会被保留(见 sweep 报告 skipped 列表),仅清退可归属部分。',
|
|
57
|
+
].join('\n');
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Owner-facing disclosure text for one host. The returned text always carries
|
|
61
|
+
* the exact version it represents so the persisted consent record can be
|
|
62
|
+
* audited against what was displayed.
|
|
63
|
+
*/
|
|
64
|
+
export function getConversationIngestionDisclosureText(hostKind) {
|
|
65
|
+
if (hostKind === 'workbuddy')
|
|
66
|
+
return getWorkbuddyIngestionDisclosureText();
|
|
67
|
+
if (hostKind === 'openclaw')
|
|
68
|
+
return getOpenclawIngestionDisclosureText();
|
|
69
|
+
return [
|
|
70
|
+
`PD · Codex 会话采集授权(${CODEX_INGESTION_DISCLOSURE_VERSION})`,
|
|
71
|
+
'',
|
|
72
|
+
getCodexIngestionDisclosureText('zh'),
|
|
73
|
+
].join('\n');
|
|
74
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HostEvent, HostEventResult } from '@principles/core/host';
|
|
2
|
+
import type { AfterToolCallEnvironmentFacts } from './environment-facts.js';
|
|
3
|
+
export interface ForwardObservationOptions {
|
|
4
|
+
hostKind?: string;
|
|
5
|
+
environmentProvider?: (event: HostEvent) => AfterToolCallEnvironmentFacts;
|
|
6
|
+
}
|
|
7
|
+
export declare function forwardObservationScopeAuthorized(workspaceDir: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Persist the opportunity and its event-scoped pre-gate environment snapshot
|
|
10
|
+
* in one immediate transaction. Returns null when evidence is unavailable;
|
|
11
|
+
* callers must continue the production gate regardless.
|
|
12
|
+
*/
|
|
13
|
+
export declare function capturePreGateOpportunity(event: HostEvent, options: ForwardObservationOptions): {
|
|
14
|
+
opportunityId: string | null;
|
|
15
|
+
warnings: string[];
|
|
16
|
+
};
|
|
17
|
+
export declare function recordForwardGateDecision(input: {
|
|
18
|
+
event: HostEvent;
|
|
19
|
+
result: HostEventResult;
|
|
20
|
+
opportunityId: string;
|
|
21
|
+
hostKind?: string;
|
|
22
|
+
}): string[];
|
|
23
|
+
/** Best-effort close-boundary observation for Stop/turn_complete hooks. */
|
|
24
|
+
export declare function observeForwardTurnClose(args: {
|
|
25
|
+
workspaceDir: string;
|
|
26
|
+
hostKind: 'codex' | 'workbuddy';
|
|
27
|
+
sessionId: string;
|
|
28
|
+
turnId?: string;
|
|
29
|
+
}): string[];
|