@productbrain/cli 0.1.0-beta.11500 → 0.1.0-beta.11506
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/README.md +1 -1
- package/dist/__tests__/adapters.test.js +3 -3
- package/dist/__tests__/adapters.test.js.map +1 -1
- package/dist/__tests__/session-close-conversation.test.js +0 -1
- package/dist/__tests__/session-close-conversation.test.js.map +1 -1
- package/dist/__tests__/session-close-loop.test.js +0 -1
- package/dist/__tests__/session-close-loop.test.js.map +1 -1
- package/dist/__tests__/session-list-show.test.js +0 -1
- package/dist/__tests__/session-list-show.test.js.map +1 -1
- package/dist/__tests__/session-resume-backstop.test.js +0 -1
- package/dist/__tests__/session-resume-backstop.test.js.map +1 -1
- package/dist/__tests__/session-role-name-sanitize.test.js +0 -1
- package/dist/__tests__/session-role-name-sanitize.test.js.map +1 -1
- package/dist/__tests__/session-switch.test.js +0 -1
- package/dist/__tests__/session-switch.test.js.map +1 -1
- package/dist/__tests__/session.test.js +0 -3
- package/dist/__tests__/session.test.js.map +1 -1
- package/dist/commands/orient.js +1 -1
- package/dist/commands/orient.js.map +1 -1
- package/dist/commands/scoreboard.d.ts +2 -5
- package/dist/commands/scoreboard.d.ts.map +1 -1
- package/dist/commands/scoreboard.js +3 -8
- package/dist/commands/scoreboard.js.map +1 -1
- package/dist/formatters/__tests__/orient-plannedWorkCut.test.js +1 -9
- package/dist/formatters/__tests__/orient-plannedWorkCut.test.js.map +1 -1
- package/dist/formatters/scoreboard.d.ts.map +1 -1
- package/dist/formatters/scoreboard.js +0 -1
- package/dist/formatters/scoreboard.js.map +1 -1
- package/dist/formatters/scoreboard.test.js +2 -3
- package/dist/formatters/scoreboard.test.js.map +1 -1
- package/dist/generators/adapters.d.ts +3 -3
- package/dist/generators/adapters.d.ts.map +1 -1
- package/dist/generators/adapters.js +8 -11
- package/dist/generators/adapters.js.map +1 -1
- package/dist/generators/adapters.test.js +2 -1
- package/dist/generators/adapters.test.js.map +1 -1
- package/dist/generators/briefing-projections.test.js +5 -30
- package/dist/generators/briefing-projections.test.js.map +1 -1
- package/dist/generators/region.d.ts +1 -1
- package/dist/generators/region.d.ts.map +1 -1
- package/dist/generators/region.js +4 -4
- package/dist/generators/region.js.map +1 -1
- package/dist/lib/productbrain-files.js +5 -5
- package/dist/lib/productbrain-files.js.map +1 -1
- package/dist/lib/projectConfig.d.ts +2 -2
- package/dist/lib/projectConfig.js +2 -2
- package/dist/lib/ruleListRender.d.ts +2 -2
- package/dist/lib/ruleListRender.js +2 -2
- package/dist/lib/sessionNotices.d.ts.map +1 -1
- package/dist/lib/sessionNotices.js +0 -4
- package/dist/lib/sessionNotices.js.map +1 -1
- package/dist/lib/workspaceVocabCache.d.ts +2 -2
- package/dist/lib/workspaceVocabCache.js +2 -2
- package/dist/lib/writePerimeter.d.ts +2 -2
- package/dist/lib/writePerimeter.js +2 -2
- package/dist/scoreboard/diagnose.d.ts +3 -33
- package/dist/scoreboard/diagnose.d.ts.map +1 -1
- package/dist/scoreboard/diagnose.js +10 -137
- package/dist/scoreboard/diagnose.js.map +1 -1
- package/dist/scoreboard/diagnose.test.d.ts +2 -2
- package/dist/scoreboard/diagnose.test.js +5 -102
- package/dist/scoreboard/diagnose.test.js.map +1 -1
- package/dist/scoreboard/floors.d.ts +3 -8
- package/dist/scoreboard/floors.d.ts.map +1 -1
- package/dist/scoreboard/floors.js +0 -17
- package/dist/scoreboard/floors.js.map +1 -1
- package/dist/served-doors.test.d.ts +2 -0
- package/dist/served-doors.test.d.ts.map +1 -0
- package/dist/served-doors.test.js +186 -0
- package/dist/served-doors.test.js.map +1 -0
- package/dist/surfaces/adapters/claude.js +2 -2
- package/package.json +1 -1
- package/dist/commands/handshakeCursorSkillCleanup.d.ts +0 -36
- package/dist/commands/handshakeCursorSkillCleanup.d.ts.map +0 -1
- package/dist/commands/handshakeCursorSkillCleanup.js +0 -110
- package/dist/commands/handshakeCursorSkillCleanup.js.map +0 -1
- package/dist/commands/handshakeDriftClassification.d.ts +0 -33
- package/dist/commands/handshakeDriftClassification.d.ts.map +0 -1
- package/dist/commands/handshakeDriftClassification.js +0 -62
- package/dist/commands/handshakeDriftClassification.js.map +0 -1
- package/dist/formatters/handshake.d.ts +0 -80
- package/dist/formatters/handshake.d.ts.map +0 -1
- package/dist/formatters/handshake.js +0 -217
- package/dist/formatters/handshake.js.map +0 -1
- package/dist/generators/briefing-md.d.ts +0 -8
- package/dist/generators/briefing-md.d.ts.map +0 -1
- package/dist/generators/briefing-md.js +0 -51
- package/dist/generators/briefing-md.js.map +0 -1
- package/dist/generators/context-md.d.ts +0 -13
- package/dist/generators/context-md.d.ts.map +0 -1
- package/dist/generators/context-md.js +0 -95
- package/dist/generators/context-md.js.map +0 -1
- package/dist/generators/everyone-rules-md.d.ts +0 -9
- package/dist/generators/everyone-rules-md.d.ts.map +0 -1
- package/dist/generators/everyone-rules-md.js +0 -21
- package/dist/generators/everyone-rules-md.js.map +0 -1
- package/dist/generators/retired-projections.d.ts +0 -12
- package/dist/generators/retired-projections.d.ts.map +0 -1
- package/dist/generators/retired-projections.js +0 -75
- package/dist/generators/retired-projections.js.map +0 -1
- package/dist/generators/retired-projections.test.d.ts +0 -2
- package/dist/generators/retired-projections.test.d.ts.map +0 -1
- package/dist/generators/retired-projections.test.js +0 -64
- package/dist/generators/retired-projections.test.js.map +0 -1
- package/dist/scoreboard/localDrift.d.ts +0 -23
- package/dist/scoreboard/localDrift.d.ts.map +0 -1
- package/dist/scoreboard/localDrift.js +0 -111
- package/dist/scoreboard/localDrift.js.map +0 -1
- package/dist/scoreboard/localDrift.test.d.ts +0 -9
- package/dist/scoreboard/localDrift.test.d.ts.map +0 -1
- package/dist/scoreboard/localDrift.test.js +0 -82
- package/dist/scoreboard/localDrift.test.js.map +0 -1
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Projection files an older `pb handshake` wrote that the current one no longer owns.
|
|
3
|
-
*
|
|
4
|
-
* `pb handshake --generate` (removed) wrote one rule per governance archetype plus a degraded-mode
|
|
5
|
-
* sentinel into `.cursor/rules/*.mdc` and `.claude/rules/*.md`, and a state file under
|
|
6
|
-
* `.productbrain/`. Nothing rewrites them now, so on an existing checkout they would keep loading
|
|
7
|
-
* obsolete governance. Removal is bounded to this fixed name list and to files that carry the
|
|
8
|
-
* handshake MARKER, so a user-owned file that happens to share a name is never touched.
|
|
9
|
-
*/
|
|
10
|
-
import { existsSync, readFileSync, rmSync } from 'fs';
|
|
11
|
-
import { join } from 'path';
|
|
12
|
-
import { MARKER } from './adapters.js';
|
|
13
|
-
const RETIRED_RULE_NAMES = [
|
|
14
|
-
'chain-constraints',
|
|
15
|
-
'chain-boundaries',
|
|
16
|
-
'chain-policies',
|
|
17
|
-
'chain-workflows',
|
|
18
|
-
'chain-quality-gates',
|
|
19
|
-
'chain-conventions',
|
|
20
|
-
'chain-degraded',
|
|
21
|
-
'_chain_degraded',
|
|
22
|
-
];
|
|
23
|
-
const RETIRED_RULE_DIRS = [
|
|
24
|
-
{ dir: ['.cursor', 'rules'], ext: '.mdc' },
|
|
25
|
-
{ dir: ['.claude', 'rules'], ext: '.md' },
|
|
26
|
-
];
|
|
27
|
-
const RETIRED_STATE_FILE = ['.productbrain', '.handshake-state.json'];
|
|
28
|
-
function removeIfMarked(cwd, segments, requireMarker) {
|
|
29
|
-
const path = join(cwd, ...segments);
|
|
30
|
-
if (!existsSync(path))
|
|
31
|
-
return null;
|
|
32
|
-
try {
|
|
33
|
-
if (requireMarker && !readFileSync(path, 'utf8').includes(MARKER))
|
|
34
|
-
return null;
|
|
35
|
-
rmSync(path);
|
|
36
|
-
return segments.join('/');
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
return null; // unreadable or unremovable — leave it; the next handshake retries
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/** Removes the retired generated rule files and state file; returns the relative paths removed. */
|
|
43
|
-
export function removeRetiredChainRuleProjections(cwd) {
|
|
44
|
-
const removed = [];
|
|
45
|
-
for (const { dir, ext } of RETIRED_RULE_DIRS) {
|
|
46
|
-
for (const name of RETIRED_RULE_NAMES) {
|
|
47
|
-
const hit = removeIfMarked(cwd, [...dir, `${name}${ext}`], true);
|
|
48
|
-
if (hit)
|
|
49
|
-
removed.push(hit);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
const state = removeIfMarked(cwd, RETIRED_STATE_FILE, false);
|
|
53
|
-
if (state)
|
|
54
|
-
removed.push(state);
|
|
55
|
-
return removed;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Removes the two briefing projections, `.productbrain/context.md` and
|
|
59
|
-
* `.productbrain/generated/everyone-rules.md`, when the workspace briefing could not be fetched
|
|
60
|
-
* this run, so an old briefing is never left on disk as if it were current (TASK-554). Only files
|
|
61
|
-
* carrying the handshake MARKER are removed. Returns the relative paths removed.
|
|
62
|
-
*/
|
|
63
|
-
export function removeStaleBriefingProjections(cwd) {
|
|
64
|
-
return [
|
|
65
|
-
removeIfMarked(cwd, ['.productbrain', 'context.md'], true),
|
|
66
|
-
removeIfMarked(cwd, ['.productbrain', 'generated', 'everyone-rules.md'], true),
|
|
67
|
-
].filter((removed) => removed !== null);
|
|
68
|
-
}
|
|
69
|
-
/** Handshake's cleanup step (apply mode with a writing materialize mode): removes the retired generated files. */
|
|
70
|
-
export function retireGeneratedProjections(cwd, log) {
|
|
71
|
-
const retired = removeRetiredChainRuleProjections(cwd);
|
|
72
|
-
if (retired.length > 0)
|
|
73
|
-
log(`Removed retired generated projections: ${retired.join(', ')}`);
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=retired-projections.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retired-projections.js","sourceRoot":"","sources":["../../src/generators/retired-projections.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACtD,O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AAI,kBAAkB,EAAE,CAAC;YACtC,MAAM,GAAG,GAAG,cAAc,CAAC,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,IAAI,GAAG,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;YACjE,IAAI,GAAG;gBAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IACD,MAAM,KAAK,GAAG,cAAc,CAAC,GAAG,EAAE,kBAAkB,EAAE,KAAK,CAAC,CAAC;IAC7D,IAAI,KAAK;QAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/B,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B,CAAC,GAAW;IACxD,OAAO;QACL,cAAc,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,YAAY,CAAC,EAAE,IAAI,CAAC;QAC1D,cAAc,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,WAAW,EAAE,mBAAmB,CAAC,EAAE,IAAI,CAAC;KAC/E,CAAC,MAAM,CAAC,CAAC,OAAO,EAAqB,EAAE,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC;AAC7D,CAAC;AAED,kHAAkH;AAClH,MAAM,UAAU,0BAA0B,CAAC,GAAW,EAAE,GAA0B;IAChF,MAAM,OAAO,GAAG,iCAAiC,CAAC,GAAG,CAAC,CAAC;IACvD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,GAAG,CAAC,0CAA0C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC9F,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retired-projections.test.d.ts","sourceRoot":"","sources":["../../src/generators/retired-projections.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { mkdtempSync, mkdirSync, writeFileSync, existsSync, rmSync } from 'fs';
|
|
2
|
-
import { tmpdir } from 'os';
|
|
3
|
-
import { join } from 'path';
|
|
4
|
-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
5
|
-
import { MARKER } from './adapters.js';
|
|
6
|
-
import { removeRetiredChainRuleProjections, removeStaleBriefingProjections } from './retired-projections.js';
|
|
7
|
-
let cwd;
|
|
8
|
-
beforeEach(() => {
|
|
9
|
-
cwd = mkdtempSync(join(tmpdir(), 'retired-projections-'));
|
|
10
|
-
});
|
|
11
|
-
afterEach(() => {
|
|
12
|
-
rmSync(cwd, { recursive: true, force: true });
|
|
13
|
-
});
|
|
14
|
-
function put(rel, content) {
|
|
15
|
-
const full = join(cwd, rel);
|
|
16
|
-
mkdirSync(join(full, '..'), { recursive: true });
|
|
17
|
-
writeFileSync(full, content);
|
|
18
|
-
}
|
|
19
|
-
describe('removeRetiredChainRuleProjections', () => {
|
|
20
|
-
it('removes marker-bearing retired rule files in .cursor/rules and .claude/rules, and the state file', () => {
|
|
21
|
-
put('.cursor/rules/chain-constraints.mdc', `<!-- ${MARKER} — t -->\nold`);
|
|
22
|
-
put('.cursor/rules/chain-policies.mdc', `<!-- ${MARKER} — t -->\nold`);
|
|
23
|
-
put('.claude/rules/chain-workflows.md', `<!-- ${MARKER} — t -->\nold`);
|
|
24
|
-
put('.cursor/rules/_chain_degraded.mdc', `<!-- ${MARKER} — t -->\nold`);
|
|
25
|
-
put('.productbrain/.handshake-state.json', '{}');
|
|
26
|
-
const removed = removeRetiredChainRuleProjections(cwd);
|
|
27
|
-
expect(removed.sort()).toEqual([
|
|
28
|
-
'.claude/rules/chain-workflows.md',
|
|
29
|
-
'.cursor/rules/_chain_degraded.mdc',
|
|
30
|
-
'.cursor/rules/chain-constraints.mdc',
|
|
31
|
-
'.cursor/rules/chain-policies.mdc',
|
|
32
|
-
'.productbrain/.handshake-state.json',
|
|
33
|
-
]);
|
|
34
|
-
expect(existsSync(join(cwd, '.cursor/rules/chain-constraints.mdc'))).toBe(false);
|
|
35
|
-
});
|
|
36
|
-
it('never touches a same-named file without the marker, the live chain.mdc, or other rules', () => {
|
|
37
|
-
put('.cursor/rules/chain-conventions.mdc', 'user-owned, no marker');
|
|
38
|
-
put('.cursor/rules/chain.mdc', `<!-- ${MARKER} — t -->\nlive`);
|
|
39
|
-
put('.cursor/rules/security-boundaries.mdc', `<!-- ${MARKER} — t -->\nother`);
|
|
40
|
-
expect(removeRetiredChainRuleProjections(cwd)).toEqual([]);
|
|
41
|
-
expect(existsSync(join(cwd, '.cursor/rules/chain-conventions.mdc'))).toBe(true);
|
|
42
|
-
expect(existsSync(join(cwd, '.cursor/rules/chain.mdc'))).toBe(true);
|
|
43
|
-
expect(existsSync(join(cwd, '.cursor/rules/security-boundaries.mdc'))).toBe(true);
|
|
44
|
-
});
|
|
45
|
-
it('is a no-op on a clean checkout', () => {
|
|
46
|
-
expect(removeRetiredChainRuleProjections(cwd)).toEqual([]);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
describe('removeStaleBriefingProjections (TASK-554)', () => {
|
|
50
|
-
it('removes a generated context.md and everyone-rules.md and reports both paths', () => {
|
|
51
|
-
put('.productbrain/context.md', `<!-- ${MARKER} — t -->\nstale`);
|
|
52
|
-
put('.productbrain/generated/everyone-rules.md', `<!-- ${MARKER} — t -->\nstale`);
|
|
53
|
-
expect(removeStaleBriefingProjections(cwd)).toEqual(['.productbrain/context.md', '.productbrain/generated/everyone-rules.md']);
|
|
54
|
-
expect(existsSync(join(cwd, '.productbrain/context.md'))).toBe(false);
|
|
55
|
-
expect(existsSync(join(cwd, '.productbrain/generated/everyone-rules.md'))).toBe(false);
|
|
56
|
-
});
|
|
57
|
-
it('leaves a file without the marker and returns nothing when absent', () => {
|
|
58
|
-
expect(removeStaleBriefingProjections(cwd)).toEqual([]);
|
|
59
|
-
put('.productbrain/generated/everyone-rules.md', 'hand-written');
|
|
60
|
-
expect(removeStaleBriefingProjections(cwd)).toEqual([]);
|
|
61
|
-
expect(existsSync(join(cwd, '.productbrain/generated/everyone-rules.md'))).toBe(true);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
//# sourceMappingURL=retired-projections.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retired-projections.test.js","sourceRoot":"","sources":["../../src/generators/retired-projections.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,iCAAiC,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAE7G,IAAI,GAAW,CAAC;AAChB,UAAU,CAAC,GAAG,EAAE;IACd,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,sBAAsB,CAAC,CAAC,CAAC;AAC5D,CAAC,CAAC,CAAC;AACH,SAAS,CAAC,GAAG,EAAE;IACb,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC;AAEH,SAAS,GAAG,CAAC,GAAW,EAAE,OAAe;IACvC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC5B,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC/B,CAAC;AAED,QAAQ,CAAC,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AAC,CAAC;QACxD,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,2CAA2C,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flywheel scoreboard M5 — LOCAL-PULL drift, computed at the CLI (DEC-1284).
|
|
3
|
-
*
|
|
4
|
-
* The data layer deliberately exposes only the SERVER-side projection-generation time
|
|
5
|
-
* (`materialization.latestMaterializedAt`) — a Convex query cannot stat the worktree's files
|
|
6
|
-
* (DEC-1284). The TRUE M5 the spec asks for is LOCAL-pull staleness: how far the agent's pulled
|
|
7
|
-
* `.productbrain/` projection lags the server projection (or its absolute age). Only the CLI can
|
|
8
|
-
* compute it, by stat-ing the local projection files' mtime. This module is that computation.
|
|
9
|
-
*
|
|
10
|
-
* Fail-soft: if `.productbrain/` is absent or no projection files are found, returns an
|
|
11
|
-
* `unavailableReason` so the diagnosis layer renders `unmeasured` — NEVER a fake `ok`.
|
|
12
|
-
*/
|
|
13
|
-
import type { LocalDriftM5 } from './diagnose.js';
|
|
14
|
-
/**
|
|
15
|
-
* computeLocalDrift — the M5 local-pull drift (A5).
|
|
16
|
-
*
|
|
17
|
-
* @param serverMaterializedAt the data layer's `materialization.latestMaterializedAt` (ms epoch,
|
|
18
|
-
* or null when the workspace never materialized server-side).
|
|
19
|
-
* @param now injectable clock for tests (defaults to Date.now()).
|
|
20
|
-
* @param startDir injectable start dir for tests (defaults to process.cwd()).
|
|
21
|
-
*/
|
|
22
|
-
export declare function computeLocalDrift(serverMaterializedAt: number | null, now?: number, startDir?: string): LocalDriftM5;
|
|
23
|
-
//# sourceMappingURL=localDrift.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"localDrift.d.ts","sourceRoot":"","sources":["../../src/scoreboard/localDrift.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAwClD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,oBAAoB,EAAE,MAAM,GAAG,IAAI,EACnC,GAAG,GAAE,MAAmB,EACxB,QAAQ,GAAE,MAAsB,GAC/B,YAAY,CAkDd"}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Flywheel scoreboard M5 — LOCAL-PULL drift, computed at the CLI (DEC-1284).
|
|
3
|
-
*
|
|
4
|
-
* The data layer deliberately exposes only the SERVER-side projection-generation time
|
|
5
|
-
* (`materialization.latestMaterializedAt`) — a Convex query cannot stat the worktree's files
|
|
6
|
-
* (DEC-1284). The TRUE M5 the spec asks for is LOCAL-pull staleness: how far the agent's pulled
|
|
7
|
-
* `.productbrain/` projection lags the server projection (or its absolute age). Only the CLI can
|
|
8
|
-
* compute it, by stat-ing the local projection files' mtime. This module is that computation.
|
|
9
|
-
*
|
|
10
|
-
* Fail-soft: if `.productbrain/` is absent or no projection files are found, returns an
|
|
11
|
-
* `unavailableReason` so the diagnosis layer renders `unmeasured` — NEVER a fake `ok`.
|
|
12
|
-
*/
|
|
13
|
-
import { existsSync, statSync, readdirSync } from 'fs';
|
|
14
|
-
import { resolve } from 'path';
|
|
15
|
-
import { findProjectRoot } from '../lib/config.js';
|
|
16
|
-
/**
|
|
17
|
-
* The `pb handshake`-written projection files whose mtime tracks the local pull. These are the
|
|
18
|
-
* gitignored projections regenerated per worktree (context.md / briefing.md / generated/). We
|
|
19
|
-
* take the NEWEST mtime across whatever projection files exist — that is the most recent pull.
|
|
20
|
-
* `config.json` is excluded: it is committed + static, not a projection, so it never reflects a
|
|
21
|
-
* handshake pull.
|
|
22
|
-
*/
|
|
23
|
-
const PROJECTION_FILES = ['context.md', 'briefing.md'];
|
|
24
|
-
const PROJECTION_DIRS = ['generated', 'rules'];
|
|
25
|
-
/** Newest mtime (ms) across a set of candidate paths, or null if none exist. */
|
|
26
|
-
function newestMtime(paths) {
|
|
27
|
-
let newest = null;
|
|
28
|
-
for (const p of paths) {
|
|
29
|
-
try {
|
|
30
|
-
if (!existsSync(p))
|
|
31
|
-
continue;
|
|
32
|
-
const st = statSync(p);
|
|
33
|
-
const mtime = st.mtimeMs;
|
|
34
|
-
if (newest === null || mtime > newest)
|
|
35
|
-
newest = mtime;
|
|
36
|
-
}
|
|
37
|
-
catch {
|
|
38
|
-
// unreadable path — skip, fail-soft
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return newest;
|
|
42
|
-
}
|
|
43
|
-
/** Collect file paths one level deep inside a projection directory. */
|
|
44
|
-
function filesInDir(dir) {
|
|
45
|
-
try {
|
|
46
|
-
if (!existsSync(dir))
|
|
47
|
-
return [];
|
|
48
|
-
return readdirSync(dir, { withFileTypes: true })
|
|
49
|
-
.filter((e) => e.isFile())
|
|
50
|
-
.map((e) => resolve(dir, e.name));
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
return [];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* computeLocalDrift — the M5 local-pull drift (A5).
|
|
58
|
-
*
|
|
59
|
-
* @param serverMaterializedAt the data layer's `materialization.latestMaterializedAt` (ms epoch,
|
|
60
|
-
* or null when the workspace never materialized server-side).
|
|
61
|
-
* @param now injectable clock for tests (defaults to Date.now()).
|
|
62
|
-
* @param startDir injectable start dir for tests (defaults to process.cwd()).
|
|
63
|
-
*/
|
|
64
|
-
export function computeLocalDrift(serverMaterializedAt, now = Date.now(), startDir = process.cwd()) {
|
|
65
|
-
const projectRoot = findProjectRoot(startDir);
|
|
66
|
-
if (!projectRoot) {
|
|
67
|
-
return {
|
|
68
|
-
localProjectionMtime: null,
|
|
69
|
-
serverMaterializedAt,
|
|
70
|
-
localLagMs: null,
|
|
71
|
-
localAgeMs: null,
|
|
72
|
-
unavailableReason: 'no .productbrain/ project root found (walked up from CWD)',
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
const pbDir = resolve(projectRoot, '.productbrain');
|
|
76
|
-
if (!existsSync(pbDir)) {
|
|
77
|
-
return {
|
|
78
|
-
localProjectionMtime: null,
|
|
79
|
-
serverMaterializedAt,
|
|
80
|
-
localLagMs: null,
|
|
81
|
-
localAgeMs: null,
|
|
82
|
-
unavailableReason: `.productbrain/ missing at ${projectRoot}`,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
const candidatePaths = [
|
|
86
|
-
...PROJECTION_FILES.map((f) => resolve(pbDir, f)),
|
|
87
|
-
...PROJECTION_DIRS.flatMap((d) => filesInDir(resolve(pbDir, d))),
|
|
88
|
-
];
|
|
89
|
-
const localProjectionMtime = newestMtime(candidatePaths);
|
|
90
|
-
if (localProjectionMtime === null) {
|
|
91
|
-
return {
|
|
92
|
-
localProjectionMtime: null,
|
|
93
|
-
serverMaterializedAt,
|
|
94
|
-
localLagMs: null,
|
|
95
|
-
localAgeMs: null,
|
|
96
|
-
unavailableReason: 'no .productbrain/ projection files (context.md / briefing.md / generated/ / rules/) found — run pb handshake',
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
// local-lag = how far the local pull lags the server projection. Positive = server is newer
|
|
100
|
-
// (local is stale). Clamp at 0 (a local mtime ahead of the server is not "negative staleness").
|
|
101
|
-
const localLagMs = serverMaterializedAt === null ? null : Math.max(0, serverMaterializedAt - localProjectionMtime);
|
|
102
|
-
// local-age = absolute age of the local projection vs now.
|
|
103
|
-
const localAgeMs = Math.max(0, now - localProjectionMtime);
|
|
104
|
-
return {
|
|
105
|
-
localProjectionMtime,
|
|
106
|
-
serverMaterializedAt,
|
|
107
|
-
localLagMs,
|
|
108
|
-
localAgeMs,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
//# sourceMappingURL=localDrift.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"localDrift.js","sourceRoot":"","sources":["../../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IAAI;YAChB,iBAAiB,EAAE,8GAA8G;SAClI,CAAC;IACJ,CAAC;IAED,4FAA4F;IAC5F,gGAAgG;IAChG,MAAM,UAAU,GACd,oBAAoB,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,oBAAoB,GAAG,oBAAoB,CAAC,CAAC;IAClG,2DAA2D;IAC3D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,oBAAoB,CAAC,CAAC;IAE3D,OAAO;QACL,oBAAoB;QACpB,oBAAoB;QACpB,UAAU;QACV,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* M5 local-pull drift unit tests (A5, DEC-1284).
|
|
3
|
-
*
|
|
4
|
-
* Exercises computeLocalDrift over a real temp `.productbrain/` so the stat path is genuinely
|
|
5
|
-
* driven (not mocked): a config-bearing root (so findProjectRoot resolves) + a projection file
|
|
6
|
-
* whose mtime is the local pull. Asserts the lag/age math, the clamp, and the fail-soft branches.
|
|
7
|
-
*/
|
|
8
|
-
export {};
|
|
9
|
-
//# sourceMappingURL=localDrift.test.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"localDrift.test.d.ts","sourceRoot":"","sources":["../../src/scoreboard/localDrift.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* M5 local-pull drift unit tests (A5, DEC-1284).
|
|
3
|
-
*
|
|
4
|
-
* Exercises computeLocalDrift over a real temp `.productbrain/` so the stat path is genuinely
|
|
5
|
-
* driven (not mocked): a config-bearing root (so findProjectRoot resolves) + a projection file
|
|
6
|
-
* whose mtime is the local pull. Asserts the lag/age math, the clamp, and the fail-soft branches.
|
|
7
|
-
*/
|
|
8
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
9
|
-
import { mkdtempSync, mkdirSync, writeFileSync, utimesSync, rmSync } from 'fs';
|
|
10
|
-
import { tmpdir } from 'os';
|
|
11
|
-
import { resolve } from 'path';
|
|
12
|
-
import { computeLocalDrift } from './localDrift.js';
|
|
13
|
-
let root;
|
|
14
|
-
function setMtime(path, ms) {
|
|
15
|
-
const secs = ms / 1000;
|
|
16
|
-
utimesSync(path, secs, secs);
|
|
17
|
-
}
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
root = mkdtempSync(resolve(tmpdir(), 'pb-m5-'));
|
|
20
|
-
const pb = resolve(root, '.productbrain');
|
|
21
|
-
mkdirSync(pb, { recursive: true });
|
|
22
|
-
// config.json makes this a CLI project root (findProjectRoot requires it).
|
|
23
|
-
writeFileSync(resolve(pb, 'config.json'), JSON.stringify({ siteUrl: 'https://example.test' }));
|
|
24
|
-
});
|
|
25
|
-
afterEach(() => {
|
|
26
|
-
rmSync(root, { recursive: true, force: true });
|
|
27
|
-
});
|
|
28
|
-
describe('computeLocalDrift', () => {
|
|
29
|
-
it('fails soft to unavailable when no projection files exist', () => {
|
|
30
|
-
const d = computeLocalDrift(5_000, 10_000, root);
|
|
31
|
-
expect(d.localProjectionMtime).toBeNull();
|
|
32
|
-
expect(d.localLagMs).toBeNull();
|
|
33
|
-
expect(d.localAgeMs).toBeNull();
|
|
34
|
-
expect(d.unavailableReason).toMatch(/projection files/);
|
|
35
|
-
});
|
|
36
|
-
it('computes lag (server − local) and age (now − local) from the newest projection mtime', () => {
|
|
37
|
-
const pb = resolve(root, '.productbrain');
|
|
38
|
-
const ctx = resolve(pb, 'context.md');
|
|
39
|
-
writeFileSync(ctx, '# context');
|
|
40
|
-
setMtime(ctx, 1_000);
|
|
41
|
-
// Also write a newer briefing — newest mtime should win.
|
|
42
|
-
const brief = resolve(pb, 'briefing.md');
|
|
43
|
-
writeFileSync(brief, '# briefing');
|
|
44
|
-
setMtime(brief, 3_000);
|
|
45
|
-
const d = computeLocalDrift(5_000 /* server */, 10_000 /* now */, root);
|
|
46
|
-
expect(d.localProjectionMtime).toBe(3_000);
|
|
47
|
-
expect(d.serverMaterializedAt).toBe(5_000);
|
|
48
|
-
expect(d.localLagMs).toBe(2_000); // 5000 − 3000
|
|
49
|
-
expect(d.localAgeMs).toBe(7_000); // 10000 − 3000
|
|
50
|
-
expect(d.unavailableReason).toBeUndefined();
|
|
51
|
-
});
|
|
52
|
-
it('clamps lag at 0 when the local pull is newer than the server materialization', () => {
|
|
53
|
-
const pb = resolve(root, '.productbrain');
|
|
54
|
-
const ctx = resolve(pb, 'context.md');
|
|
55
|
-
writeFileSync(ctx, '# context');
|
|
56
|
-
setMtime(ctx, 9_000);
|
|
57
|
-
const d = computeLocalDrift(5_000, 10_000, root);
|
|
58
|
-
expect(d.localLagMs).toBe(0); // max(0, 5000 − 9000)
|
|
59
|
-
expect(d.localAgeMs).toBe(1_000);
|
|
60
|
-
});
|
|
61
|
-
it('returns null lag when the server never materialized', () => {
|
|
62
|
-
const pb = resolve(root, '.productbrain');
|
|
63
|
-
const ctx = resolve(pb, 'context.md');
|
|
64
|
-
writeFileSync(ctx, '# context');
|
|
65
|
-
setMtime(ctx, 2_000);
|
|
66
|
-
const d = computeLocalDrift(null, 10_000, root);
|
|
67
|
-
expect(d.localLagMs).toBeNull();
|
|
68
|
-
expect(d.localAgeMs).toBe(8_000);
|
|
69
|
-
});
|
|
70
|
-
it('reports unavailable when no project root is found', () => {
|
|
71
|
-
const bare = mkdtempSync(resolve(tmpdir(), 'pb-noroot-'));
|
|
72
|
-
try {
|
|
73
|
-
const d = computeLocalDrift(5_000, 10_000, bare);
|
|
74
|
-
expect(d.localProjectionMtime).toBeNull();
|
|
75
|
-
expect(d.unavailableReason).toMatch(/project root|missing/i);
|
|
76
|
-
}
|
|
77
|
-
finally {
|
|
78
|
-
rmSync(bare, { recursive: true, force: true });
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
//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