@productbrain/cli 0.1.0-beta.7278 → 0.1.0-beta.7288

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.
Files changed (101) hide show
  1. package/dist/__tests__/onboarding.test.js +4 -1
  2. package/dist/__tests__/onboarding.test.js.map +1 -1
  3. package/dist/__tests__/session-close-loop.test.js +0 -2
  4. package/dist/__tests__/session-close-loop.test.js.map +1 -1
  5. package/dist/commands/handshake.js +2 -2
  6. package/dist/commands/handshake.js.map +1 -1
  7. package/dist/commands/init.d.ts.map +1 -1
  8. package/dist/commands/init.js +2 -4
  9. package/dist/commands/init.js.map +1 -1
  10. package/dist/commands/session.d.ts.map +1 -1
  11. package/dist/commands/session.js +0 -18
  12. package/dist/commands/session.js.map +1 -1
  13. package/dist/formatters/digest.d.ts.map +1 -1
  14. package/dist/formatters/digest.js +9 -5
  15. package/dist/formatters/digest.js.map +1 -1
  16. package/dist/index.js +1 -62
  17. package/dist/index.js.map +1 -1
  18. package/dist/lib/onboarding-shared.d.ts.map +1 -1
  19. package/dist/lib/onboarding-shared.js +8 -9
  20. package/dist/lib/onboarding-shared.js.map +1 -1
  21. package/dist/lib/onboarding-topics.js +1 -1
  22. package/dist/lib/onboarding.d.ts.map +1 -1
  23. package/dist/lib/onboarding.js +7 -13
  24. package/dist/lib/onboarding.js.map +1 -1
  25. package/package.json +1 -1
  26. package/dist/__tests__/migrate-setup-session-refusal.test.d.ts +0 -2
  27. package/dist/__tests__/migrate-setup-session-refusal.test.d.ts.map +0 -1
  28. package/dist/__tests__/migrate-setup-session-refusal.test.js +0 -65
  29. package/dist/__tests__/migrate-setup-session-refusal.test.js.map +0 -1
  30. package/dist/__tests__/setup-ingest.test.d.ts +0 -2
  31. package/dist/__tests__/setup-ingest.test.d.ts.map +0 -1
  32. package/dist/__tests__/setup-ingest.test.js +0 -71
  33. package/dist/__tests__/setup-ingest.test.js.map +0 -1
  34. package/dist/__tests__/setup-resolver.test.d.ts +0 -14
  35. package/dist/__tests__/setup-resolver.test.d.ts.map +0 -1
  36. package/dist/__tests__/setup-resolver.test.js +0 -228
  37. package/dist/__tests__/setup-resolver.test.js.map +0 -1
  38. package/dist/__tests__/setupShFallbackWarning.test.d.ts +0 -2
  39. package/dist/__tests__/setupShFallbackWarning.test.d.ts.map +0 -1
  40. package/dist/__tests__/setupShFallbackWarning.test.js +0 -15
  41. package/dist/__tests__/setupShFallbackWarning.test.js.map +0 -1
  42. package/dist/commands/__tests__/setup-detect-surfaces.test.d.ts +0 -15
  43. package/dist/commands/__tests__/setup-detect-surfaces.test.d.ts.map +0 -1
  44. package/dist/commands/__tests__/setup-detect-surfaces.test.js +0 -149
  45. package/dist/commands/__tests__/setup-detect-surfaces.test.js.map +0 -1
  46. package/dist/commands/__tests__/setup-state.test.d.ts +0 -2
  47. package/dist/commands/__tests__/setup-state.test.d.ts.map +0 -1
  48. package/dist/commands/__tests__/setup-state.test.js +0 -194
  49. package/dist/commands/__tests__/setup-state.test.js.map +0 -1
  50. package/dist/commands/migrate-setup.d.ts +0 -18
  51. package/dist/commands/migrate-setup.d.ts.map +0 -1
  52. package/dist/commands/migrate-setup.js +0 -162
  53. package/dist/commands/migrate-setup.js.map +0 -1
  54. package/dist/commands/setup-audit.d.ts +0 -59
  55. package/dist/commands/setup-audit.d.ts.map +0 -1
  56. package/dist/commands/setup-audit.js +0 -250
  57. package/dist/commands/setup-audit.js.map +0 -1
  58. package/dist/commands/setup-detect-surfaces.d.ts +0 -38
  59. package/dist/commands/setup-detect-surfaces.d.ts.map +0 -1
  60. package/dist/commands/setup-detect-surfaces.js +0 -76
  61. package/dist/commands/setup-detect-surfaces.js.map +0 -1
  62. package/dist/commands/setup-ingest.d.ts +0 -17
  63. package/dist/commands/setup-ingest.d.ts.map +0 -1
  64. package/dist/commands/setup-ingest.js +0 -179
  65. package/dist/commands/setup-ingest.js.map +0 -1
  66. package/dist/commands/setup-resolver.d.ts +0 -58
  67. package/dist/commands/setup-resolver.d.ts.map +0 -1
  68. package/dist/commands/setup-resolver.js +0 -150
  69. package/dist/commands/setup-resolver.js.map +0 -1
  70. package/dist/commands/setup-state.d.ts +0 -42
  71. package/dist/commands/setup-state.d.ts.map +0 -1
  72. package/dist/commands/setup-state.js +0 -93
  73. package/dist/commands/setup-state.js.map +0 -1
  74. package/dist/commands/setup.d.ts +0 -23
  75. package/dist/commands/setup.d.ts.map +0 -1
  76. package/dist/commands/setup.js +0 -69
  77. package/dist/commands/setup.js.map +0 -1
  78. package/dist/setup/__tests__/coach-traces.test.d.ts +0 -2
  79. package/dist/setup/__tests__/coach-traces.test.d.ts.map +0 -1
  80. package/dist/setup/__tests__/coach-traces.test.js +0 -189
  81. package/dist/setup/__tests__/coach-traces.test.js.map +0 -1
  82. package/dist/setup/__tests__/setup-commands.test.d.ts +0 -2
  83. package/dist/setup/__tests__/setup-commands.test.d.ts.map +0 -1
  84. package/dist/setup/__tests__/setup-commands.test.js +0 -177
  85. package/dist/setup/__tests__/setup-commands.test.js.map +0 -1
  86. package/dist/setup/__tests__/state-machine.test.d.ts +0 -2
  87. package/dist/setup/__tests__/state-machine.test.d.ts.map +0 -1
  88. package/dist/setup/__tests__/state-machine.test.js +0 -341
  89. package/dist/setup/__tests__/state-machine.test.js.map +0 -1
  90. package/dist/setup/detect-surfaces.d.ts +0 -21
  91. package/dist/setup/detect-surfaces.d.ts.map +0 -1
  92. package/dist/setup/detect-surfaces.js +0 -39
  93. package/dist/setup/detect-surfaces.js.map +0 -1
  94. package/dist/setup/manifest-writer.d.ts +0 -17
  95. package/dist/setup/manifest-writer.d.ts.map +0 -1
  96. package/dist/setup/manifest-writer.js +0 -153
  97. package/dist/setup/manifest-writer.js.map +0 -1
  98. package/dist/setup/state-machine.d.ts +0 -67
  99. package/dist/setup/state-machine.d.ts.map +0 -1
  100. package/dist/setup/state-machine.js +0 -124
  101. package/dist/setup/state-machine.js.map +0 -1
