@principles/pd-cli 2.2.0 → 2.4.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/commands/build-trajectory-evidence.d.ts.map +1 -1
- package/dist/commands/build-trajectory-evidence.js +17 -11
- package/dist/commands/build-trajectory-evidence.js.map +1 -1
- package/dist/commands/codex-reconcile.d.ts +7 -0
- package/dist/commands/codex-reconcile.d.ts.map +1 -1
- package/dist/commands/codex-reconcile.js +11 -2
- package/dist/commands/codex-reconcile.js.map +1 -1
- package/dist/commands/codex-worker.d.ts.map +1 -1
- package/dist/commands/codex-worker.js +35 -0
- package/dist/commands/codex-worker.js.map +1 -1
- package/dist/commands/command-helpers.d.ts +1 -1
- package/dist/commands/command-helpers.js +1 -1
- package/dist/commands/diagnose.js +1 -1
- package/dist/commands/diagnose.js.map +1 -1
- package/dist/commands/errors-list.d.ts +1 -1
- package/dist/commands/errors-list.js +1 -1
- package/dist/commands/health-ingestion.d.ts +96 -0
- package/dist/commands/health-ingestion.d.ts.map +1 -0
- package/dist/commands/health-ingestion.js +473 -0
- package/dist/commands/health-ingestion.js.map +1 -0
- package/dist/commands/health-mcp.d.ts +23 -1
- package/dist/commands/health-mcp.d.ts.map +1 -1
- package/dist/commands/health-mcp.js +81 -22
- package/dist/commands/health-mcp.js.map +1 -1
- package/dist/commands/health.d.ts +1 -1
- package/dist/commands/health.d.ts.map +1 -1
- package/dist/commands/health.js +22 -5
- package/dist/commands/health.js.map +1 -1
- package/dist/commands/principles-stats.d.ts +1 -1
- package/dist/commands/principles-stats.js +1 -1
- package/dist/commands/trajectory-retention.d.ts +23 -0
- package/dist/commands/trajectory-retention.d.ts.map +1 -0
- package/dist/commands/trajectory-retention.js +159 -0
- package/dist/commands/trajectory-retention.js.map +1 -0
- package/dist/commands/workbuddy-setup.d.ts +69 -0
- package/dist/commands/workbuddy-setup.d.ts.map +1 -0
- package/dist/commands/workbuddy-setup.js +379 -0
- package/dist/commands/workbuddy-setup.js.map +1 -0
- package/dist/commands/workbuddy-worker.d.ts.map +1 -1
- package/dist/commands/workbuddy-worker.js +42 -6
- package/dist/commands/workbuddy-worker.js.map +1 -1
- package/dist/index.d.ts +1 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1201
- package/dist/index.js.map +1 -1
- package/dist/program.d.ts +17 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +1263 -0
- package/dist/program.js.map +1 -0
- package/dist/services/delivery-surfaces.d.ts.map +1 -1
- package/dist/services/delivery-surfaces.js +7 -5
- package/dist/services/delivery-surfaces.js.map +1 -1
- package/dist/services/demo-story-a-runner.js +1 -1
- package/dist/services/demo-story-a-runner.js.map +1 -1
- package/dist/services/version-report.d.ts.map +1 -1
- package/dist/services/version-report.js +35 -5
- package/dist/services/version-report.js.map +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `pd trajectory maintain | retention status | vacuum` — SPEC-PD-TR-001.
|
|
3
|
+
*
|
|
4
|
+
* CLI contract:
|
|
5
|
+
* - `--json` writes exactly one JSON document to stdout (cli-1);
|
|
6
|
+
* - refusals carry a structured `reason` + `nextAction` and exit non-zero
|
|
7
|
+
* without mutating anything (cli-5, cli-6);
|
|
8
|
+
* - `vacuum` is dry-run unless `--yes` (cli-4).
|
|
9
|
+
*/
|
|
10
|
+
import { readTrajectoryRetentionStatus, runTrajectoryRetention, vacuumTrajectoryDatabase, } from '@principles/host-runtime';
|
|
11
|
+
import { resolveWorkspaceDir } from '../resolve-workspace.js';
|
|
12
|
+
function printMaintain(report) {
|
|
13
|
+
if (report.outcome === 'skipped') {
|
|
14
|
+
console.log(`Retention skipped: ${report.reason ?? 'unknown'}`);
|
|
15
|
+
if (report.nextAction !== undefined)
|
|
16
|
+
console.log(`Next: ${report.nextAction}`);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const deleted = Object.entries(report.deletedByTable)
|
|
20
|
+
.filter(([, count]) => count > 0)
|
|
21
|
+
.map(([table, count]) => `${table}=${count}`)
|
|
22
|
+
.join(' ');
|
|
23
|
+
console.log(`Retention ${report.outcome} (cutoff ${report.cutoff ?? 'n/a'}, ${report.batches} batch(es), `
|
|
24
|
+
+ `${report.totalDurationMs} ms total, max batch ${report.maxBatchDurationMs} ms)`
|
|
25
|
+
+ (deleted === '' ? ', deleted 0 rows' : `: ${deleted}`));
|
|
26
|
+
if (report.partial)
|
|
27
|
+
console.log('Partial: the run budget or batch budget was exhausted; the next run continues.');
|
|
28
|
+
if (report.backoffUntil !== null)
|
|
29
|
+
console.log(`Backoff until ${report.backoffUntil}`);
|
|
30
|
+
if (report.nextAction !== undefined)
|
|
31
|
+
console.log(`Next: ${report.nextAction}`);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Reasons that mean "this run was supposed to delete but could not" and that a
|
|
35
|
+
* human/automation must act on. Deliberately EXCLUDES the designed yields —
|
|
36
|
+
* `deferred:busy`, `deadline`, `run_budget_exhausted`, `no_progress:*`,
|
|
37
|
+
* `batch_over_budget`, `locked`, `not_due:*`, `backoff:*` — because a healthy
|
|
38
|
+
* cron must not page on the budget doing its job.
|
|
39
|
+
*
|
|
40
|
+
* Included:
|
|
41
|
+
* - `failed:` unhandled error, deletion stopped;
|
|
42
|
+
* - `audit_failed:` fail-closed: the batch was NOT deleted because the
|
|
43
|
+
* audit list could not be written;
|
|
44
|
+
* - `config_invalid:` / config refuses to load or degrades: nothing is deleted;
|
|
45
|
+
* `degraded:`
|
|
46
|
+
* - `journal_mode_not_wal` the database can never be swept in this mode;
|
|
47
|
+
* - `clock_*` / `marker_timestamp_invalid` the clock/marker guard skipped the
|
|
48
|
+
* run (forward/invalid self-heals next run, backwards
|
|
49
|
+
* persists while the clock is wrong);
|
|
50
|
+
* - `index_failed:` sweeping works but the plan is degraded; persistent
|
|
51
|
+
* until repaired;
|
|
52
|
+
* - `invariant_violation` row counts did not reconcile.
|
|
53
|
+
*/
|
|
54
|
+
const OPERATOR_FAILURE_REASON_PREFIXES = Object.freeze([
|
|
55
|
+
'failed:',
|
|
56
|
+
'audit_failed:',
|
|
57
|
+
'config_invalid:',
|
|
58
|
+
'degraded:',
|
|
59
|
+
'journal_mode_not_wal',
|
|
60
|
+
'clock_',
|
|
61
|
+
'marker_timestamp_invalid',
|
|
62
|
+
'index_failed:',
|
|
63
|
+
]);
|
|
64
|
+
/**
|
|
65
|
+
* Exit code for `pd trajectory maintain`: 1 only when the run needs a human,
|
|
66
|
+
* 0 for success, intentional-off states and designed budget/busy yields.
|
|
67
|
+
*/
|
|
68
|
+
export function retentionExitCode(report) {
|
|
69
|
+
if (report.outcome === 'invariant_violation')
|
|
70
|
+
return 1;
|
|
71
|
+
const reason = report.reason ?? '';
|
|
72
|
+
return OPERATOR_FAILURE_REASON_PREFIXES.some((prefix) => reason.startsWith(prefix)) ? 1 : 0;
|
|
73
|
+
}
|
|
74
|
+
export async function handleTrajectoryMaintain(opts) {
|
|
75
|
+
const workspaceDir = resolveWorkspaceDir(opts.workspace);
|
|
76
|
+
// Manual invocations are the fallback for workspaces with no running worker,
|
|
77
|
+
// so they ignore `intervalHours`; lock, clock guards, budgets and the
|
|
78
|
+
// fail-closed config rules all still apply.
|
|
79
|
+
const report = runTrajectoryRetention({ workspaceDir, trigger: 'manual' });
|
|
80
|
+
if (opts.json === true) {
|
|
81
|
+
console.log(JSON.stringify(report, null, 2));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
printMaintain(report);
|
|
85
|
+
}
|
|
86
|
+
const exitCode = retentionExitCode(report);
|
|
87
|
+
if (exitCode !== 0)
|
|
88
|
+
process.exitCode = exitCode;
|
|
89
|
+
}
|
|
90
|
+
export async function handleTrajectoryRetentionStatus(opts) {
|
|
91
|
+
const workspaceDir = resolveWorkspaceDir(opts.workspace);
|
|
92
|
+
const status = readTrajectoryRetentionStatus(workspaceDir);
|
|
93
|
+
if (opts.json === true) {
|
|
94
|
+
console.log(JSON.stringify(status, null, 2));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
console.log(`Workspace: ${status.workspaceDir}`);
|
|
98
|
+
console.log(`Database: ${status.dbPath} (${status.dbExists ? 'present' : 'missing'})`);
|
|
99
|
+
console.log(`Policy: enabled=${status.policy.enabled} retentionDays=${status.policy.retentionDays} `
|
|
100
|
+
+ `intervalHours=${status.policy.intervalHours} batchSize=${status.policy.batchSize} `
|
|
101
|
+
+ `runBudgetMs=${status.policy.runBudgetMs}`
|
|
102
|
+
+ (status.policy.degradedReason === undefined ? '' : ` [degraded: ${status.policy.degradedReason}]`));
|
|
103
|
+
console.log(`Last run: ${status.marker.lastRunAt ?? 'never'} (${status.marker.lastOutcome ?? 'n/a'})`);
|
|
104
|
+
console.log(`Cutoff: ${status.marker.lastCutoff ?? 'n/a'}`);
|
|
105
|
+
console.log(`Next run: cutoff ${status.nextCutoff ?? 'n/a (no sweep scheduled)'}`);
|
|
106
|
+
if (status.marker.backoffUntil !== null)
|
|
107
|
+
console.log(`Backoff: ${status.marker.backoffUntil}`);
|
|
108
|
+
if (status.markerError !== null)
|
|
109
|
+
console.log(`Marker: unreadable (${status.markerError})`);
|
|
110
|
+
if (status.dbError !== null)
|
|
111
|
+
console.log(`Database: unreadable (${status.dbError})`);
|
|
112
|
+
if (status.indexesMissing.length > 0) {
|
|
113
|
+
console.log(`Indexes: missing ${status.indexesMissing.join(', ')} — run \`pd trajectory vacuum --yes\``);
|
|
114
|
+
}
|
|
115
|
+
if (status.expiredByTable !== null) {
|
|
116
|
+
const counts = Object.entries(status.expiredByTable)
|
|
117
|
+
.map(([table, count]) => `${table}=${count}`)
|
|
118
|
+
.join(' ');
|
|
119
|
+
// Same cutoff the next run will use, so this is a projection, not a
|
|
120
|
+
// different definition of "expired" (F4).
|
|
121
|
+
console.log(`Next delete: ${counts}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function printVacuum(report) {
|
|
125
|
+
if (report.refusedReason !== null) {
|
|
126
|
+
console.log(`VACUUM refused: ${report.refusedReason}`);
|
|
127
|
+
console.log(`Size ${report.sizeBeforeBytes} bytes, free ${report.freeBytes ?? 'unknown'}, `
|
|
128
|
+
+ `required ${report.requiredBytes ?? 'unknown'} (2 x size + 10%)`);
|
|
129
|
+
if (report.nextAction !== undefined)
|
|
130
|
+
console.log(`Next: ${report.nextAction}`);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (!report.applied) {
|
|
134
|
+
console.log(`VACUUM dry run: size ${report.sizeBeforeBytes} bytes, freelist ${report.freelistBefore ?? 'unknown'} pages, `
|
|
135
|
+
+ `free ${report.freeBytes ?? 'unknown'}, required ${report.requiredBytes ?? 'unknown'}`);
|
|
136
|
+
if (report.nextAction !== undefined)
|
|
137
|
+
console.log(`Next: ${report.nextAction}`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
console.log(`VACUUM done in ${report.durationMs} ms: ${report.sizeBeforeBytes} -> ${report.sizeAfterBytes ?? 'unknown'} bytes, `
|
|
141
|
+
+ `freelist ${report.freelistBefore ?? 'unknown'} -> ${report.freelistAfter ?? 'unknown'} pages`);
|
|
142
|
+
if (report.indexes !== null) {
|
|
143
|
+
console.log(`Indexes: ${report.indexes.applied.length} applied, ${report.indexes.skipped.length} skipped`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
export async function handleTrajectoryVacuum(opts) {
|
|
147
|
+
const workspaceDir = resolveWorkspaceDir(opts.workspace);
|
|
148
|
+
const report = vacuumTrajectoryDatabase({ workspaceDir, apply: opts.yes === true });
|
|
149
|
+
if (opts.json === true) {
|
|
150
|
+
console.log(JSON.stringify(report, null, 2));
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
printVacuum(report);
|
|
154
|
+
}
|
|
155
|
+
if (report.refusedReason !== null) {
|
|
156
|
+
process.exitCode = 1;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=trajectory-retention.js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AM,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,UAAU,CAChG,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,IAA6B;IACxE,MAAM,YAAY,GAAG,mBAAmB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,wBAAwB,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC,CAAC;IAEpF,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC;SAAM,CAAC;QACN,WAAW,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;IAED,IAAI,MAAM,CAAC,aAAa,KAAK,IAAI,EAAE,CAAC;QAClC,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type ConversationIngestionConsentState } from '@principles/host-runtime';
|
|
2
|
+
export declare const WORKBUDDY_INGESTION_DISCLOSURE_VERSION = "wb-2026-11-11";
|
|
3
|
+
export interface WorkbuddySetupOptions {
|
|
4
|
+
workspace?: string;
|
|
5
|
+
json?: boolean;
|
|
6
|
+
accept?: boolean;
|
|
7
|
+
decline?: boolean;
|
|
8
|
+
showDisclosure?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface WorkbuddySetupReport {
|
|
11
|
+
generatedAt: string;
|
|
12
|
+
host: 'workbuddy';
|
|
13
|
+
workspace: string;
|
|
14
|
+
status: 'ok' | 'degraded';
|
|
15
|
+
decision?: 'granted' | 'revoked';
|
|
16
|
+
consentStateBefore: ConversationIngestionConsentState;
|
|
17
|
+
consentState: ConversationIngestionConsentState;
|
|
18
|
+
disclosureVersion: string;
|
|
19
|
+
ingestionFlag: {
|
|
20
|
+
name: string;
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
};
|
|
23
|
+
hostWorkbuddyFlagEnabled: boolean;
|
|
24
|
+
warnings: string[];
|
|
25
|
+
reason?: string;
|
|
26
|
+
nextAction?: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function getWorkbuddyIngestionDisclosureText(): string;
|
|
29
|
+
/**
|
|
30
|
+
* `restored` is only meaningful on failure: it says whether the pre-mutation
|
|
31
|
+
* bytes were successfully put back. A rollback whose calibration check fails
|
|
32
|
+
* can still have restored the file, and the operator message must not claim
|
|
33
|
+
* otherwise.
|
|
34
|
+
*/
|
|
35
|
+
type FlagWriteResult = {
|
|
36
|
+
ok: true;
|
|
37
|
+
} | {
|
|
38
|
+
ok: false;
|
|
39
|
+
reason: string;
|
|
40
|
+
nextAction: string;
|
|
41
|
+
restored?: boolean;
|
|
42
|
+
};
|
|
43
|
+
/** Options for {@link setWorkbuddyIngestionFlag}. */
|
|
44
|
+
export interface SetWorkbuddyIngestionFlagOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Exact bytes captured BEFORE this command's first mutation. Used when the
|
|
47
|
+
* round-trip verification fails: a restore must return the file to the last
|
|
48
|
+
* state the Owner actually saw, not to whatever the current call just read
|
|
49
|
+
* (a rollback call would otherwise "restore" the intermediate enabled bytes).
|
|
50
|
+
*/
|
|
51
|
+
restoreBytes?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Line-targeted, atomic, round-trip-verified edit of
|
|
55
|
+
* `features.workbuddy_conversation_ingestion.enabled`. Same shape as the
|
|
56
|
+
* Codex setup's config edit (kept separate so the frozen Codex consent flow
|
|
57
|
+
* is untouched); comments and every other key are preserved.
|
|
58
|
+
*/
|
|
59
|
+
export declare function setWorkbuddyIngestionFlag(workspaceDir: string, enabled: boolean, options?: SetWorkbuddyIngestionFlagOptions): FlagWriteResult;
|
|
60
|
+
/**
|
|
61
|
+
* `pd workbuddy setup` entry point: read the current consent/flag state, then
|
|
62
|
+
* grant or revoke WorkBuddy ingestion and report what changed.
|
|
63
|
+
*
|
|
64
|
+
* Emits exactly one machine-readable JSON object under `--json` (cli-1) and
|
|
65
|
+
* sets exit code 1 only for a degraded outcome.
|
|
66
|
+
*/
|
|
67
|
+
export declare function handleWorkbuddySetup(options: WorkbuddySetupOptions): Promise<void>;
|
|
68
|
+
export {};
|
|
69
|
+
//# sourceMappingURL=workbuddy-setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workbuddy-setup.d.ts","sourceRoot":"","sources":["../../src/commands/workbuddy-setup.ts"],"names":[],"mappings":"AA6BA,OAAO,EAML,KAAK,iCAAiC,EACvC,MAAM,0BAA0B,CAAC;AAGlC,eAAO,MAAM,sCAAsC,kBAAkB,CAAC;AAItE,MAAM,WAAW,qBAAqB;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,IAAI,GAAG,UAAU,CAAC;IAC1B,QAAQ,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IACjC,kBAAkB,EAAE,iCAAiC,CAAC;IACtD,YAAY,EAAE,iCAAiC,CAAC;IAChD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAClD,wBAAwB,EAAE,OAAO,CAAC;IAClC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,mCAAmC,IAAI,MAAM,CAmB5D;AAED;;;;;GAKG;AACH,KAAK,eAAe,GAChB;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GACZ;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAiB1E,qDAAqD;AACrD,MAAM,WAAW,gCAAgC;IAC/C;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,gCAAqC,GAAG,eAAe,CA0HjJ;AAWD;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CA+JxF"}
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pd workbuddy setup — the SUPPORTED entry point for WorkBuddy conversation
|
|
3
|
+
* ingestion consent (PRI-1171 P2, tickets ⑤/⑥).
|
|
4
|
+
*
|
|
5
|
+
* "Supported" is a convention, not an enforced boundary: the consent ledger
|
|
6
|
+
* (`<workspace>/.state/conversation-ingestion-consent.json`) and the workspace
|
|
7
|
+
* config are ordinary files, and `recordConversationIngestionConsent` is a
|
|
8
|
+
* public export — another tool could write the same durable facts. What this
|
|
9
|
+
* command owns is the intended UX: present the disclosure, record the explicit
|
|
10
|
+
* decision, and flip the flag in the order below.
|
|
11
|
+
*
|
|
12
|
+
* The two writes are ordered so a granted record can never precede a
|
|
13
|
+
* successfully enabled flag, and a failed consent write rolls the flag back to
|
|
14
|
+
* the exact bytes captured before this command's first mutation (atomic
|
|
15
|
+
* tmp+rename, never an in-place truncate).
|
|
16
|
+
*
|
|
17
|
+
* The runtime (workbuddy-adapter/src/ingestion/ingestion.ts) READS this ledger
|
|
18
|
+
* on every Stop hook — unlike the Codex path, which still hard-codes a grant
|
|
19
|
+
* from its setup-flow invariant. Revocation therefore takes effect immediately.
|
|
20
|
+
*
|
|
21
|
+
* CLI gate compliance: cli-1 (--json is one JSON object), cli-2 (explicit
|
|
22
|
+
* exit after refuse), cli-4 (--accept/--decline mutex), cli-5 (refused runs
|
|
23
|
+
* mutate nothing), cli-6 (every refusal carries reason + nextAction).
|
|
24
|
+
*/
|
|
25
|
+
import * as fs from 'node:fs';
|
|
26
|
+
import * as os from 'node:os';
|
|
27
|
+
import * as path from 'node:path';
|
|
28
|
+
import { getWorkbuddyWorkspaceDir } from '@principles/install-layout';
|
|
29
|
+
import { resolveWorkspaceDir } from '../resolve-workspace.js';
|
|
30
|
+
import { deriveConversationIngestionConsentState, getPdConfigPath, loadPdConfigForPlugin, readConversationIngestionConsent, recordConversationIngestionConsent, } from '@principles/host-runtime';
|
|
31
|
+
import { computeEffectivePdConfig, computeFeatureFlagsFromConfig, isFeatureEnabled } from '@principles/core/runtime';
|
|
32
|
+
export const WORKBUDDY_INGESTION_DISCLOSURE_VERSION = 'wb-2026-11-11';
|
|
33
|
+
const FLAG_ID = 'workbuddy_conversation_ingestion';
|
|
34
|
+
const SETUP_COMMAND = 'pd workbuddy setup';
|
|
35
|
+
export function getWorkbuddyIngestionDisclosureText() {
|
|
36
|
+
return [
|
|
37
|
+
'PD · WorkBuddy 会话采集授权(' + WORKBUDDY_INGESTION_DISCLOSURE_VERSION + ')',
|
|
38
|
+
'',
|
|
39
|
+
'开启后,PD 会在每次会话结束时读取 WorkBuddy 在本机写下的会话转录',
|
|
40
|
+
'(~/.workbuddy/projects/<项目>/<会话ID>.jsonl),并把以下内容写入本工作区的',
|
|
41
|
+
'trajectory.db(governance_observations 表),供 Pain 诊断与原则内化的数据管道使用:',
|
|
42
|
+
' - 您本人输入的话语(仅 <user_query> 内的文本)',
|
|
43
|
+
' - 助手的可见回复、推理记录、工具调用名称与结果状态',
|
|
44
|
+
'不会采集:宿主注入的 system-reminder 上下文(系统提示、身份文件、工具声明、',
|
|
45
|
+
'连接器状态等)。解码器只从 <user_query> 结构化边界投影 Owner 原话;',
|
|
46
|
+
'无法确认该边界时,该条记录标记为 partial 且不写入原文(fail-closed,宁缺毋滥)。',
|
|
47
|
+
'',
|
|
48
|
+
'采集受三道门约束:host.workbuddy + workbuddy_conversation_ingestion + 本同意记录',
|
|
49
|
+
'(decision=granted)。默认关闭;任一门关闭时 PD 不会打开任何转录文件(零读取)。',
|
|
50
|
+
'',
|
|
51
|
+
'随时可用 `' + SETUP_COMMAND + ' --decline` 撤销;撤销只影响后续采集,',
|
|
52
|
+
'已入库数据按既有的保留策略处理。',
|
|
53
|
+
].join('\n');
|
|
54
|
+
}
|
|
55
|
+
const FEATURES_LINE = /^features:\s*(?:#.*)?$/;
|
|
56
|
+
const KEY_LINE = /^ {2}workbuddy_conversation_ingestion:\s*(?:#.*)?$/;
|
|
57
|
+
const ENABLED_LINE = /^ {4}enabled:\s*(?:true|false)\s*(?:#.*)?$/;
|
|
58
|
+
/** Drop an inline `#` comment and surrounding whitespace from one YAML line. */
|
|
59
|
+
function stripComment(line) {
|
|
60
|
+
const hash = line.indexOf('#');
|
|
61
|
+
return (hash === -1 ? line : line.slice(0, hash)).trim();
|
|
62
|
+
}
|
|
63
|
+
/** Runtime-contract guard (rc-1): a non-null, non-array object is the only trusted shape. */
|
|
64
|
+
function isPlainObject(value) {
|
|
65
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Line-targeted, atomic, round-trip-verified edit of
|
|
69
|
+
* `features.workbuddy_conversation_ingestion.enabled`. Same shape as the
|
|
70
|
+
* Codex setup's config edit (kept separate so the frozen Codex consent flow
|
|
71
|
+
* is untouched); comments and every other key are preserved.
|
|
72
|
+
*/
|
|
73
|
+
export function setWorkbuddyIngestionFlag(workspaceDir, enabled, options = {}) {
|
|
74
|
+
const configPath = getPdConfigPath(workspaceDir);
|
|
75
|
+
let raw;
|
|
76
|
+
try {
|
|
77
|
+
raw = fs.readFileSync(configPath, 'utf8');
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
const code = typeof error === 'object' && error !== null && Object.hasOwn(error, 'code')
|
|
81
|
+
? String(error.code) : String(error);
|
|
82
|
+
return { ok: false, reason: 'config_unreadable:' + code, nextAction: 'Run `pd runtime init --confirm` in this workspace, then re-run `' + SETUP_COMMAND + '`.' };
|
|
83
|
+
}
|
|
84
|
+
const registry = computeFeatureFlagsFromConfig(computeEffectivePdConfig(null)).flags;
|
|
85
|
+
const category = registry[FLAG_ID]?.category ?? 'quiet';
|
|
86
|
+
const restoreBytes = options.restoreBytes ?? raw;
|
|
87
|
+
let tmpSequence = 0;
|
|
88
|
+
/**
|
|
89
|
+
* Every mutation — forward write AND restore — goes through tmp+rename.
|
|
90
|
+
* An in-place `writeFileSync(configPath, ...)` can leave a truncated
|
|
91
|
+
* config.yaml if the process dies mid-write, which is exactly the state the
|
|
92
|
+
* restore path exists to prevent. Returns the failure message, or null.
|
|
93
|
+
*/
|
|
94
|
+
const atomicWrite = (content) => {
|
|
95
|
+
tmpSequence += 1;
|
|
96
|
+
const tmpPath = configPath + '.tmp-wbsetup-' + String(process.pid) + '-' + String(Date.now()) + '-' + String(tmpSequence);
|
|
97
|
+
try {
|
|
98
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
99
|
+
fs.writeFileSync(tmpPath, content, { encoding: 'utf8' });
|
|
100
|
+
fs.renameSync(tmpPath, configPath);
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
try {
|
|
105
|
+
fs.rmSync(tmpPath, { force: true });
|
|
106
|
+
}
|
|
107
|
+
catch { /* best effort */ }
|
|
108
|
+
return error instanceof Error ? error.message : String(error);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Shared commit: atomic write, production-loader round-trip verification and
|
|
113
|
+
* an atomic restore of the pre-mutation bytes on any mismatch, so a failed
|
|
114
|
+
* run leaves the file as the Owner last saw it.
|
|
115
|
+
*/
|
|
116
|
+
const commit = (nextContent) => {
|
|
117
|
+
const writeFailure = atomicWrite(nextContent);
|
|
118
|
+
if (writeFailure !== null) {
|
|
119
|
+
return { ok: false, reason: 'config_write_failed:' + writeFailure.slice(0, 160), nextAction: 'Check permissions on ' + path.dirname(configPath) + '; config.yaml was left unchanged.' };
|
|
120
|
+
}
|
|
121
|
+
const verification = loadPdConfigForPlugin(workspaceDir);
|
|
122
|
+
const verified = verification.ok ? isFeatureEnabled(computeFeatureFlagsFromConfig(verification.effective), FLAG_ID) : undefined;
|
|
123
|
+
if (!verification.ok || verified !== enabled) {
|
|
124
|
+
const restoreFailure = atomicWrite(restoreBytes);
|
|
125
|
+
return {
|
|
126
|
+
ok: false,
|
|
127
|
+
reason: verification.ok ? 'config_roundtrip_mismatch' : 'config_roundtrip_invalid:' + (verification.errors[0]?.reason ?? 'unknown'),
|
|
128
|
+
restored: restoreFailure === null,
|
|
129
|
+
nextAction: restoreFailure === null
|
|
130
|
+
? 'config.yaml was restored to its pre-command bytes. Fix the features block in ' + configPath + ' and re-run `' + SETUP_COMMAND + '`.'
|
|
131
|
+
: 'WARNING: config.yaml could not be restored (' + restoreFailure.slice(0, 120) + '); repair ' + configPath + ' manually before re-running `' + SETUP_COMMAND + '`.',
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return { ok: true };
|
|
135
|
+
};
|
|
136
|
+
// JSON is a valid YAML subset and is what some installers/fixtures write.
|
|
137
|
+
// A line-targeted edit cannot see a `features:` line there, so update the
|
|
138
|
+
// parsed object instead — every other key is preserved verbatim.
|
|
139
|
+
if (raw.trim().startsWith('{')) {
|
|
140
|
+
let parsed;
|
|
141
|
+
try {
|
|
142
|
+
parsed = JSON.parse(raw);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return { ok: false, reason: 'config_json_invalid', nextAction: 'Repair ' + configPath + ' (it is neither valid JSON nor YAML), then re-run `' + SETUP_COMMAND + '`.' };
|
|
146
|
+
}
|
|
147
|
+
if (!isPlainObject(parsed) || !isPlainObject(parsed.features)) {
|
|
148
|
+
return { ok: false, reason: 'config_features_section_missing', nextAction: 'Add a features mapping to ' + configPath + ', then re-run `' + SETUP_COMMAND + '`.' };
|
|
149
|
+
}
|
|
150
|
+
const features = parsed.features;
|
|
151
|
+
const existing = features[FLAG_ID];
|
|
152
|
+
features[FLAG_ID] = { ...(isPlainObject(existing) ? existing : {}), category, enabled };
|
|
153
|
+
return commit(JSON.stringify(parsed));
|
|
154
|
+
}
|
|
155
|
+
const lineEnding = raw.includes('\r\n') ? '\r\n' : '\n';
|
|
156
|
+
const lines = raw.replace(/\r\n/g, '\n').split('\n');
|
|
157
|
+
const block = [' ' + FLAG_ID + ':', ' category: ' + category, ' enabled: ' + String(enabled)];
|
|
158
|
+
const featuresIndex = lines.findIndex((line) => FEATURES_LINE.test(line) || stripComment(line).replace(/\s+/g, '') === 'features:{}');
|
|
159
|
+
if (featuresIndex === -1) {
|
|
160
|
+
return { ok: false, reason: 'config_features_section_missing', nextAction: 'Add a features section to ' + configPath + ', then re-run `' + SETUP_COMMAND + '`.' };
|
|
161
|
+
}
|
|
162
|
+
const featuresLine = lines[featuresIndex];
|
|
163
|
+
if (featuresLine === undefined) {
|
|
164
|
+
return { ok: false, reason: 'config_features_line_undefined', nextAction: 'config.yaml was left unchanged; re-run `' + SETUP_COMMAND + '`.' };
|
|
165
|
+
}
|
|
166
|
+
let mutated = false;
|
|
167
|
+
if (stripComment(featuresLine).replace(/\s+/g, '') === 'features:{}') {
|
|
168
|
+
lines.splice(featuresIndex, 1, 'features:', ...block);
|
|
169
|
+
mutated = true;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
let keyIndex = -1;
|
|
173
|
+
let blockEnd = lines.length;
|
|
174
|
+
for (let i = featuresIndex + 1; i < lines.length; i += 1) {
|
|
175
|
+
const line = lines[i];
|
|
176
|
+
if (line === undefined || line.trim() === '')
|
|
177
|
+
continue;
|
|
178
|
+
if (KEY_LINE.test(line)) {
|
|
179
|
+
keyIndex = i;
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (keyIndex !== -1 && /^( {0,1}\S| {2}\S)/.test(line)) {
|
|
183
|
+
blockEnd = i;
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (keyIndex === -1) {
|
|
188
|
+
lines.splice(featuresIndex + 1, 0, ...block);
|
|
189
|
+
mutated = true;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
let enabledFound = false;
|
|
193
|
+
for (let i = keyIndex + 1; i < blockEnd; i += 1) {
|
|
194
|
+
const current = lines[i];
|
|
195
|
+
if (current === undefined || !ENABLED_LINE.test(current))
|
|
196
|
+
continue;
|
|
197
|
+
enabledFound = true;
|
|
198
|
+
const comment = current.indexOf(' #');
|
|
199
|
+
const next = ' enabled: ' + String(enabled) + (comment === -1 ? '' : ' ' + current.slice(comment + 1));
|
|
200
|
+
if (current !== next) {
|
|
201
|
+
lines[i] = next;
|
|
202
|
+
mutated = true;
|
|
203
|
+
}
|
|
204
|
+
break;
|
|
205
|
+
}
|
|
206
|
+
if (!enabledFound) {
|
|
207
|
+
lines.splice(keyIndex + 1, 0, ' enabled: ' + String(enabled));
|
|
208
|
+
mutated = true;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (!mutated)
|
|
213
|
+
return { ok: true };
|
|
214
|
+
return commit(lines.join(lineEnding));
|
|
215
|
+
}
|
|
216
|
+
function consentInput(decision, evidenceRef) {
|
|
217
|
+
return {
|
|
218
|
+
decision,
|
|
219
|
+
decidedVia: 'owner_directive',
|
|
220
|
+
disclosureVersion: WORKBUDDY_INGESTION_DISCLOSURE_VERSION,
|
|
221
|
+
evidenceRef,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* `pd workbuddy setup` entry point: read the current consent/flag state, then
|
|
226
|
+
* grant or revoke WorkBuddy ingestion and report what changed.
|
|
227
|
+
*
|
|
228
|
+
* Emits exactly one machine-readable JSON object under `--json` (cli-1) and
|
|
229
|
+
* sets exit code 1 only for a degraded outcome.
|
|
230
|
+
*/
|
|
231
|
+
export async function handleWorkbuddySetup(options) {
|
|
232
|
+
const generatedAt = new Date().toISOString();
|
|
233
|
+
// OD-07 / SPEC §4.1: the WorkBuddy runtime (Stop hook AND worker) reads a
|
|
234
|
+
// single user-level governance workspace. Defaulting to the generic CLI
|
|
235
|
+
// workspace here would write consent somewhere the hook never reads, so the
|
|
236
|
+
// default must use the SAME resolution; an explicit --workspace still wins.
|
|
237
|
+
const workspace = options.workspace !== undefined && options.workspace.trim().length > 0
|
|
238
|
+
? resolveWorkspaceDir(options.workspace)
|
|
239
|
+
: getWorkbuddyWorkspaceDir(os.homedir());
|
|
240
|
+
/** Print the final report (JSON or human) and set the process exit code. */
|
|
241
|
+
const finish = (report) => {
|
|
242
|
+
if (options.json === true) {
|
|
243
|
+
console.log(JSON.stringify(report));
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
const lines = [
|
|
247
|
+
'WorkBuddy conversation-ingestion setup (' + report.workspace + ')',
|
|
248
|
+
' status: ' + report.status,
|
|
249
|
+
' disclosureVersion: ' + report.disclosureVersion,
|
|
250
|
+
' consent (before): ' + report.consentStateBefore,
|
|
251
|
+
' consent (now): ' + report.consentState,
|
|
252
|
+
' ingestion flag: ' + String(report.ingestionFlag.enabled),
|
|
253
|
+
' host.workbuddy: ' + String(report.hostWorkbuddyFlagEnabled),
|
|
254
|
+
];
|
|
255
|
+
for (const warning of report.warnings)
|
|
256
|
+
lines.push(' warning: ' + warning);
|
|
257
|
+
if (report.reason !== undefined)
|
|
258
|
+
lines.push(' reason: ' + report.reason);
|
|
259
|
+
if (report.nextAction !== undefined)
|
|
260
|
+
lines.push(' next action: ' + report.nextAction);
|
|
261
|
+
console.log(lines.join('\n'));
|
|
262
|
+
}
|
|
263
|
+
if (report.status === 'degraded')
|
|
264
|
+
process.exitCode = 1;
|
|
265
|
+
};
|
|
266
|
+
const refuse = (reason, nextAction, detail = {}) => {
|
|
267
|
+
const { consentStateBefore: before, actualFlags } = detail;
|
|
268
|
+
const consentStateBefore = before ?? 'not_present';
|
|
269
|
+
finish({
|
|
270
|
+
generatedAt, host: 'workbuddy', workspace, status: 'degraded',
|
|
271
|
+
consentStateBefore, consentState: consentStateBefore,
|
|
272
|
+
disclosureVersion: WORKBUDDY_INGESTION_DISCLOSURE_VERSION,
|
|
273
|
+
// A rolled-back failure can leave the flag ON (rollback itself failed).
|
|
274
|
+
// Report the state we actually know, never a comforting `false`.
|
|
275
|
+
ingestionFlag: { name: FLAG_ID, enabled: actualFlags?.ingestionFlagEnabled ?? false },
|
|
276
|
+
hostWorkbuddyFlagEnabled: actualFlags?.hostWorkbuddyFlagEnabled ?? false,
|
|
277
|
+
warnings: [], reason, nextAction,
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
// cli-1/cli-5 (P2 review): `--show-disclosure` is a read-only early exit and
|
|
281
|
+
// cannot honour a decision or the JSON contract. Silently printing text made
|
|
282
|
+
// `--show-disclosure --accept` exit 0 without recording consent, and made
|
|
283
|
+
// `--show-disclosure --json` emit non-JSON. Reject the combinations instead.
|
|
284
|
+
if (options.showDisclosure === true && (options.accept === true || options.decline === true || options.json === true)) {
|
|
285
|
+
refuse('show_disclosure_conflicts_with_decision', '--show-disclosure only prints the disclosure. Drop --accept/--decline/--json, or run `pd workbuddy setup --accept|--decline [--json]` to record a decision.');
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (options.showDisclosure === true) {
|
|
289
|
+
console.log(getWorkbuddyIngestionDisclosureText());
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (options.accept === true && options.decline === true) {
|
|
293
|
+
refuse('accept_decline_mutex', 'Pass either --accept or --decline, not both.');
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
if (options.json === true && options.accept !== true && options.decline !== true) {
|
|
297
|
+
refuse('decision_not_explicit', 'With --json a decision must be explicit: pass --accept or --decline.');
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
if (options.accept === true) {
|
|
301
|
+
// Accepting must never skip the disclosure: print it before any mutation.
|
|
302
|
+
// `--json` keeps stdout machine-readable (cli-1), so there it goes to
|
|
303
|
+
// stderr — the same split the Codex setup uses for its human channel.
|
|
304
|
+
const disclosure = getWorkbuddyIngestionDisclosureText();
|
|
305
|
+
if (options.json === true)
|
|
306
|
+
console.error(disclosure);
|
|
307
|
+
else
|
|
308
|
+
console.log(disclosure);
|
|
309
|
+
}
|
|
310
|
+
const configPath = getPdConfigPath(workspace);
|
|
311
|
+
if (!fs.existsSync(configPath)) {
|
|
312
|
+
refuse('workspace_config_not_found', 'No .pd/config.yaml at ' + workspace + '. Run `pd runtime init --confirm` first.');
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const configLoad = loadPdConfigForPlugin(workspace);
|
|
316
|
+
if (!configLoad.ok) {
|
|
317
|
+
refuse('workspace_config_malformed:' + (configLoad.errors[0]?.reason ?? 'unknown'), 'Fix .pd/config.yaml before granting consent; nothing was mutated.');
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
const flags = computeFeatureFlagsFromConfig(configLoad.effective);
|
|
321
|
+
const flagEnabledBefore = isFeatureEnabled(flags, FLAG_ID);
|
|
322
|
+
const hostEnabled = isFeatureEnabled(flags, 'host.workbuddy');
|
|
323
|
+
const consentRead = readConversationIngestionConsent(workspace, 'workbuddy');
|
|
324
|
+
if (!consentRead.ok) {
|
|
325
|
+
refuse(consentRead.reason, consentRead.nextAction);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const stateBefore = deriveConversationIngestionConsentState(consentRead.record, flagEnabledBefore);
|
|
329
|
+
// No explicit decision: report-only, never mutate (cli-5).
|
|
330
|
+
if (options.accept !== true && options.decline !== true) {
|
|
331
|
+
console.log(getWorkbuddyIngestionDisclosureText());
|
|
332
|
+
finish({
|
|
333
|
+
generatedAt, host: 'workbuddy', workspace, status: 'ok',
|
|
334
|
+
consentStateBefore: stateBefore, consentState: stateBefore,
|
|
335
|
+
disclosureVersion: WORKBUDDY_INGESTION_DISCLOSURE_VERSION,
|
|
336
|
+
ingestionFlag: { name: FLAG_ID, enabled: flagEnabledBefore }, hostWorkbuddyFlagEnabled: hostEnabled,
|
|
337
|
+
warnings: hostEnabled ? [] : ['host.workbuddy is off: ingestion stays gated even after consent is granted.'],
|
|
338
|
+
});
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const decision = options.accept === true ? 'granted' : 'revoked';
|
|
342
|
+
const targetFlag = decision === 'granted';
|
|
343
|
+
// Capture the pre-mutation bytes BEFORE the first write: if the consent
|
|
344
|
+
// write fails, the rollback restores this exact state, not the intermediate
|
|
345
|
+
// flag flip this command just made.
|
|
346
|
+
let originalConfigBytes;
|
|
347
|
+
try {
|
|
348
|
+
originalConfigBytes = fs.readFileSync(configPath, 'utf8');
|
|
349
|
+
}
|
|
350
|
+
catch { /* pre-checked above; leave undefined */ }
|
|
351
|
+
const flagWrite = setWorkbuddyIngestionFlag(workspace, targetFlag);
|
|
352
|
+
if (!flagWrite.ok) {
|
|
353
|
+
refuse(flagWrite.reason, flagWrite.nextAction, { consentStateBefore: stateBefore });
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const recorded = recordConversationIngestionConsent(workspace, 'workbuddy', consentInput(decision, '`' + SETUP_COMMAND + ' --' + (decision === 'granted' ? 'accept' : 'decline') + '` at ' + generatedAt));
|
|
357
|
+
if (!recorded.ok) {
|
|
358
|
+
// Never leave a flag enabled without its grant (or a revocation without
|
|
359
|
+
// its flag off): roll the config back to the previous value.
|
|
360
|
+
const rollback = setWorkbuddyIngestionFlag(workspace, flagEnabledBefore, originalConfigBytes !== undefined ? { restoreBytes: originalConfigBytes } : {});
|
|
361
|
+
const rollbackOk = rollback.ok || rollback.restored === true;
|
|
362
|
+
refuse('consent_write_failed:' + recorded.reason, recorded.nextAction + (rollbackOk
|
|
363
|
+
? ' The ingestion flag was rolled back.'
|
|
364
|
+
: ' WARNING: the ingestion flag could NOT be rolled back; disable it manually.'), {
|
|
365
|
+
consentStateBefore: stateBefore,
|
|
366
|
+
actualFlags: { ingestionFlagEnabled: rollbackOk ? flagEnabledBefore : targetFlag, hostWorkbuddyFlagEnabled: hostEnabled },
|
|
367
|
+
});
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
const stateAfter = deriveConversationIngestionConsentState(recorded.record, targetFlag);
|
|
371
|
+
finish({
|
|
372
|
+
generatedAt, host: 'workbuddy', workspace, status: 'ok', decision,
|
|
373
|
+
consentStateBefore: stateBefore, consentState: stateAfter,
|
|
374
|
+
disclosureVersion: WORKBUDDY_INGESTION_DISCLOSURE_VERSION,
|
|
375
|
+
ingestionFlag: { name: FLAG_ID, enabled: targetFlag }, hostWorkbuddyFlagEnabled: hostEnabled,
|
|
376
|
+
warnings: decision === 'granted' && !hostEnabled ? ['host.workbuddy is off: no transcript will be read until the host master switch is enabled.'] : [],
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
//# sourceMappingURL=workbuddy-setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workbuddy-setup.js","sourceRoot":"","sources":["../../src/commands/workbuddy-setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;A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