pi-odd-worktree 2.0.0 → 3.0.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/README.md +54 -311
- package/extensions/odd-worktree-tools.ts +4149 -2447
- package/lib/bash-activity.js +1164 -0
- package/lib/bash-design.js +684 -0
- package/lib/bash-destructive.js +559 -0
- package/lib/bash-frame.js +205 -0
- package/lib/card-content.js +23 -0
- package/lib/card-style.js +175 -0
- package/lib/checkout-facts.js +30 -70
- package/lib/codegraph-card-preview.js +628 -0
- package/lib/codegraph-card.js +515 -0
- package/lib/codegraph-compaction.js +76 -0
- package/lib/codegraph-daemon.js +246 -0
- package/lib/codegraph-edit-sync.js +182 -0
- package/lib/codegraph-guard-target.js +337 -0
- package/lib/codegraph-guard.js +211 -0
- package/lib/codegraph-index.js +1020 -0
- package/lib/codegraph-lock.js +607 -0
- package/lib/codegraph-mcp-config.js +134 -0
- package/lib/codegraph-mcp.js +123 -0
- package/lib/codegraph-paths.js +69 -0
- package/lib/codegraph-prompt/explore.md +11 -0
- package/lib/codegraph-prompt/fix.md +6 -0
- package/lib/codegraph-prompt/generic.md +8 -0
- package/lib/codegraph-prompt/judge.md +9 -0
- package/lib/codegraph-prompt/orchestrator.md +17 -0
- package/lib/codegraph-prompt/verify.md +10 -0
- package/lib/codegraph-prompt/worker.md +7 -0
- package/lib/codegraph-role.js +55 -0
- package/lib/codegraph-rules.js +146 -0
- package/lib/codegraph-session.js +303 -383
- package/lib/codegraph-warmup.js +139 -0
- package/lib/file-card-markdown.js +141 -0
- package/lib/file-card-resolver.js +245 -0
- package/lib/file-card.js +659 -0
- package/lib/files-index.js +387 -0
- package/lib/files-insert.js +81 -0
- package/lib/files-orders.js +326 -0
- package/lib/files-picker-view.js +1416 -0
- package/lib/files-preview.js +338 -0
- package/lib/files-scope-detail.js +171 -0
- package/lib/files-scope-view.js +507 -0
- package/lib/gh-issues.js +308 -14
- package/lib/issue-preview.js +26 -7
- package/lib/issues-bash-mutation.js +206 -0
- package/lib/issues-cache-store.js +261 -0
- package/lib/issues-section.js +710 -0
- package/lib/issues-view.js +649 -52
- package/lib/odd-prompt/odd-worktrees.md +21 -0
- package/lib/odd-worktrees-prompt.js +10 -28
- package/lib/related-issues-cache.js +210 -0
- package/lib/shell-card.js +825 -0
- package/lib/skill-odd-card.js +183 -0
- package/lib/tui-paint.js +4 -5
- package/lib/warp-create-panel.js +538 -250
- package/lib/warp-create-picker.js +56 -9
- package/lib/warp-delete-confirm.js +19 -28
- package/lib/warp-selector-view.js +160 -82
- package/lib/which-command.js +90 -0
- package/lib/worktree-card.js +267 -897
- package/lib/worktree-cards.js +383 -0
- package/lib/worktree-create.js +287 -0
- package/lib/worktree-git.js +3 -3
- package/lib/worktree-guard.js +548 -0
- package/lib/worktree-hooks.js +421 -711
- package/lib/worktree-list.js +120 -0
- package/lib/worktree-registry.js +162 -879
- package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
- package/lib/worktree-setup-runner.js +376 -0
- package/lib/worktree-setup.js +140 -0
- package/lib/worktree-warp-busy.js +462 -85
- package/lib/worktree-warp-sessions.js +1 -2
- package/package.json +2 -2
- package/tools/bash-activity.test.js +1419 -0
- package/tools/bash-design.test.js +1091 -0
- package/tools/bash-destructive.test.js +139 -0
- package/tools/card-content.test.js +44 -0
- package/tools/card-style.test.js +298 -0
- package/tools/codegraph-card-preview.test.js +254 -0
- package/tools/codegraph-card.test.js +1080 -0
- package/tools/codegraph-compaction.test.js +378 -0
- package/tools/codegraph-daemon.test.js +248 -0
- package/tools/codegraph-edit-sync.test.js +295 -0
- package/tools/codegraph-guard-target.test.js +174 -0
- package/tools/codegraph-guard.test.js +238 -0
- package/tools/codegraph-index.test.js +1948 -0
- package/tools/codegraph-lock.test.js +932 -0
- package/tools/codegraph-mcp-config.test.js +181 -0
- package/tools/codegraph-mcp.test.js +194 -0
- package/tools/codegraph-paths.test.js +44 -0
- package/tools/codegraph-role.test.js +30 -0
- package/tools/codegraph-rules.test.js +250 -0
- package/tools/codegraph-session.test.js +660 -391
- package/tools/codegraph-warmup.test.js +316 -0
- package/tools/commands.test.js +510 -31
- package/tools/file-card-markdown.test.js +188 -0
- package/tools/file-card.test.js +1289 -0
- package/tools/files-bridge.test.js +575 -0
- package/tools/files-command.test.js +610 -0
- package/tools/files-index.test.js +473 -0
- package/tools/files-insert.test.js +139 -0
- package/tools/files-orders.test.js +597 -0
- package/tools/files-picker-view.test.js +1871 -0
- package/tools/files-preview.test.js +452 -0
- package/tools/files-scope-detail.test.js +264 -0
- package/tools/files-scope-view.test.js +614 -0
- package/tools/fixtures/card-codegraph-outputs.js +110 -0
- package/tools/fixtures/codegraph-cli-stub.js +16 -0
- package/tools/fixtures/codegraph-init-process.js +28 -0
- package/tools/fixtures/codegraph-lock-worker.js +117 -0
- package/tools/fixtures/daemon-fake.js +98 -0
- package/tools/fixtures/daemon-mcp-server.js +39 -0
- package/tools/fixtures/daemon-warmup-worker.js +12 -0
- package/tools/fixtures/load-extension.js +136 -3
- package/tools/gh-issues-feedback.test.js +31 -7
- package/tools/gh-issues.test.js +391 -1
- package/tools/issue-preview.test.js +44 -7
- package/tools/issues-bash-mutation.test.js +101 -0
- package/tools/issues-cache-store.test.js +222 -0
- package/tools/issues-command.test.js +1512 -66
- package/tools/issues-open-guard.test.js +1096 -0
- package/tools/issues-section.test.js +4195 -0
- package/tools/issues-seed-query-regression.test.js +67 -0
- package/tools/issues-view.test.js +1489 -60
- package/tools/odd-worktrees-prompt.test.js +98 -65
- package/tools/package-surface.test.js +431 -36
- package/tools/related-issues-cache.test.js +324 -0
- package/tools/shell-card.test.js +834 -0
- package/tools/skill-odd-card.test.js +200 -0
- package/tools/t5-session-identity.test.js +44 -22
- package/tools/warp-busy-guard.test.js +2569 -308
- package/tools/warp-create-panel.test.js +499 -74
- package/tools/warp-create-picker.test.js +101 -5
- package/tools/warp-delete-confirm.test.js +49 -15
- package/tools/warp-empty-session.test.js +0 -1
- package/tools/warp-fallback-regression.test.js +533 -0
- package/tools/warp-selector-view.test.js +460 -196
- package/tools/which-command.test.js +126 -0
- package/tools/worktree-card.test.js +551 -0
- package/tools/worktree-cards.test.js +845 -0
- package/tools/worktree-changes.test.js +4 -5
- package/tools/worktree-create.test.js +489 -0
- package/tools/worktree-guard.test.js +823 -0
- package/tools/worktree-hooks.test.js +905 -0
- package/tools/worktree-list.test.js +170 -0
- package/tools/worktree-registry.test.js +89 -230
- package/tools/worktree-remove-async.test.js +318 -0
- package/tools/worktree-setup-runner.test.js +276 -0
- package/tools/worktree-setup.test.js +140 -0
- package/tools/worktree-tools.test.js +477 -93
- package/lib/codegraph-commands.js +0 -165
- package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
- package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
- package/lib/worktree-model-result.js +0 -291
- package/tools/codegraph-commands.test.js +0 -371
- package/tools/herdr-free-create.test.js +0 -161
- package/tools/worktree-close-herdr-async.test.js +0 -204
- package/tools/worktree-odd-migration.test.js +0 -224
- package/tools/worktree-registry-cache.test.js +0 -163
- package/tools/worktree-registry-odd.test.js +0 -231
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
## ODD worktrees
|
|
2
|
+
|
|
3
|
+
An ODD writes only in its own worktree, never in the primary checkout or on the default
|
|
4
|
+
branch; the feature branch lives there. Reading anywhere is fine, and a request that stays
|
|
5
|
+
read-only needs no worktree.
|
|
6
|
+
|
|
7
|
+
A worktree lives at `<repo-parent>/<repo-name>-worktrees/<odd>`: the directory IS the ODD
|
|
8
|
+
it serves. Before the ODD's first write, call `worktree_list`: if it already has a
|
|
9
|
+
worktree, work there; if not, create it with `worktree_create` (use `copy_changes: true`
|
|
10
|
+
if the pending changes of the current checkout belong to that work).
|
|
11
|
+
|
|
12
|
+
One ODD, one worktree. An ODD is one request and its follow-ups, big or small: everything
|
|
13
|
+
that belongs to it goes into the same ODD and worktree, and an unrelated request is another
|
|
14
|
+
ODD with its own worktree.
|
|
15
|
+
|
|
16
|
+
Delegate an ODD's independent units of behavior to agents in parallel, each with the
|
|
17
|
+
`workspace_root` of that ODD's worktree; the only limit is that two agents never edit the
|
|
18
|
+
same file.
|
|
19
|
+
|
|
20
|
+
After the merge, update the default branch. Then remove the worktree, keeping its branch,
|
|
21
|
+
unless its tree is dirty or a session is standing in it.
|
|
@@ -7,30 +7,20 @@
|
|
|
7
7
|
// ever added after the existing text, is skipped when it is already there, and
|
|
8
8
|
// reaches a primary session only — a named agent or a `GENTLE_PI_AGENTS_CHILD`
|
|
9
9
|
// worker is left untouched. `ODD_WORKTREE_PROMPT=0` turns it off.
|
|
10
|
-
//
|
|
11
|
-
// The section has two variants: the CodeGraph sentences are present only when
|
|
12
|
-
// the session gate says the CLI exists, so the prompt never promises a sync
|
|
13
|
-
// that cannot happen.
|
|
14
10
|
|
|
15
11
|
const fs = require('node:fs');
|
|
16
12
|
const path = require('node:path');
|
|
17
13
|
|
|
18
|
-
const { hasCodegraph } = require('./codegraph-session.js');
|
|
19
|
-
|
|
20
14
|
// The heading is the identity of the block, so an already-injected section is
|
|
21
|
-
// never added twice
|
|
22
|
-
// different variant would otherwise be appended.
|
|
15
|
+
// never added twice.
|
|
23
16
|
const SECTION_MARKER = '## ODD worktrees';
|
|
24
17
|
|
|
25
|
-
// The section text lives in its own Markdown
|
|
26
|
-
// and edited as prose: `lib/odd-prompt/odd-worktrees
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
// empty file falls back to the heading alone: the block still injects, never
|
|
30
|
-
// crashes the session, and the idempotency marker still works.
|
|
18
|
+
// The section text lives in its own Markdown file so it can be read, reviewed
|
|
19
|
+
// and edited as prose: `lib/odd-prompt/odd-worktrees.md`. A missing or empty
|
|
20
|
+
// file falls back to the heading alone: the block still injects, never crashes
|
|
21
|
+
// the session, and the idempotency marker still works.
|
|
31
22
|
const PROMPT_DIR = path.join(__dirname, 'odd-prompt');
|
|
32
|
-
const
|
|
33
|
-
const WITHOUT_FILE = path.join(PROMPT_DIR, 'odd-worktrees.without-codegraph.md');
|
|
23
|
+
const PROMPT_FILE = path.join(PROMPT_DIR, 'odd-worktrees.md');
|
|
34
24
|
const FALLBACK = `${SECTION_MARKER}\n\nEach ODD feature has its own worktree.`;
|
|
35
25
|
|
|
36
26
|
function readPromptFile(file) {
|
|
@@ -42,9 +32,7 @@ function readPromptFile(file) {
|
|
|
42
32
|
}
|
|
43
33
|
}
|
|
44
34
|
|
|
45
|
-
const
|
|
46
|
-
const WITHOUT_CODEGRAPH = readPromptFile(WITHOUT_FILE) || FALLBACK;
|
|
47
|
-
|
|
35
|
+
const SECTION = readPromptFile(PROMPT_FILE) || FALLBACK;
|
|
48
36
|
|
|
49
37
|
// The names a named-agent event may carry. `agent` itself is listed because a
|
|
50
38
|
// plain string there is a named agent too; an object is read through `.name`.
|
|
@@ -83,17 +71,12 @@ function appendOddWorktreesSection(event, deps = {}) {
|
|
|
83
71
|
const options = event && event.systemPromptOptions;
|
|
84
72
|
if (!options || typeof options !== 'object') return;
|
|
85
73
|
|
|
86
|
-
const available = typeof effectiveDeps.hasCodegraph === 'function'
|
|
87
|
-
? effectiveDeps.hasCodegraph(env)
|
|
88
|
-
: hasCodegraph(env);
|
|
89
|
-
const section = available ? WITH_CODEGRAPH : WITHOUT_CODEGRAPH;
|
|
90
|
-
|
|
91
74
|
const existing = typeof options.appendSystemPrompt === 'string' ? options.appendSystemPrompt : '';
|
|
92
75
|
if (existing.includes(SECTION_MARKER)) return;
|
|
93
76
|
// Append-only: every existing byte stays the prefix of the new value.
|
|
94
77
|
options.appendSystemPrompt = existing.length === 0
|
|
95
|
-
?
|
|
96
|
-
: `${existing}${separatorFor(existing)}${
|
|
78
|
+
? SECTION
|
|
79
|
+
: `${existing}${separatorFor(existing)}${SECTION}`;
|
|
97
80
|
} catch {
|
|
98
81
|
// The prompt block must never break session start.
|
|
99
82
|
}
|
|
@@ -101,6 +84,5 @@ function appendOddWorktreesSection(event, deps = {}) {
|
|
|
101
84
|
|
|
102
85
|
module.exports = {
|
|
103
86
|
appendOddWorktreesSection,
|
|
104
|
-
|
|
105
|
-
WITHOUT_CODEGRAPH,
|
|
87
|
+
SECTION,
|
|
106
88
|
};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// S9 (issues-sidebar, T14): the in-process cache of the three scoped issue
|
|
3
|
+
// views the rail's ONE combined read answers (`mine`, `assigned`, `involved`).
|
|
4
|
+
//
|
|
5
|
+
// Pure by contract: no imports, no child process and no clock but the one
|
|
6
|
+
// injected. State is process memory only — nothing is ever written to disk —
|
|
7
|
+
// and it is kept per repository identity (`<host>/<owner>/<repo>`), so a session
|
|
8
|
+
// that moves between checkouts can never show one repository's rows under
|
|
9
|
+
// another's name.
|
|
10
|
+
//
|
|
11
|
+
// The first sync reads up to 100 per bucket and REPLACES it. Later syncs read
|
|
12
|
+
// the newest 20 and MERGE by issue number. A merge cannot see an issue that was
|
|
13
|
+
// closed or unassigned (it simply leaves the result), so after every apply each
|
|
14
|
+
// bucket that is not truncated is held to one invariant: the cached row count
|
|
15
|
+
// must equal the `issueCount` the same response reported. A mismatch is exactly
|
|
16
|
+
// how a departed issue is detected, and it makes the NEXT `plan` a full re-read
|
|
17
|
+
// of the three buckets. A bucket whose `issueCount` exceeds `bucketCap` is
|
|
18
|
+
// `truncated`: the invariant is skipped for it — a bucket the cache cannot hold
|
|
19
|
+
// whole is never held to a count it cannot store — and the truncation is
|
|
20
|
+
// reported to the caller instead of being looped over.
|
|
21
|
+
//
|
|
22
|
+
// Two times are kept per entry (T15): `fullAt` moves only when a FULL apply
|
|
23
|
+
// replaces the buckets, and `syncedAt` moves on every apply and is what `get`
|
|
24
|
+
// reports. `plan` compares `fullAt` with `fullTtlMs`, so a steady stream of
|
|
25
|
+
// deltas can never postpone the ten-minute full re-read.
|
|
26
|
+
//
|
|
27
|
+
// `apply` also accepts the caller's start-ordered `sequence` (T15): a response
|
|
28
|
+
// whose sequence is older than the last one applied for that identity is ignored
|
|
29
|
+
// whole, so a full read that finishes after a newer one can never overwrite it.
|
|
30
|
+
//
|
|
31
|
+
// `get` hands out copies, so a consumer can never mutate the cache through a
|
|
32
|
+
// frame it rendered. It reports the entry's own `truncated` and `inconsistent`
|
|
33
|
+
// facts (T17): a consumer that reports a TOTAL must not claim an exact one from
|
|
34
|
+
// an entry whose cached rows no longer match the count the response reported —
|
|
35
|
+
// that is the same fact `plan` acts on. `apply` never throws: a failed or
|
|
36
|
+
// malformed answer leaves the cached entry exactly as it was.
|
|
37
|
+
|
|
38
|
+
const BUCKET_KEYS = ['mine', 'assigned', 'involved'];
|
|
39
|
+
// The two read sizes S9 names: the first sync is the full one, every later one
|
|
40
|
+
// is the newest 20 that can still change what the rail shows.
|
|
41
|
+
const FULL_FIRST = 100;
|
|
42
|
+
const DELTA_FIRST = 20;
|
|
43
|
+
const DEFAULT_FULL_TTL_MS = 600000;
|
|
44
|
+
const DEFAULT_BUCKET_CAP = 100;
|
|
45
|
+
|
|
46
|
+
function updatedAtValue(row) {
|
|
47
|
+
const raw = row && typeof row === 'object' ? row.updatedAt : null;
|
|
48
|
+
const parsed = typeof raw === 'string' ? Date.parse(raw) : Number.NaN;
|
|
49
|
+
return Number.isFinite(parsed) ? parsed : Number.NEGATIVE_INFINITY;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function copyIssue(row) {
|
|
53
|
+
const copy = { ...row };
|
|
54
|
+
if (Array.isArray(row.labels)) copy.labels = row.labels.map((label) => (label && typeof label === 'object' ? { ...label } : label));
|
|
55
|
+
if (Array.isArray(row.assignees)) copy.assignees = row.assignees.slice();
|
|
56
|
+
if (row.reactions && typeof row.reactions === 'object') copy.reactions = { ...row.reactions };
|
|
57
|
+
return copy;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The rows of one bucket, deduplicated by issue number (a later occurrence
|
|
61
|
+
// replaces an earlier one) and stored as copies. A row without a usable number
|
|
62
|
+
// cannot be merged or counted, so it never enters the cache.
|
|
63
|
+
function normalizeRows(rows) {
|
|
64
|
+
const byNumber = new Map();
|
|
65
|
+
if (!Array.isArray(rows)) return [];
|
|
66
|
+
for (const row of rows) {
|
|
67
|
+
if (!row || typeof row !== 'object') continue;
|
|
68
|
+
if (!Number.isInteger(row.number) || row.number <= 0) continue;
|
|
69
|
+
byNumber.set(row.number, copyIssue(row));
|
|
70
|
+
}
|
|
71
|
+
return [...byNumber.values()];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// A delta MERGES by issue number. The freshly read row is the newer one, so it
|
|
75
|
+
// replaces the stored row; a stored row whose number the delta did not mention
|
|
76
|
+
// stays exactly as it was (which is what lets the count invariant notice an
|
|
77
|
+
// issue that left the result).
|
|
78
|
+
function mergeRows(previous, incoming) {
|
|
79
|
+
const byNumber = new Map();
|
|
80
|
+
for (const row of previous || []) byNumber.set(row.number, copyIssue(row));
|
|
81
|
+
for (const row of incoming) {
|
|
82
|
+
const existing = byNumber.get(row.number);
|
|
83
|
+
if (existing === undefined || updatedAtValue(row) >= updatedAtValue(existing)) {
|
|
84
|
+
byNumber.set(row.number, row);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return [...byNumber.values()];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function sortAndTrim(rows, cap) {
|
|
91
|
+
return rows
|
|
92
|
+
.slice()
|
|
93
|
+
.sort((left, right) => updatedAtValue(right) - updatedAtValue(left))
|
|
94
|
+
.slice(0, cap);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function createIssuesCache(options = {}) {
|
|
98
|
+
const opts = options && typeof options === 'object' ? options : {};
|
|
99
|
+
const now = typeof opts.now === 'function' ? opts.now : Date.now;
|
|
100
|
+
const fullTtlMs = Number.isFinite(opts.fullTtlMs) && opts.fullTtlMs >= 0
|
|
101
|
+
? opts.fullTtlMs
|
|
102
|
+
: DEFAULT_FULL_TTL_MS;
|
|
103
|
+
const bucketCap = Number.isInteger(opts.bucketCap) && opts.bucketCap > 0
|
|
104
|
+
? opts.bucketCap
|
|
105
|
+
: DEFAULT_BUCKET_CAP;
|
|
106
|
+
const entries = new Map();
|
|
107
|
+
|
|
108
|
+
// The injected clock is the module's only notion of time; a clock that throws
|
|
109
|
+
// or answers nonsense costs the staleness window, never a caller.
|
|
110
|
+
function clock() {
|
|
111
|
+
try {
|
|
112
|
+
const value = now();
|
|
113
|
+
return Number.isFinite(value) ? value : 0;
|
|
114
|
+
} catch {
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function plan(identity) {
|
|
120
|
+
const entry = entries.get(identity);
|
|
121
|
+
if (!entry) return { full: true, first: FULL_FIRST };
|
|
122
|
+
if (entry.inconsistent === true) return { full: true, first: FULL_FIRST };
|
|
123
|
+
// T15 (S9, defect 3): the ten-minute bound is measured from the last FULL
|
|
124
|
+
// read. Every delta stamps `syncedAt`, but only a full apply moves `fullAt`,
|
|
125
|
+
// so a steady stream of deltas can never postpone the full re-read forever.
|
|
126
|
+
const age = clock() - entry.fullAt;
|
|
127
|
+
if (!Number.isFinite(age) || age >= fullTtlMs) return { full: true, first: FULL_FIRST };
|
|
128
|
+
return { full: false, first: DELTA_FIRST };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function apply(identity, response, applyOptions = {}) {
|
|
132
|
+
const buckets = response && response.ok === true && response.buckets && typeof response.buckets === 'object'
|
|
133
|
+
? response.buckets
|
|
134
|
+
: null;
|
|
135
|
+
if (buckets === null) {
|
|
136
|
+
return { consistent: false, truncated: { mine: false, assigned: false, involved: false } };
|
|
137
|
+
}
|
|
138
|
+
const full = Boolean(applyOptions && applyOptions.full === true);
|
|
139
|
+
// T15 (S9, defect 5): the caller numbers a read when it STARTS. An answer
|
|
140
|
+
// older than the last one applied for this identity is ignored whole — a
|
|
141
|
+
// full read that finishes after a newer one can never overwrite it.
|
|
142
|
+
const sequence = Number.isFinite(applyOptions && applyOptions.sequence) ? applyOptions.sequence : null;
|
|
143
|
+
const previous = entries.get(identity);
|
|
144
|
+
if (sequence !== null && previous && Number.isFinite(previous.lastApplied)
|
|
145
|
+
&& sequence <= previous.lastApplied) {
|
|
146
|
+
return { consistent: false, truncated: { ...previous.truncated } };
|
|
147
|
+
}
|
|
148
|
+
const at = clock();
|
|
149
|
+
const next = {
|
|
150
|
+
buckets: {},
|
|
151
|
+
counts: {},
|
|
152
|
+
truncated: {},
|
|
153
|
+
inconsistent: false,
|
|
154
|
+
fullAt: full || !previous ? at : previous.fullAt,
|
|
155
|
+
syncedAt: at,
|
|
156
|
+
lastApplied: sequence !== null
|
|
157
|
+
? sequence
|
|
158
|
+
: (previous && Number.isFinite(previous.lastApplied) ? previous.lastApplied : null),
|
|
159
|
+
};
|
|
160
|
+
for (const key of BUCKET_KEYS) {
|
|
161
|
+
const bucket = buckets[key] && typeof buckets[key] === 'object' ? buckets[key] : null;
|
|
162
|
+
if (!bucket || !Number.isInteger(bucket.issueCount) || bucket.issueCount < 0
|
|
163
|
+
|| !Array.isArray(bucket.issues)) {
|
|
164
|
+
// A malformed answer is not a state change: the cached entry stays as
|
|
165
|
+
// it was and the caller is told the result is not trustworthy.
|
|
166
|
+
return { consistent: false, truncated: { mine: false, assigned: false, involved: false } };
|
|
167
|
+
}
|
|
168
|
+
const incoming = normalizeRows(bucket.issues);
|
|
169
|
+
const merged = full || !previous ? incoming : mergeRows(previous.buckets[key], incoming);
|
|
170
|
+
next.buckets[key] = sortAndTrim(merged, bucketCap);
|
|
171
|
+
next.counts[key] = bucket.issueCount;
|
|
172
|
+
next.truncated[key] = bucket.issueCount > bucketCap;
|
|
173
|
+
if (!next.truncated[key] && next.buckets[key].length !== bucket.issueCount) {
|
|
174
|
+
next.inconsistent = true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
entries.set(identity, next);
|
|
178
|
+
return {
|
|
179
|
+
consistent: next.inconsistent === false,
|
|
180
|
+
truncated: { ...next.truncated },
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function get(identity) {
|
|
185
|
+
const entry = entries.get(identity);
|
|
186
|
+
if (!entry) return null;
|
|
187
|
+
const buckets = {};
|
|
188
|
+
for (const key of BUCKET_KEYS) {
|
|
189
|
+
buckets[key] = entry.buckets[key].map(copyIssue);
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
buckets,
|
|
193
|
+
truncated: { ...entry.truncated },
|
|
194
|
+
inconsistent: entry.inconsistent === true,
|
|
195
|
+
syncedAt: entry.syncedAt,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function drop(identity) {
|
|
200
|
+
entries.delete(identity);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function clear() {
|
|
204
|
+
entries.clear();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return { get, plan, apply, drop, clear };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
module.exports = { createIssuesCache };
|