@@ -1,58 +0,0 @@
1
- /**
2
- * WP-336 E2 (CLI side): Dual-mode setup asset resolver for `pb handshake`.
3
- *
4
- * SetupMode:
5
- * local — reads skills/rules from .productbrain/ (current builder behavior, default).
6
- * chain — calls the Convex API (setup.getActiveSurface) and returns Chain-backed assets.
7
- *
8
- * The env var PB_SETUP_MODE controls which path runs:
9
- * unset or 'local' → local mode (no network call, fully offline-safe)
10
- * 'chain' → chain mode (requires authenticated kernelCall, user workspace)
11
- *
12
- * Chain: WP-336 (Agent Surface Foundation), DEC-619 (setup_receipt infrastructure)
13
- */
14
- export type SetupMode = 'local' | 'chain';
15
- /**
16
- * Unified asset shape returned by resolveSetupAssets.
17
- *
18
- * Local mode: assetKind derived from .productbrain/ directory (skills/ → 'skill', rules/ → 'rule').
19
- * Chain mode: assetKind comes from the entry's data.assetKind field (seeded by WP-336 E3 seed).
20
- *
21
- * The `body` field is the raw Markdown content that gets written to adapter files.
22
- * The `source` field is informational — used for reporting/telemetry, not for write decisions.
23
- */
24
- export interface SetupAsset {
25
- assetKind: 'skill' | 'rule' | 'hook';
26
- displayName: string;
27
- body: string;
28
- source: 'seeded' | 'authored' | 'imported';
29
- }
30
- /**
31
- * Wire shape returned by the Convex getActiveSurface query.
32
- * Must match the return type of convex/setup.ts:getActiveSurface.
33
- */
34
- export interface GetActiveSurfaceResult {
35
- assetId: string;
36
- assetKind: string;
37
- displayName: string;
38
- shortDescription: string;
39
- body: string;
40
- version: number;
41
- source: string;
42
- }
43
- /**
44
- * Returns the active SetupMode.
45
- * Reads PB_SETUP_MODE from process.env.
46
- * Unknown values default to 'local' (fail-open for forward compat).
47
- */
48
- export declare function getSetupMode(): SetupMode;
49
- /**
50
- * Resolve setup assets for the current mode.
51
- *
52
- * @param mode - 'local' | 'chain', from getSetupMode()
53
- * @param kernelCall - authenticated kernelCall function (from packages/cli/src/lib/client.ts)
54
- * Only called in chain mode.
55
- * @param cwd - current working directory (for .productbrain/ path resolution)
56
- */
57
- export declare function resolveSetupAssets(mode: SetupMode, kernelCall: <T>(fn: string, args: Record<string, unknown>) => Promise<T>, cwd: string): Promise<SetupAsset[]>;
58
- //# sourceMappingURL=setup-resolver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup-resolver.d.ts","sourceRoot":"","sources":["../../src/commands/setup-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAOH,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAE1C;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC;CAC5C;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAID;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,SAAS,CAIxC;AA6HD;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,SAAS,EACf,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EACxE,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,UAAU,EAAE,CAAC,CAQvB"}
@@ -1,150 +0,0 @@
1
- /**
2
- * WP-336 E2 (CLI side): Dual-mode setup asset resolver for `pb handshake`.
3
- *
4
- * SetupMode:
5
- * local — reads skills/rules from .productbrain/ (current builder behavior, default).
6
- * chain — calls the Convex API (setup.getActiveSurface) and returns Chain-backed assets.
7
- *
8
- * The env var PB_SETUP_MODE controls which path runs:
9
- * unset or 'local' → local mode (no network call, fully offline-safe)
10
- * 'chain' → chain mode (requires authenticated kernelCall, user workspace)
11
- *
12
- * Chain: WP-336 (Agent Surface Foundation), DEC-619 (setup_receipt infrastructure)
13
- */
14
- import { existsSync, readdirSync, readFileSync } from 'fs';
15
- import { join, basename } from 'path';
16
- // ── Mode resolution ───────────────────────────────────────────────────────────
17
- /**
18
- * Returns the active SetupMode.
19
- * Reads PB_SETUP_MODE from process.env.
20
- * Unknown values default to 'local' (fail-open for forward compat).
21
- */
22
- export function getSetupMode() {
23
- const raw = process.env.PB_SETUP_MODE;
24
- if (raw === 'chain')
25
- return 'chain';
26
- return 'local';
27
- }
28
- // ── Local mode ────────────────────────────────────────────────────────────────
29
- /**
30
- * Read a single Markdown file from a .productbrain/ sub-directory.
31
- * Returns the file body after stripping a minimal YAML frontmatter block
32
- * (lines between opening and closing ---). If no frontmatter is found,
33
- * returns the full file content unchanged.
34
- *
35
- * We intentionally keep this light — the local mode is a contract test pass-through
36
- * that verifies parity with the existing handshake.ts lines 443–507 pipeline.
37
- */
38
- function stripFrontmatter(raw) {
39
- const lines = raw.split('\n');
40
- if (lines[0]?.trim() !== '---')
41
- return raw;
42
- const closeIdx = lines.indexOf('---', 1);
43
- if (closeIdx === -1)
44
- return raw;
45
- return lines.slice(closeIdx + 1).join('\n').trimStart();
46
- }
47
- /**
48
- * Read skills from .productbrain/skills/ and map them to SetupAsset[].
49
- * Mirrors the shape produced by readCanonicalSkills() in portable-knowledge.ts.
50
- * Does NOT apply level/stage filtering — that remains in the handshake pipeline.
51
- */
52
- function readLocalSkillAssets(pbDir) {
53
- const skillsDir = join(pbDir, 'skills');
54
- if (!existsSync(skillsDir))
55
- return [];
56
- const files = readdirSync(skillsDir).filter((f) => f.endsWith('.md'));
57
- return files.map((file) => {
58
- const raw = readFileSync(join(skillsDir, file), 'utf8');
59
- const displayName = basename(file, '.md');
60
- return {
61
- assetKind: 'skill',
62
- displayName,
63
- body: stripFrontmatter(raw),
64
- source: 'authored',
65
- };
66
- });
67
- }
68
- /**
69
- * Read rules from .productbrain/rules/ and map them to SetupAsset[].
70
- * Mirrors the shape produced by readCanonicalRules() in portable-knowledge.ts.
71
- */
72
- function readLocalRuleAssets(pbDir) {
73
- const rulesDir = join(pbDir, 'rules');
74
- if (!existsSync(rulesDir))
75
- return [];
76
- const files = readdirSync(rulesDir).filter((f) => f.endsWith('.md'));
77
- return files.map((file) => {
78
- const raw = readFileSync(join(rulesDir, file), 'utf8');
79
- const displayName = basename(file, '.md');
80
- return {
81
- assetKind: 'rule',
82
- displayName,
83
- body: stripFrontmatter(raw),
84
- source: 'authored',
85
- };
86
- });
87
- }
88
- /**
89
- * Local mode: return skills + rules from .productbrain/.
90
- *
91
- * This is the identity pass-through — the assets returned here are the same
92
- * files that handshake.ts lines 443–507 already read via readCanonicalSkills()
93
- * and readCanonicalRules(). The resolver does NOT replace those calls; it is a
94
- * parallel view used for contract testing and mode-switching.
95
- */
96
- function resolveLocalAssets(pbDir) {
97
- return [
98
- ...readLocalSkillAssets(pbDir),
99
- ...readLocalRuleAssets(pbDir),
100
- ];
101
- }
102
- // ── Chain mode ────────────────────────────────────────────────────────────────
103
- /**
104
- * Map a raw GetActiveSurfaceResult to a typed SetupAsset.
105
- * Falls back gracefully on unexpected assetKind values.
106
- */
107
- function mapChainAsset(raw) {
108
- const assetKind = raw.assetKind === 'rule' ? 'rule'
109
- : raw.assetKind === 'hook' ? 'hook'
110
- : 'skill'; // default — skill is the safe fallback
111
- const source = raw.source === 'authored' ? 'authored'
112
- : raw.source === 'imported' ? 'imported'
113
- : 'seeded';
114
- return {
115
- assetKind,
116
- displayName: raw.displayName,
117
- body: raw.body,
118
- source,
119
- };
120
- }
121
- /**
122
- * Chain mode: call setup.getActiveSurface via the AKI gateway and return assets.
123
- *
124
- * workspaceId is injected server-side by the gateway (BR-18).
125
- * personId is injected server-side by injectSessionAuth — the CLI does not pass it.
126
- *
127
- * @param kernelCall - the authenticated kernelCall function from the handshake flow
128
- */
129
- async function resolveChainAssets(kernelCall) {
130
- const results = await kernelCall('setup.getActiveSurface', {});
131
- return results.map(mapChainAsset);
132
- }
133
- // ── Public API ────────────────────────────────────────────────────────────────
134
- /**
135
- * Resolve setup assets for the current mode.
136
- *
137
- * @param mode - 'local' | 'chain', from getSetupMode()
138
- * @param kernelCall - authenticated kernelCall function (from packages/cli/src/lib/client.ts)
139
- * Only called in chain mode.
140
- * @param cwd - current working directory (for .productbrain/ path resolution)
141
- */
142
- export async function resolveSetupAssets(mode, kernelCall, cwd) {
143
- if (mode === 'chain') {
144
- return resolveChainAssets(kernelCall);
145
- }
146
- // local mode — read from .productbrain/ (synchronous, no network)
147
- const pbDir = join(cwd, '.productbrain');
148
- return resolveLocalAssets(pbDir);
149
- }
150
- //# sourceMappingURL=setup-resolver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup-resolver.js","sourceRoot":"","sources":["../../src/commands/setup-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAoCtC,iFAAiF;AAEjF;;;;GAIG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IACtC,IAAI,GAAG,KAAK,OAAO;QAAE,OAAO,OAAO,CAAC;IACpC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,iFAAiF;AAEjF;;;;;;;;GAQG;AACH,SAAS,gBAAgB,CAAC,GAAW;IACnC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,KAAK;QAAE,OAAO,GAAG,CAAC;IAC3C,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AAkB,CAC/B,UAAwE;IAExE,MAAM,OAAO,GAAG,MAAM,UAAU,CAC9B,wBAAwB,EACxB,EAAE,CACH,CAAC;IAEF,OAAO,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;AACpC,CAAC;AAED,iFAAiF;AAEjF;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAAe,EACf,UAAwE,EACxE,GAAW;IAEX,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACrB,OAAO,kBAAkB,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAED,kEAAkE;IAClE,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IACzC,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC"}
@@ -1,42 +0,0 @@
1
- /**
2
- * `pb setup-state` — WP-431 S3.
3
- *
4
- * Calls the Convex `getPbSetupState` query and emits the result as compact JSON
5
- * on stdout. Machine-readable always — the skill body parses this.
6
- *
7
- * Auth & userId injection (STD-234 perimeter):
8
- * The HTTP gateway derives `workspaceId` and `userId` from the API key and
9
- * passes them server-side; the CLI does not need to know the user's id.
10
- * Defense-in-depth equality check happens inside the query handler.
11
- *
12
- * Exit codes (CLI convention):
13
- * 0 success — JSON written to stdout
14
- * 2 auth/permission — AUTH_* / AUTHZ_* error class
15
- * 3 network — host unreachable / fetch failed
16
- * 1 other (validation / internal)
17
- */
18
- export interface RunSetupStateOptions {
19
- /** Pre-fetched state — used by `pb setup` to avoid a duplicate gateway round-trip. */
20
- preloaded?: SetupStateResult;
21
- }
22
- export interface SetupStateResult {
23
- phase: number | 'settings';
24
- role: 'creator' | 'joiner';
25
- expectedAction: string;
26
- reasonForPhase: string;
27
- isComplete: boolean;
28
- /**
29
- * WP-431 S3 review fix #1: structural surfaceCapability passthrough.
30
- * Mirrors the resolver output (PbSetupStateOutput.surfaceCapability).
31
- */
32
- surfaceCapability: 'cli' | 'chat-only';
33
- }
34
- export declare function fetchSetupState(): Promise<SetupStateResult>;
35
- export declare function runSetupState(opts?: RunSetupStateOptions): Promise<void>;
36
- /**
37
- * Map a setup-state failure to the documented exit-code contract.
38
- * Always re-throws (typed `never`) so the global handler in index.ts can format
39
- * the message; we route through CLIError so JSON mode reports `code` cleanly.
40
- */
41
- export declare function handleSetupError(err: unknown): never;
42
- //# sourceMappingURL=setup-state.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup-state.d.ts","sourceRoot":"","sources":["../../src/commands/setup-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAMH,MAAM,WAAW,oBAAoB;IACnC,sFAAsF;IACtF,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC;IAC3B,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,iBAAiB,EAAE,KAAK,GAAG,WAAW,CAAC;CACxC;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAEjE;AAED,wBAAsB,aAAa,CAAC,IAAI,GAAE,oBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CAQlF;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,CAiCpD"}
@@ -1,93 +0,0 @@
1
- /**
2
- * `pb setup-state` — WP-431 S3.
3
- *
4
- * Calls the Convex `getPbSetupState` query and emits the result as compact JSON
5
- * on stdout. Machine-readable always — the skill body parses this.
6
- *
7
- * Auth & userId injection (STD-234 perimeter):
8
- * The HTTP gateway derives `workspaceId` and `userId` from the API key and
9
- * passes them server-side; the CLI does not need to know the user's id.
10
- * Defense-in-depth equality check happens inside the query handler.
11
- *
12
- * Exit codes (CLI convention):
13
- * 0 success — JSON written to stdout
14
- * 2 auth/permission — AUTH_* / AUTHZ_* error class
15
- * 3 network — host unreachable / fetch failed
16
- * 1 other (validation / internal)
17
- */
18
- import { kernelCall, McpError } from '../lib/client.js';
19
- import { CLIError, ErrorCode } from '../lib/errors.js';
20
- export async function fetchSetupState() {
21
- return await kernelCall('setup.getPbSetupState', {});
22
- }
23
- export async function runSetupState(opts = {}) {
24
- let result;
25
- try {
26
- result = opts.preloaded ?? (await fetchSetupState());
27
- }
28
- catch (err) {
29
- handleSetupError(err);
30
- }
31
- process.stdout.write(JSON.stringify(result) + '\n');
32
- }
33
- /**
34
- * Map a setup-state failure to the documented exit-code contract.
35
- * Always re-throws (typed `never`) so the global handler in index.ts can format
36
- * the message; we route through CLIError so JSON mode reports `code` cleanly.
37
- */
38
- export function handleSetupError(err) {
39
- if (err instanceof McpError) {
40
- const code = err.code;
41
- if (code && (code.startsWith('AUTH') || code.startsWith('AUTHZ'))) {
42
- const wrapped = new CLIError(err.message, {
43
- code: ErrorCode.AUTH_DENIED,
44
- category: 'auth',
45
- guidance: 'Run `pb login` to refresh your API key, or check workspace membership.',
46
- });
47
- writeJsonError(wrapped);
48
- process.exit(2);
49
- }
50
- writeJsonError(err);
51
- process.exit(1);
52
- }
53
- if (err instanceof CLIError && err.category === 'network') {
54
- writeJsonError(err);
55
- process.exit(3);
56
- }
57
- if (err instanceof CLIError && err.category === 'auth') {
58
- writeJsonError(err);
59
- process.exit(2);
60
- }
61
- if (err instanceof CLIError) {
62
- writeJsonError(err);
63
- process.exit(1);
64
- }
65
- const wrapped = new CLIError(err instanceof Error ? err.message : String(err), {
66
- code: ErrorCode.INTERNAL,
67
- category: 'internal',
68
- });
69
- writeJsonError(wrapped);
70
- process.exit(1);
71
- }
72
- /**
73
- * Write a structured JSON error to stderr. WP-431 S3 review (Boy Scout #2):
74
- * route every shape through CLIError.toJSON() so the stderr envelope is
75
- * identical to every other CLI command (no per-call ad-hoc shapes).
76
- */
77
- function writeJsonError(err) {
78
- const cliErr = toCLIError(err);
79
- process.stderr.write(JSON.stringify(cliErr.toJSON()) + '\n');
80
- }
81
- function toCLIError(err) {
82
- if (err instanceof CLIError)
83
- return err;
84
- if (err instanceof Error) {
85
- const code = err.code;
86
- const errorCode = code && Object.values(ErrorCode).includes(code)
87
- ? code
88
- : ErrorCode.INTERNAL;
89
- return new CLIError(err.message, { code: errorCode, category: 'internal' });
90
- }
91
- return new CLIError(String(err), { code: ErrorCode.INTERNAL, category: 'internal' });
92
- }
93
- //# sourceMappingURL=setup-state.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup-state.js","sourceRoot":"","sources":["../../src/commands/setup-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAoBvD,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,OAAO,MAAM,UAAU,CAAoD,uBAAuB,EAAE,EAAE,CAAC,CAAC;AAC1G,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAA6B,EAAE;IACjE,IAAI,MAAwB,CAAC;IAC7B,IAAI,CAAC;QACH,MAAM,GAAG,IAAI,CAAC,SAAS,IAAI,CAAC,MAAM,eAAe,EAAE,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;AACtD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAY;IAC3C,IAAI,GAAG,YAAY,QAAQ,EAAE,CAAC;QAC5B,MAAM,IAAI,GAA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AAC,CAAC;IACH,cAAc,CAAC,OAAO,CAAC,CAAC;IACxB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc,CAAC,GAAY;IAClC,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;IAC/B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;AAC/D,CAAC;AAED,SAAS,UAAU,CAAC,GAAY;IAC9B,IAAI,GAAG,YAAY,QAAQ;QAAE,OAAO,GAAG,CAAC;IACxC,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,GAAI,GAAiC,CAAC,IAAI,CAAC;QACrD,MAAM,SAAS,GACb,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,IAAkD,CAAC;YAC3F,CAAC,CAAE,IAAmD;YACtD,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC;QACzB,OAAO,IAAI,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;AACvF,CAAC"}
@@ -1,23 +0,0 @@
1
- /**
2
- * `pb setup` — WP-431 S3 canonical entry point (DEC-995).
3
- *
4
- * Flow:
5
- * 1. Auto-detect surface markers and union-merge into `manifest.surfaces` (S3 #1).
6
- * Phase-1 users land here with empty surfaces; this single auto-detect lifts
7
- * them to Phase 2 without requiring a separate `pb setup-detect-surfaces` run.
8
- * 2. Read pb-setup state via the Convex query (`setup.getPbSetupState`).
9
- * 3. Record invocation receipt — first-write-wins per DEC-996, idempotent.
10
- * 4. Emit the resolved state JSON on stdout for the skill body to consume.
11
- *
12
- * `pb start` (session-start alias) is unchanged and keeps the same call path it
13
- * had before this slice.
14
- *
15
- * Legacy `pb setup` (WP-301) — guided onboarding via @clack/prompts — is removed
16
- * from the canonical entry per DEC-995. The login flow remains reachable via
17
- * `pb login`.
18
- */
19
- export interface RunSetupOptions {
20
- cwd?: string;
21
- }
22
- export declare function runSetup(opts?: RunSetupOptions): Promise<void>;
23
- //# sourceMappingURL=setup.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAOH,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAsB,QAAQ,CAAC,IAAI,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BxE"}
@@ -1,69 +0,0 @@
1
- /**
2
- * `pb setup` — WP-431 S3 canonical entry point (DEC-995).
3
- *
4
- * Flow:
5
- * 1. Auto-detect surface markers and union-merge into `manifest.surfaces` (S3 #1).
6
- * Phase-1 users land here with empty surfaces; this single auto-detect lifts
7
- * them to Phase 2 without requiring a separate `pb setup-detect-surfaces` run.
8
- * 2. Read pb-setup state via the Convex query (`setup.getPbSetupState`).
9
- * 3. Record invocation receipt — first-write-wins per DEC-996, idempotent.
10
- * 4. Emit the resolved state JSON on stdout for the skill body to consume.
11
- *
12
- * `pb start` (session-start alias) is unchanged and keeps the same call path it
13
- * had before this slice.
14
- *
15
- * Legacy `pb setup` (WP-301) — guided onboarding via @clack/prompts — is removed
16
- * from the canonical entry per DEC-995. The login flow remains reachable via
17
- * `pb login`.
18
- */
19
- import { runSetupDetectSurfaces, formatDetectSurfacesSummary } from './setup-detect-surfaces.js';
20
- import { fetchSetupState, handleSetupError } from './setup-state.js';
21
- import { kernelCall } from '../lib/client.js';
22
- export async function runSetup(opts = {}) {
23
- const cwd = opts.cwd ?? process.cwd();
24
- const isTty = Boolean(process.stdout.isTTY);
25
- let initialState;
26
- try {
27
- initialState = await fetchSetupState();
28
- }
29
- catch (err) {
30
- handleSetupError(err);
31
- }
32
- // Always record invocation — first-write-wins per DEC-996.
33
- await recordInvocationBestEffort(initialState);
34
- let finalState = initialState;
35
- if (initialState.phase === 1) {
36
- const detect = await runSetupDetectSurfaces({ cwd });
37
- if (isTty) {
38
- process.stderr.write(formatDetectSurfacesSummary(detect) + '\n');
39
- }
40
- if (detect.manifestUpdated) {
41
- try {
42
- finalState = await fetchSetupState();
43
- }
44
- catch (err) {
45
- handleSetupError(err);
46
- }
47
- }
48
- }
49
- process.stdout.write(JSON.stringify(finalState) + '\n');
50
- }
51
- async function recordInvocationBestEffort(state) {
52
- // WP-431 S3 review fix #1: surfaceCapability is now a structural field on the
53
- // resolver output (PbSetupStateOutput.surfaceCapability) — read it directly
54
- // rather than string-grepping reasonForPhase strings the producer never
55
- // emits. The pre-fix `inferSurfaceCapability` always returned 'cli' for
56
- // chat-only users, silently breaking OBJ-32 dual-threshold telemetry.
57
- const surfaceCapability = state.surfaceCapability;
58
- try {
59
- await kernelCall('setup.recordSetupInvocation', { surfaceCapability });
60
- }
61
- catch (err) {
62
- // Best-effort — invocation receipt is telemetry, never block the state
63
- // read. WP-431 S3 review (Boy Scout #1): log to stderr so a silent failure
64
- // doesn't strand OBJ-32 dual-threshold attribution.
65
- const message = err instanceof Error ? err.message : String(err);
66
- process.stderr.write(`[pb setup] invocation attribution failed: ${message}\n`);
67
- }
68
- }
69
- //# sourceMappingURL=setup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/commands/setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AACjG,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;IAC/D,8EAA8E;IAC9E,4EAA4E;IAC5E,wEAAwE;IACxE,wEAAwE;IACxE,sEAAsE;IACtE,MAAM,iBAAiB,GAAG,KAAK,CAAC,iBAAiB,CAAC;IAClD,IAAI,CAAC;QACH,MAAM,UAAU,CAA0D,6BAA6B,EAAE,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAClI,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,uEAAuE;QACvE,2EAA2E;QAC3E,oDAAoD;QACpD,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,6CAA6C,OAAO,IAAI,CAAC,CAAC;IACjF,CAAC;AACH,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=coach-traces.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"coach-traces.test.d.ts","sourceRoot":"","sources":["../../../src/setup/__tests__/coach-traces.test.ts"],"names":[],"mappings":""}
@@ -1,189 +0,0 @@
1
- /**
2
- * Cross-model coach validation harness — WP-431 S4 (doneWhen #16).
3
- *
4
- * Mock harness chosen for cross-model validation per TEN-1962 — deterministic,
5
- * runs in CI without API keys. Live trace via dev-only Cursor Desktop documented
6
- * separately if needed. The harness does NOT call any model; it simulates the
7
- * criteria-progression loop encoded in `.productbrain/skills/pb-setup.md`
8
- * Phase 3 and asserts convergence within 3 turns OR correct fallback to the
9
- * FLO-72 Path C wizard (DEC-991).
10
- *
11
- * The fixture set covers cross-model behaviour by encoding three response
12
- * shapes that any reasonable instruction-following model produces — the user's
13
- * answer is the variable, the agent's response loop is the constant. The
14
- * skill body is the universal SSOT (DEC-997); this harness exercises it.
15
- */
16
- import { describe, expect, it } from 'vitest';
17
- /**
18
- * Criteria check (verbatim from `.productbrain/skills/pb-setup.md` Phase 3):
19
- * "answer mentions a verb + a thing they do regularly".
20
- *
21
- * The criteria predicate keeps the test honest: it deterministically maps a
22
- * user utterance to met/not-met. The tokeniser is intentionally simple — the
23
- * skill text says "verb + thing", and that's what we look for.
24
- */
25
- const VERB_HINTS = [
26
- 'ship',
27
- 'shipping',
28
- 'fix',
29
- 'fixing',
30
- 'write',
31
- 'writing',
32
- 'review',
33
- 'reviewing',
34
- 'build',
35
- 'building',
36
- 'integrate',
37
- 'integrating',
38
- 'design',
39
- 'designing',
40
- 'debug',
41
- 'debugging',
42
- 'refactor',
43
- 'refactoring',
44
- 'document',
45
- 'documenting',
46
- ];
47
- const THING_HINTS = [
48
- 'feature',
49
- 'features',
50
- 'bug',
51
- 'bugs',
52
- 'copy',
53
- 'integration',
54
- 'integrations',
55
- 'review',
56
- 'reviews',
57
- 'issue',
58
- 'issues',
59
- 'doc',
60
- 'docs',
61
- 'api',
62
- 'apis',
63
- 'endpoint',
64
- 'endpoints',
65
- 'workflow',
66
- 'workflows',
67
- 'page',
68
- 'pages',
69
- 'rule',
70
- 'rules',
71
- ];
72
- function meetsCriteria(answer) {
73
- const lower = answer.toLowerCase();
74
- const hasVerb = VERB_HINTS.some((v) => new RegExp(`\\b${v}\\b`).test(lower));
75
- const hasThing = THING_HINTS.some((t) => new RegExp(`\\b${t}\\b`).test(lower));
76
- return hasVerb && hasThing;
77
- }
78
- /**
79
- * Run the coach loop encoded in pb-setup.md against a scripted user.
80
- *
81
- * Loop (verbatim from the skill):
82
- * 1. Ask the open question.
83
- * 2. If answer meets criteria -> progress.
84
- * 3. If vague, ask one follow-up.
85
- * 4. If 2 follow-ups don't yield, fall back to wizard (DEC-991).
86
- *
87
- * Convergence target (doneWhen #16): within 3 turns. Three turns means: the
88
- * open question + at most two follow-ups. After the third turn without
89
- * criteria-met, the agent MUST fall back to the wizard.
90
- */
91
- function runCoachLoop(turns) {
92
- const trace = [];
93
- let followUps = 0;
94
- for (let i = 0; i < turns.length; i++) {
95
- const turn = turns[i];
96
- const met = meetsCriteria(turn.user);
97
- trace.push({ turn: i + 1, user: turn.user, met });
98
- if (met) {
99
- return {
100
- state: 'criteria-met',
101
- turnsUsed: i + 1,
102
- finalAnswer: turn.user,
103
- trace,
104
- };
105
- }
106
- followUps += 1;
107
- if (followUps >= 2) {
108
- // Skill behaviour: "if 2 follow-ups don't yield, suggest a default
109
- // catalog and let them pick (DEC-991 fallback path)".
110
- return {
111
- state: 'wizard-fallback',
112
- turnsUsed: i + 1,
113
- finalAnswer: turn.user,
114
- trace,
115
- };
116
- }
117
- }
118
- // Out of scripted turns without convergence — treat as wizard-fallback so
119
- // the test surfaces a faulty fixture rather than silently passing.
120
- return {
121
- state: 'wizard-fallback',
122
- turnsUsed: turns.length,
123
- finalAnswer: turns[turns.length - 1]?.user ?? '',
124
- trace,
125
- };
126
- }
127
- describe('Phase 3 coach loop — cross-model trace harness (TEN-1962)', () => {
128
- it('Scenario A — happy path (specific answer, 1 turn)', () => {
129
- const turns = [
130
- { user: 'Mostly shipping new features for our SvelteKit app.' },
131
- ];
132
- const outcome = runCoachLoop(turns);
133
- expect(outcome.state).toBe('criteria-met');
134
- expect(outcome.turnsUsed).toBe(1);
135
- expect(outcome.turnsUsed).toBeLessThanOrEqual(3);
136
- });
137
- it('Scenario B — vague then specific (follow-up, 2 turns)', () => {
138
- const turns = [
139
- { user: 'I dunno, various stuff.' },
140
- { user: 'Last week I spent the most time fixing customer bugs.' },
141
- ];
142
- const outcome = runCoachLoop(turns);
143
- expect(outcome.state).toBe('criteria-met');
144
- expect(outcome.turnsUsed).toBe(2);
145
- expect(outcome.turnsUsed).toBeLessThanOrEqual(3);
146
- });
147
- it('Scenario C — 2 vague turns triggers wizard fallback (DEC-991 path)', () => {
148
- const turns = [
149
- { user: 'Just code, you know how it is.' },
150
- { user: 'Stuff. Things. The usual.' },
151
- ];
152
- const outcome = runCoachLoop(turns);
153
- expect(outcome.state).toBe('wizard-fallback');
154
- expect(outcome.turnsUsed).toBe(2);
155
- // Convergence to a deterministic outcome (criteria-met OR wizard) within
156
- // the 3-turn budget defends OBJ-32 generalisation across surfaces.
157
- expect(outcome.turnsUsed).toBeLessThanOrEqual(3);
158
- });
159
- it('Scenario D — marketing copy answer (non-engineering domain, criteria still met)', () => {
160
- const turns = [
161
- { user: 'I write marketing copy and review pages from the design team.' },
162
- ];
163
- const outcome = runCoachLoop(turns);
164
- expect(outcome.state).toBe('criteria-met');
165
- expect(outcome.turnsUsed).toBe(1);
166
- });
167
- it('Scenario E — every fixture converges within the 3-turn budget', () => {
168
- // Roll-up assertion across all scenarios so a future fixture addition that
169
- // exceeds the budget surfaces here as a single named failure.
170
- const fixtures = [
171
- [{ user: 'Mostly shipping new features for our SvelteKit app.' }],
172
- [
173
- { user: 'I dunno, various stuff.' },
174
- { user: 'Last week I spent the most time fixing customer bugs.' },
175
- ],
176
- [
177
- { user: 'Just code, you know how it is.' },
178
- { user: 'Stuff. Things. The usual.' },
179
- ],
180
- [{ user: 'I write marketing copy and review pages from the design team.' }],
181
- ];
182
- for (const turns of fixtures) {
183
- const outcome = runCoachLoop(turns);
184
- expect(outcome.turnsUsed).toBeLessThanOrEqual(3);
185
- expect(['criteria-met', 'wizard-fallback']).toContain(outcome.state);
186
- }
187
- });
188
- });
189
- //# sourceMappingURL=coach-traces.test.js.map