@granular-software/fractory 0.0.0-stage → 0.1.25
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/LICENSE +4 -0
- package/README.md +28 -2
- package/dist/activity-volume.d.ts +18 -0
- package/dist/activity-volume.js +94 -0
- package/dist/annotations.d.ts +122 -0
- package/dist/annotations.js +304 -0
- package/dist/benchmark-cli.d.ts +1 -0
- package/dist/benchmark-cli.js +95 -0
- package/dist/benchmark-worker.d.ts +2 -0
- package/dist/benchmark-worker.js +22 -0
- package/dist/benchmarks.d.ts +19 -0
- package/dist/benchmarks.js +414 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +63 -0
- package/dist/block-cli.d.ts +1 -0
- package/dist/block-cli.js +88 -0
- package/dist/block-documents.d.ts +35 -0
- package/dist/block-documents.js +84 -0
- package/dist/change-impact.d.ts +55 -0
- package/dist/change-impact.js +223 -0
- package/dist/check-source.d.ts +2 -0
- package/dist/check-source.js +66 -0
- package/dist/checks-model.d.ts +64 -0
- package/dist/checks-model.js +36 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +359 -0
- package/dist/code-model.d.ts +38 -0
- package/dist/code-model.js +94 -0
- package/dist/code-store.d.ts +9 -0
- package/dist/code-store.js +79 -0
- package/dist/compare-artifact.d.ts +6 -0
- package/dist/compare-artifact.js +277 -0
- package/dist/compare.d.ts +81 -0
- package/dist/compare.js +291 -0
- package/dist/compiler.d.ts +10 -0
- package/dist/compiler.js +1240 -0
- package/dist/compose.d.ts +9 -0
- package/dist/compose.js +72 -0
- package/dist/core.d.ts +87 -0
- package/dist/core.js +207 -0
- package/dist/coverage-cli.d.ts +1 -0
- package/dist/coverage-cli.js +42 -0
- package/dist/declaration-sources.d.ts +3 -0
- package/dist/declaration-sources.js +51 -0
- package/dist/declared-graph.d.ts +3 -0
- package/dist/declared-graph.js +67 -0
- package/dist/display-name.d.ts +2 -0
- package/dist/display-name.js +8 -0
- package/dist/error-heat.d.ts +58 -0
- package/dist/error-heat.js +96 -0
- package/dist/evidence.d.ts +3 -0
- package/dist/evidence.js +68 -0
- package/dist/factory-graph.d.ts +7 -0
- package/dist/factory-graph.js +389 -0
- package/dist/factory-model.d.ts +111 -0
- package/dist/factory-model.js +1 -0
- package/dist/git-code.d.ts +47 -0
- package/dist/git-code.js +352 -0
- package/dist/git-refs.d.ts +4 -0
- package/dist/git-refs.js +37 -0
- package/dist/history-activity.d.ts +4 -0
- package/dist/history-activity.js +129 -0
- package/dist/history-churn.d.ts +36 -0
- package/dist/history-churn.js +302 -0
- package/dist/history-git.d.ts +21 -0
- package/dist/history-git.js +125 -0
- package/dist/history-ledger.d.ts +43 -0
- package/dist/history-ledger.js +450 -0
- package/dist/history-ownership.d.ts +10 -0
- package/dist/history-ownership.js +75 -0
- package/dist/history-source.d.ts +13 -0
- package/dist/history-source.js +100 -0
- package/dist/integrations-cli.d.ts +2 -0
- package/dist/integrations-cli.js +159 -0
- package/dist/interface-map.d.ts +15 -0
- package/dist/interface-map.js +125 -0
- package/dist/issue-cache.d.ts +9 -0
- package/dist/issue-cache.js +68 -0
- package/dist/issue-cli.d.ts +1 -0
- package/dist/issue-cli.js +89 -0
- package/dist/issue-links.d.ts +15 -0
- package/dist/issue-links.js +125 -0
- package/dist/linear-issues.d.ts +19 -0
- package/dist/linear-issues.js +124 -0
- package/dist/local-runtime.d.ts +8 -0
- package/dist/local-runtime.js +59 -0
- package/dist/map-activity.d.ts +73 -0
- package/dist/map-activity.js +234 -0
- package/dist/map-model.d.ts +5 -0
- package/dist/map-model.js +166 -0
- package/dist/map-quality.d.ts +20 -0
- package/dist/map-quality.js +61 -0
- package/dist/mapping-coverage.d.ts +87 -0
- package/dist/mapping-coverage.js +404 -0
- package/dist/model.d.ts +186 -0
- package/dist/model.js +66 -0
- package/dist/operation-benchmark-worker.d.ts +2 -0
- package/dist/operation-benchmark-worker.js +60 -0
- package/dist/operation-benchmark.d.ts +29 -0
- package/dist/operation-benchmark.js +1 -0
- package/dist/otel-metrics.d.ts +21 -0
- package/dist/otel-metrics.js +146 -0
- package/dist/performance-model.d.ts +185 -0
- package/dist/performance-model.js +396 -0
- package/dist/product-map.d.ts +71 -0
- package/dist/product-map.js +197 -0
- package/dist/provider-access.cjs +207 -0
- package/dist/provider-access.d.cts +14 -0
- package/dist/public-boundaries.d.ts +13 -0
- package/dist/public-boundaries.js +115 -0
- package/dist/reports-cli.d.ts +1 -0
- package/dist/reports-cli.js +111 -0
- package/dist/reports-model.d.ts +27 -0
- package/dist/reports-model.js +39 -0
- package/dist/reports.d.ts +23 -0
- package/dist/reports.js +223 -0
- package/dist/repository-map.d.ts +22 -0
- package/dist/repository-map.js +153 -0
- package/dist/resource-cache.d.ts +17 -0
- package/dist/resource-cache.js +65 -0
- package/dist/review-cli.d.ts +19 -0
- package/dist/review-cli.js +224 -0
- package/dist/review.d.ts +48 -0
- package/dist/review.js +289 -0
- package/dist/runtime-metrics.d.ts +26 -0
- package/dist/runtime-metrics.js +290 -0
- package/dist/scope.d.ts +14 -0
- package/dist/scope.js +168 -0
- package/dist/sentry-activity.d.ts +39 -0
- package/dist/sentry-activity.js +174 -0
- package/dist/sentry.d.ts +130 -0
- package/dist/sentry.js +369 -0
- package/dist/service-release.d.ts +16 -0
- package/dist/service-release.js +14 -0
- package/dist/setup-cli.d.ts +2 -0
- package/dist/setup-cli.js +52 -0
- package/dist/setup-kit.cjs +163 -0
- package/dist/setup-kit.d.cts +32 -0
- package/dist/source-index.d.ts +37 -0
- package/dist/source-index.js +170 -0
- package/dist/source-review-git.d.ts +7 -0
- package/dist/source-review-git.js +105 -0
- package/dist/source-review.d.ts +18 -0
- package/dist/source-review.js +573 -0
- package/dist/telemetry.d.ts +17 -0
- package/dist/telemetry.js +51 -0
- package/dist/time-window.d.ts +9 -0
- package/dist/time-window.js +35 -0
- package/dist/trace-evidence.d.ts +23 -0
- package/dist/trace-evidence.js +55 -0
- package/dist/trace-model.d.ts +26 -0
- package/dist/trace-model.js +1 -0
- package/dist/tracing.d.ts +44 -0
- package/dist/tracing.js +123 -0
- package/dist/work-check.d.ts +18 -0
- package/dist/work-check.js +115 -0
- package/dist/work-cli.d.ts +1 -0
- package/dist/work-cli.js +176 -0
- package/dist/work-context.d.ts +59 -0
- package/dist/work-context.js +594 -0
- package/dist/work-intents.d.ts +6 -0
- package/dist/work-intents.js +140 -0
- package/dist/work-items.d.ts +58 -0
- package/dist/work-items.js +86 -0
- package/dist/work-lock-check.d.ts +12 -0
- package/dist/work-lock-check.js +339 -0
- package/dist/work-locks.d.ts +10 -0
- package/dist/work-locks.js +98 -0
- package/dist/work-model.d.ts +119 -0
- package/dist/work-model.js +310 -0
- package/dist/work-review-git.d.ts +8 -0
- package/dist/work-review-git.js +111 -0
- package/dist/work-review.d.ts +26 -0
- package/dist/work-review.js +426 -0
- package/dist/work-switcher-model.d.ts +43 -0
- package/dist/work-switcher-model.js +79 -0
- package/dist/work-switcher.d.ts +6 -0
- package/dist/work-switcher.js +171 -0
- package/dist/working-cli.d.ts +1 -0
- package/dist/working-cli.js +33 -0
- package/dist/working-code.d.ts +74 -0
- package/dist/working-code.js +421 -0
- package/dist/workspace-notes.d.ts +71 -0
- package/dist/workspace-notes.js +177 -0
- package/dist/workspace-tests.d.ts +21 -0
- package/dist/workspace-tests.js +573 -0
- package/package.json +547 -4
- package/src/activity-volume.ts +149 -0
- package/src/annotations.ts +485 -0
- package/src/benchmark-cli.ts +118 -0
- package/src/benchmark-worker.ts +22 -0
- package/src/benchmarks.ts +493 -0
- package/src/bin.ts +54 -0
- package/src/block-cli.ts +106 -0
- package/src/block-documents.ts +117 -0
- package/src/change-impact.ts +280 -0
- package/src/check-source.ts +82 -0
- package/src/checks-model.ts +108 -0
- package/src/cli.ts +440 -0
- package/src/code-model.ts +159 -0
- package/src/code-store.ts +98 -0
- package/src/compare-artifact.ts +314 -0
- package/src/compare.ts +440 -0
- package/src/compiler.ts +1512 -0
- package/src/compose.ts +94 -0
- package/src/core.ts +361 -0
- package/src/coverage-cli.ts +52 -0
- package/src/declaration-sources.ts +69 -0
- package/src/declared-graph.ts +75 -0
- package/src/display-name.ts +8 -0
- package/src/error-heat.ts +161 -0
- package/src/evidence.ts +94 -0
- package/src/factory-graph.ts +462 -0
- package/src/factory-model.ts +82 -0
- package/src/git-code.ts +461 -0
- package/src/git-refs.ts +43 -0
- package/src/history-activity.ts +146 -0
- package/src/history-churn.ts +416 -0
- package/src/history-git.ts +163 -0
- package/src/history-ledger.ts +636 -0
- package/src/history-ownership.ts +116 -0
- package/src/history-source.ts +117 -0
- package/src/integrations-cli.ts +187 -0
- package/src/interface-map.ts +166 -0
- package/src/issue-cache.ts +96 -0
- package/src/issue-cli.ts +137 -0
- package/src/issue-links.ts +153 -0
- package/src/linear-issues.ts +154 -0
- package/src/local-runtime.ts +70 -0
- package/src/map-activity.ts +309 -0
- package/src/map-model.ts +213 -0
- package/src/map-quality.ts +66 -0
- package/src/mapping-coverage.ts +570 -0
- package/src/model.ts +228 -0
- package/src/operation-benchmark-worker.ts +60 -0
- package/src/operation-benchmark.ts +28 -0
- package/src/otel-metrics.ts +176 -0
- package/src/performance-model.ts +575 -0
- package/src/product-map.ts +271 -0
- package/src/provider-access.cjs +207 -0
- package/src/provider-access.d.cts +14 -0
- package/src/public-boundaries.ts +143 -0
- package/src/reports-cli.ts +125 -0
- package/src/reports-model.ts +73 -0
- package/src/reports.ts +276 -0
- package/src/repository-map.ts +191 -0
- package/src/resource-cache.ts +76 -0
- package/src/review-cli.ts +256 -0
- package/src/review.ts +376 -0
- package/src/runtime-metrics.ts +386 -0
- package/src/scope.ts +192 -0
- package/src/sentry-activity.ts +234 -0
- package/src/sentry.ts +545 -0
- package/src/service-release.ts +18 -0
- package/src/setup-cli.ts +58 -0
- package/src/setup-kit.cjs +163 -0
- package/src/setup-kit.d.cts +32 -0
- package/src/source-index.ts +208 -0
- package/src/source-review-git.ts +131 -0
- package/src/source-review.ts +736 -0
- package/src/telemetry.ts +68 -0
- package/src/time-window.ts +51 -0
- package/src/trace-evidence.ts +80 -0
- package/src/trace-model.ts +26 -0
- package/src/tracing.ts +165 -0
- package/src/work-check.ts +149 -0
- package/src/work-cli.ts +229 -0
- package/src/work-context.ts +753 -0
- package/src/work-intents.ts +196 -0
- package/src/work-items.ts +151 -0
- package/src/work-lock-check.ts +549 -0
- package/src/work-locks.ts +108 -0
- package/src/work-model.ts +466 -0
- package/src/work-review-git.ts +130 -0
- package/src/work-review.ts +573 -0
- package/src/work-switcher-model.ts +121 -0
- package/src/work-switcher.ts +191 -0
- package/src/working-cli.ts +38 -0
- package/src/working-code.ts +582 -0
- package/src/workspace-notes.ts +203 -0
- package/src/workspace-tests.ts +654 -0
- package/toolkit/GUIDE.md +354 -0
- package/toolkit/SKILL.md +142 -0
- package/toolkit/bin/fractory +2 -0
- package/toolkit/build.json +1 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/** Local confirmation records: current source evidence, never inferred completion or test coverage. */
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { readFileSync, statSync } from "node:fs";
|
|
4
|
+
import type { Connection, DefinitionGraph, Element, SourceRef } from "./model";
|
|
5
|
+
import type { WorkIntentState, WorkPlan, WorkProposal } from "./work-model";
|
|
6
|
+
import { checkedPath } from "./workspace-notes";
|
|
7
|
+
|
|
8
|
+
const hash = (value: string | Buffer) =>
|
|
9
|
+
createHash("sha256").update(value).digest("hex");
|
|
10
|
+
const stable = (value: unknown): string =>
|
|
11
|
+
JSON.stringify(value, (_key, item) =>
|
|
12
|
+
item && typeof item === "object" && !Array.isArray(item)
|
|
13
|
+
? Object.fromEntries(
|
|
14
|
+
Object.keys(item)
|
|
15
|
+
.sort()
|
|
16
|
+
.map((key) => [key, item[key]]),
|
|
17
|
+
)
|
|
18
|
+
: item,
|
|
19
|
+
);
|
|
20
|
+
const files = new Map<
|
|
21
|
+
string,
|
|
22
|
+
{ stamp: string; digest: string; bytes: number }
|
|
23
|
+
>();
|
|
24
|
+
function fingerprint(root: string, file: string) {
|
|
25
|
+
const path = checkedPath(root, file),
|
|
26
|
+
stat = statSync(path);
|
|
27
|
+
if (!stat.isFile() || stat.size > 2 * 1024 * 1024)
|
|
28
|
+
throw Error("Choose a smaller implementation block to confirm.");
|
|
29
|
+
const stamp = `${stat.ino}:${stat.size}:${stat.mtimeMs}:${stat.ctimeMs}`;
|
|
30
|
+
let saved = files.get(path);
|
|
31
|
+
if (saved?.stamp !== stamp) {
|
|
32
|
+
saved = { stamp, digest: hash(readFileSync(path)), bytes: stat.size };
|
|
33
|
+
files.set(path, saved);
|
|
34
|
+
if (files.size > 2048) files.delete(files.keys().next().value!);
|
|
35
|
+
}
|
|
36
|
+
return saved!;
|
|
37
|
+
}
|
|
38
|
+
export function intentTarget(graph: DefinitionGraph, proposal: WorkProposal) {
|
|
39
|
+
const id =
|
|
40
|
+
proposal.implementation ||
|
|
41
|
+
(proposal.kind === "annotation" ? proposal.target : undefined);
|
|
42
|
+
return (
|
|
43
|
+
id &&
|
|
44
|
+
(proposal.kind === "connection"
|
|
45
|
+
? graph.connections.find(
|
|
46
|
+
(e) => e.id === id && e.provenance !== "proposed",
|
|
47
|
+
)
|
|
48
|
+
: graph.elements.find(
|
|
49
|
+
(n) => n.id === id && n.provenance !== "proposed",
|
|
50
|
+
) ||
|
|
51
|
+
(proposal.kind === "annotation"
|
|
52
|
+
? graph.connections.find(
|
|
53
|
+
(e) => e.id === id && e.provenance !== "proposed",
|
|
54
|
+
)
|
|
55
|
+
: undefined))
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
/** No fuzzy match: an agent/developer chooses the implementation identity explicitly. */
|
|
59
|
+
export function intentEvidence(
|
|
60
|
+
root: string,
|
|
61
|
+
graph: DefinitionGraph,
|
|
62
|
+
proposal: WorkProposal,
|
|
63
|
+
baseline?: DefinitionGraph,
|
|
64
|
+
) {
|
|
65
|
+
const target = intentTarget(graph, proposal);
|
|
66
|
+
const removed =
|
|
67
|
+
proposal.kind === "annotation" &&
|
|
68
|
+
proposal.change === "remove" &&
|
|
69
|
+
!target &&
|
|
70
|
+
proposal.target &&
|
|
71
|
+
[...(baseline?.elements || []), ...(baseline?.connections || [])].find(
|
|
72
|
+
(n) => n.id === proposal.target,
|
|
73
|
+
);
|
|
74
|
+
if (!target && !removed)
|
|
75
|
+
throw Error("Link the real implementation on the map first.");
|
|
76
|
+
if (proposal.change === "remove" && target)
|
|
77
|
+
throw Error("This block or connection is still on the map.");
|
|
78
|
+
const nodes: (Element | Connection)[] = target
|
|
79
|
+
? [target]
|
|
80
|
+
: [removed as Element | Connection];
|
|
81
|
+
if (target && "kind" in target) {
|
|
82
|
+
const ids = new Set([target.id]);
|
|
83
|
+
for (let i = 0, changed = true; changed && i < graph.elements.length; i++) {
|
|
84
|
+
changed = false;
|
|
85
|
+
for (const n of graph.elements)
|
|
86
|
+
if (n.parent && ids.has(n.parent) && !ids.has(n.id)) {
|
|
87
|
+
ids.add(n.id);
|
|
88
|
+
nodes.push(n);
|
|
89
|
+
changed = true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const refs: SourceRef[] = nodes.flatMap((n) => [
|
|
94
|
+
...("kind" in n && n.source ? [n.source] : []),
|
|
95
|
+
...("sourceRef" in n && n.sourceRef ? [n.sourceRef] : []),
|
|
96
|
+
...(n.sources || []),
|
|
97
|
+
]);
|
|
98
|
+
if (!refs.length)
|
|
99
|
+
throw Error(
|
|
100
|
+
"Map this implementation to real source code before marking it done.",
|
|
101
|
+
);
|
|
102
|
+
const paths = new Set(refs.map((r) => r.file));
|
|
103
|
+
for (const n of nodes)
|
|
104
|
+
if ("attachments" in n) {
|
|
105
|
+
for (const path of [
|
|
106
|
+
...(n.attachments?.docs || []),
|
|
107
|
+
...(n.attachments?.tests || []),
|
|
108
|
+
])
|
|
109
|
+
paths.add(path);
|
|
110
|
+
}
|
|
111
|
+
if (paths.size > 256)
|
|
112
|
+
throw Error("Choose a smaller implementation block to confirm.");
|
|
113
|
+
let bytes = 0;
|
|
114
|
+
const evidence: [string, string][] = [];
|
|
115
|
+
for (const path of [...paths].sort()) {
|
|
116
|
+
let source;
|
|
117
|
+
try {
|
|
118
|
+
source = fingerprint(root, path);
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (refs.some((r) => r.file === path) && !removed)
|
|
121
|
+
throw Error(
|
|
122
|
+
"The implementation source is missing or unavailable. Refresh its map before confirming.",
|
|
123
|
+
);
|
|
124
|
+
evidence.push([path, "missing"]);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
bytes += source.bytes;
|
|
128
|
+
if (bytes > 16 * 1024 * 1024)
|
|
129
|
+
throw Error("Choose a smaller implementation block to confirm.");
|
|
130
|
+
if (
|
|
131
|
+
!removed &&
|
|
132
|
+
refs.some(
|
|
133
|
+
(r) =>
|
|
134
|
+
r.file === path &&
|
|
135
|
+
(!/^(?:[a-f0-9]{16}|[a-f0-9]{64})$/.test(r.digest) ||
|
|
136
|
+
!source.digest.startsWith(r.digest)),
|
|
137
|
+
)
|
|
138
|
+
)
|
|
139
|
+
throw Error(
|
|
140
|
+
"The map’s source references are stale. Regenerate the map before confirming.",
|
|
141
|
+
);
|
|
142
|
+
evidence.push([path, source.digest]);
|
|
143
|
+
}
|
|
144
|
+
const {
|
|
145
|
+
outcome: _outcome,
|
|
146
|
+
position: _position,
|
|
147
|
+
resolved: _resolved,
|
|
148
|
+
createdAt: _createdAt,
|
|
149
|
+
...request
|
|
150
|
+
} = proposal;
|
|
151
|
+
return hash(
|
|
152
|
+
stable({
|
|
153
|
+
request,
|
|
154
|
+
nodes: nodes.sort((a, b) => a.id.localeCompare(b.id)),
|
|
155
|
+
removed: !!removed,
|
|
156
|
+
files: evidence,
|
|
157
|
+
}),
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
export function workIntentStates(
|
|
161
|
+
root: string,
|
|
162
|
+
graph: DefinitionGraph,
|
|
163
|
+
plan?: WorkPlan,
|
|
164
|
+
baseline?: DefinitionGraph,
|
|
165
|
+
): Record<string, WorkIntentState> {
|
|
166
|
+
return Object.fromEntries(
|
|
167
|
+
(plan?.proposals || []).map((p) => {
|
|
168
|
+
const implementation =
|
|
169
|
+
p.implementation || (p.kind === "annotation" ? p.target : undefined);
|
|
170
|
+
let state: WorkIntentState = {
|
|
171
|
+
status: p.outcome?.status || "planned",
|
|
172
|
+
implementation,
|
|
173
|
+
};
|
|
174
|
+
if (p.outcome?.status === "done")
|
|
175
|
+
try {
|
|
176
|
+
if (intentEvidence(root, graph, p, baseline) !== p.outcome.evidence)
|
|
177
|
+
state = {
|
|
178
|
+
status: "changed",
|
|
179
|
+
implementation,
|
|
180
|
+
reason:
|
|
181
|
+
"The request or implementation changed after it was marked done.",
|
|
182
|
+
};
|
|
183
|
+
} catch (e) {
|
|
184
|
+
state = {
|
|
185
|
+
status: "changed",
|
|
186
|
+
implementation,
|
|
187
|
+
reason:
|
|
188
|
+
e instanceof Error
|
|
189
|
+
? e.message
|
|
190
|
+
: "Implementation evidence is unavailable.",
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
return [p.id, state];
|
|
194
|
+
}),
|
|
195
|
+
);
|
|
196
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { DefinitionGraph } from "./model";
|
|
2
|
+
export type WorkState =
|
|
3
|
+
| "todo"
|
|
4
|
+
| "in_progress"
|
|
5
|
+
| "done"
|
|
6
|
+
| "archived"
|
|
7
|
+
| "canceled"
|
|
8
|
+
| "unknown";
|
|
9
|
+
export interface LinearWorkIssue {
|
|
10
|
+
id: string;
|
|
11
|
+
identifier: string;
|
|
12
|
+
title: string;
|
|
13
|
+
url: string;
|
|
14
|
+
state: { name: string; type: string };
|
|
15
|
+
updatedAt: string;
|
|
16
|
+
checkedAt: string;
|
|
17
|
+
archivedAt?: string | null;
|
|
18
|
+
}
|
|
19
|
+
export interface IssueLink {
|
|
20
|
+
issue: string;
|
|
21
|
+
identifier?: string;
|
|
22
|
+
blocks: string[];
|
|
23
|
+
}
|
|
24
|
+
export interface IssueLinks {
|
|
25
|
+
schema: "fractal.issues.v1";
|
|
26
|
+
workspace?: { id?: string; name?: string; url: string };
|
|
27
|
+
links: IssueLink[];
|
|
28
|
+
}
|
|
29
|
+
export interface WorkItem extends IssueLink {
|
|
30
|
+
metadata?: LinearWorkIssue;
|
|
31
|
+
state: WorkState;
|
|
32
|
+
}
|
|
33
|
+
export interface WorkView {
|
|
34
|
+
_cache?: { at: string; stale: boolean; refreshing: boolean; failed: boolean };
|
|
35
|
+
revision: string;
|
|
36
|
+
registry: IssueLinks;
|
|
37
|
+
items: WorkItem[];
|
|
38
|
+
connection: {
|
|
39
|
+
configured: boolean;
|
|
40
|
+
notice?: string;
|
|
41
|
+
source: "linear" | "recorded" | "unavailable";
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function issueReference(value: string): {
|
|
45
|
+
key: string;
|
|
46
|
+
workspace?: string;
|
|
47
|
+
url?: string;
|
|
48
|
+
} {
|
|
49
|
+
value = value.trim();
|
|
50
|
+
if (/^https:\/\//i.test(value)) {
|
|
51
|
+
const url = new URL(value),
|
|
52
|
+
parts = url.pathname.split("/").filter(Boolean);
|
|
53
|
+
if (
|
|
54
|
+
url.hostname !== "linear.app" ||
|
|
55
|
+
url.port ||
|
|
56
|
+
url.username ||
|
|
57
|
+
url.password ||
|
|
58
|
+
parts[1] !== "issue"
|
|
59
|
+
)
|
|
60
|
+
throw Error("Use a Linear issue URL or identifier");
|
|
61
|
+
const key = parts[2]?.toUpperCase();
|
|
62
|
+
if (!/^[A-Z][A-Z0-9]{0,15}-[1-9][0-9]{0,9}$/.test(key || ""))
|
|
63
|
+
throw Error("Invalid Linear issue identifier");
|
|
64
|
+
return {
|
|
65
|
+
key,
|
|
66
|
+
workspace: parts[0],
|
|
67
|
+
url: `https://linear.app/${parts[0]}/issue/${key}`,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (/^[A-Z][A-Z0-9]{0,15}-[1-9][0-9]{0,9}$/i.test(value))
|
|
71
|
+
return { key: value.toUpperCase() };
|
|
72
|
+
if (/^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(value))
|
|
73
|
+
return { key: value.toLowerCase() };
|
|
74
|
+
throw Error("Enter a Linear issue identifier, UUID or URL");
|
|
75
|
+
}
|
|
76
|
+
export function workState(issue?: LinearWorkIssue): WorkState {
|
|
77
|
+
if (!issue) return "unknown";
|
|
78
|
+
if (issue.archivedAt) return "archived";
|
|
79
|
+
if (issue.state.type === "started") return "in_progress";
|
|
80
|
+
if (issue.state.type === "completed") return "done";
|
|
81
|
+
if (["canceled", "duplicate"].includes(issue.state.type)) return "canceled";
|
|
82
|
+
return ["triage", "backlog", "unstarted"].includes(issue.state.type)
|
|
83
|
+
? "todo"
|
|
84
|
+
: "unknown";
|
|
85
|
+
}
|
|
86
|
+
/** Use the provider's typed state; do not guess progress from a title or an assignee. */
|
|
87
|
+
export function workItems(
|
|
88
|
+
registry: IssueLinks,
|
|
89
|
+
metadata: LinearWorkIssue[],
|
|
90
|
+
includeUnlinked = false,
|
|
91
|
+
): WorkItem[] {
|
|
92
|
+
const byId = new Map(
|
|
93
|
+
metadata.flatMap(
|
|
94
|
+
(issue) =>
|
|
95
|
+
[
|
|
96
|
+
[issue.id, issue],
|
|
97
|
+
[issue.identifier, issue],
|
|
98
|
+
] as const,
|
|
99
|
+
),
|
|
100
|
+
);
|
|
101
|
+
const items = new Map<string, WorkItem>();
|
|
102
|
+
for (const link of registry.links) {
|
|
103
|
+
const issue =
|
|
104
|
+
byId.get(link.issue) ||
|
|
105
|
+
(link.identifier ? byId.get(link.identifier) : undefined);
|
|
106
|
+
const key = issue?.id || link.issue,
|
|
107
|
+
prior = items.get(key);
|
|
108
|
+
items.set(key, {
|
|
109
|
+
...link,
|
|
110
|
+
blocks: [...new Set([...(prior?.blocks || []), ...link.blocks])],
|
|
111
|
+
metadata: issue,
|
|
112
|
+
state: workState(issue),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
if (includeUnlinked)
|
|
116
|
+
for (const issue of metadata)
|
|
117
|
+
if (!items.has(issue.id))
|
|
118
|
+
items.set(issue.id, {
|
|
119
|
+
issue: issue.id,
|
|
120
|
+
identifier: issue.identifier,
|
|
121
|
+
blocks: [],
|
|
122
|
+
metadata: issue,
|
|
123
|
+
state: workState(issue),
|
|
124
|
+
});
|
|
125
|
+
return [...items.values()];
|
|
126
|
+
}
|
|
127
|
+
export function workForScope(
|
|
128
|
+
graph: DefinitionGraph,
|
|
129
|
+
items: WorkItem[],
|
|
130
|
+
scope: string,
|
|
131
|
+
): WorkItem[] {
|
|
132
|
+
if (scope === graph.id) return items;
|
|
133
|
+
const descendants = new Set([scope]);
|
|
134
|
+
for (let changed = true; changed; ) {
|
|
135
|
+
changed = false;
|
|
136
|
+
for (const node of graph.elements)
|
|
137
|
+
if (
|
|
138
|
+
node.parent &&
|
|
139
|
+
descendants.has(node.parent) &&
|
|
140
|
+
!descendants.has(node.id)
|
|
141
|
+
) {
|
|
142
|
+
descendants.add(node.id);
|
|
143
|
+
changed = true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return items.filter((item) =>
|
|
147
|
+
item.blocks.some((block) =>
|
|
148
|
+
descendants.has(graph.aliases?.[block] || block),
|
|
149
|
+
),
|
|
150
|
+
);
|
|
151
|
+
}
|