@granular-software/fractory 0.0.0-stage → 0.1.24
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 +118 -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 +1083 -0
- package/dist/compose.d.ts +9 -0
- package/dist/compose.js +72 -0
- package/dist/core.d.ts +86 -0
- package/dist/core.js +206 -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 +66 -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 +4 -0
- package/dist/factory-graph.js +318 -0
- package/dist/factory-model.d.ts +97 -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/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 +14 -0
- package/dist/map-quality.js +56 -0
- package/dist/mapping-coverage.d.ts +87 -0
- package/dist/mapping-coverage.js +404 -0
- package/dist/model.d.ts +182 -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 +69 -0
- package/dist/product-map.js +168 -0
- package/dist/provider-access.cjs +207 -0
- package/dist/provider-access.d.cts +14 -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 +151 -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 +12 -0
- package/dist/scope.js +94 -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 +166 -0
- package/dist/source-review-git.d.ts +7 -0
- package/dist/source-review-git.js +103 -0
- package/dist/source-review.d.ts +16 -0
- package/dist/source-review.js +493 -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 +17 -0
- package/dist/work-check.js +110 -0
- package/dist/work-cli.d.ts +1 -0
- package/dist/work-cli.js +148 -0
- package/dist/work-context.d.ts +57 -0
- package/dist/work-context.js +568 -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-model.d.ts +110 -0
- package/dist/work-model.js +261 -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 +481 -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 +1326 -0
- package/src/compose.ts +94 -0
- package/src/core.ts +357 -0
- package/src/coverage-cli.ts +52 -0
- package/src/declaration-sources.ts +69 -0
- package/src/declared-graph.ts +74 -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 +378 -0
- package/src/factory-model.ts +73 -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/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 +61 -0
- package/src/mapping-coverage.ts +570 -0
- package/src/model.ts +221 -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 +236 -0
- package/src/provider-access.cjs +207 -0
- package/src/provider-access.d.cts +14 -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 +189 -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 +103 -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 +205 -0
- package/src/source-review-git.ts +129 -0
- package/src/source-review.ts +637 -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 +143 -0
- package/src/work-cli.ts +195 -0
- package/src/work-context.ts +713 -0
- package/src/work-intents.ts +196 -0
- package/src/work-items.ts +151 -0
- package/src/work-model.ts +400 -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 +305 -0
- package/toolkit/SKILL.md +131 -0
- package/toolkit/bin/fractory +2 -0
- package/toolkit/build.json +1 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Shared UTC, half-open time interval: from inclusive, to exclusive. */
|
|
2
|
+
export interface TimeWindow {
|
|
3
|
+
from: string;
|
|
4
|
+
to: string;
|
|
5
|
+
}
|
|
6
|
+
export const DAY_MS = 86_400_000;
|
|
7
|
+
export function recentWindow(days = 14, now = Date.now()): TimeWindow {
|
|
8
|
+
const end = Math.floor(now / 60_000) * 60_000;
|
|
9
|
+
return {
|
|
10
|
+
from: new Date(end - days * DAY_MS).toISOString(),
|
|
11
|
+
to: new Date(end).toISOString(),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function parseTimeWindow(
|
|
15
|
+
params: Pick<URLSearchParams, "get">,
|
|
16
|
+
now = Date.now(),
|
|
17
|
+
maxDays = 90,
|
|
18
|
+
): TimeWindow | undefined {
|
|
19
|
+
const from = params.get("from"),
|
|
20
|
+
to = params.get("to");
|
|
21
|
+
if (from === null && to === null) return;
|
|
22
|
+
const start = from && Date.parse(from),
|
|
23
|
+
end = to && Date.parse(to);
|
|
24
|
+
if (
|
|
25
|
+
!from ||
|
|
26
|
+
!to ||
|
|
27
|
+
!/^\d{4}-\d{2}-\d{2}T/.test(from) ||
|
|
28
|
+
!/^\d{4}-\d{2}-\d{2}T/.test(to) ||
|
|
29
|
+
!Number.isFinite(start) ||
|
|
30
|
+
!Number.isFinite(end) ||
|
|
31
|
+
Number(start) < 0 ||
|
|
32
|
+
Number(start) >= Number(end) ||
|
|
33
|
+
Number(end) > now + 60_000 ||
|
|
34
|
+
Number(end) - Number(start) > maxDays * DAY_MS + 1000
|
|
35
|
+
)
|
|
36
|
+
throw Error(
|
|
37
|
+
`Choose a valid time range of up to ${maxDays} days, ending no later than now.`,
|
|
38
|
+
);
|
|
39
|
+
return {
|
|
40
|
+
from: new Date(Number(start)).toISOString(),
|
|
41
|
+
to: new Date(Number(end)).toISOString(),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function inTimeWindow(at: string | undefined, window: TimeWindow) {
|
|
45
|
+
const value = Date.parse(at || "");
|
|
46
|
+
return (
|
|
47
|
+
Number.isFinite(value) &&
|
|
48
|
+
value >= Date.parse(window.from) &&
|
|
49
|
+
value < Date.parse(window.to)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { DefinitionGraph, Connection } from "./model";
|
|
2
|
+
import type { TraceSnapshot, TraceEvent } from "./trace-model";
|
|
3
|
+
|
|
4
|
+
export interface ObservedSpan {
|
|
5
|
+
spanId: string;
|
|
6
|
+
traceId: string;
|
|
7
|
+
elementId: string;
|
|
8
|
+
contract: string;
|
|
9
|
+
parentSpanId?: string;
|
|
10
|
+
linkedSpanId?: string;
|
|
11
|
+
linkedTraceId?: string;
|
|
12
|
+
timestamp: number;
|
|
13
|
+
durationMs?: number;
|
|
14
|
+
jobStatus?: string;
|
|
15
|
+
status: TraceEvent["status"];
|
|
16
|
+
failureCode?: TraceEvent["failureCode"];
|
|
17
|
+
startObserved: boolean;
|
|
18
|
+
}
|
|
19
|
+
/** Only compatible, recorded spans can color the graph. State alone never creates a span. */
|
|
20
|
+
export function executionPath(
|
|
21
|
+
graph: DefinitionGraph,
|
|
22
|
+
snapshot: Pick<TraceSnapshot, "events"> | null | undefined,
|
|
23
|
+
) {
|
|
24
|
+
const byId = new Map(graph.elements.map((n) => [n.id, n]));
|
|
25
|
+
const spans = new Map<string, ObservedSpan>();
|
|
26
|
+
let incompatibleEvents = 0;
|
|
27
|
+
for (const event of snapshot?.events || []) {
|
|
28
|
+
const node = byId.get(event.elementId);
|
|
29
|
+
if (
|
|
30
|
+
event.definitionRevision !==
|
|
31
|
+
(node?.definitionRevision || graph.revision) ||
|
|
32
|
+
node?.contract?.id !== event.contract ||
|
|
33
|
+
(graph.codeRevision !== undefined &&
|
|
34
|
+
event.codeRevision !== graph.codeRevision)
|
|
35
|
+
) {
|
|
36
|
+
incompatibleEvents++;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const previous = spans.get(event.spanId);
|
|
40
|
+
spans.set(event.spanId, {
|
|
41
|
+
spanId: event.spanId,
|
|
42
|
+
traceId: event.traceId,
|
|
43
|
+
elementId: event.elementId,
|
|
44
|
+
contract: event.contract,
|
|
45
|
+
parentSpanId: event.parentSpanId,
|
|
46
|
+
linkedSpanId: event.linkedSpanId,
|
|
47
|
+
linkedTraceId: event.linkedTraceId,
|
|
48
|
+
status: event.status,
|
|
49
|
+
durationMs: event.durationMs,
|
|
50
|
+
failureCode: event.failureCode,
|
|
51
|
+
jobStatus: event.jobStatus,
|
|
52
|
+
timestamp: previous?.timestamp ?? event.timestamp,
|
|
53
|
+
startObserved: previous?.startObserved || event.status === "started",
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const connections: Connection[] = [];
|
|
57
|
+
for (const span of spans.values()) {
|
|
58
|
+
const parent = spans.get(span.parentSpanId || span.linkedSpanId || "");
|
|
59
|
+
if (
|
|
60
|
+
!parent ||
|
|
61
|
+
(span.parentSpanId
|
|
62
|
+
? parent.traceId !== span.traceId
|
|
63
|
+
: parent.traceId !== span.linkedTraceId)
|
|
64
|
+
)
|
|
65
|
+
continue;
|
|
66
|
+
connections.push({
|
|
67
|
+
id: `observed:${span.spanId}`,
|
|
68
|
+
source: parent.elementId,
|
|
69
|
+
target: span.elementId,
|
|
70
|
+
relation: span.parentSpanId ? "calls" : "resumes",
|
|
71
|
+
label: `${span.parentSpanId ? "" : "Continuation · "}${span.contract} · ${span.jobStatus === "failed" ? "job failed" : span.status}`,
|
|
72
|
+
provenance: "observed",
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
spans: [...spans.values()].sort((a, b) => a.timestamp - b.timestamp),
|
|
77
|
+
connections,
|
|
78
|
+
incompatibleEvents,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Safe, payload-free records emitted only when a decorated boundary executes. */
|
|
2
|
+
export interface TraceEvent {
|
|
3
|
+
id: string;
|
|
4
|
+
traceId: string;
|
|
5
|
+
spanId: string;
|
|
6
|
+
parentSpanId?: string;
|
|
7
|
+
linkedSpanId?: string;
|
|
8
|
+
linkedTraceId?: string;
|
|
9
|
+
elementId: string;
|
|
10
|
+
contract: string;
|
|
11
|
+
definitionRevision: string;
|
|
12
|
+
codeRevision?: string;
|
|
13
|
+
timestamp: number;
|
|
14
|
+
durationMs?: number;
|
|
15
|
+
/** Persisted job state observed at the boundary; distinct from the method outcome. */
|
|
16
|
+
jobStatus?: string;
|
|
17
|
+
status: "started" | "completed" | "failed";
|
|
18
|
+
failureCode?: "InvalidInput" | "InvalidOutput" | "OperationFailed";
|
|
19
|
+
}
|
|
20
|
+
export interface TraceSnapshot {
|
|
21
|
+
schema: "fractal.trace.v1";
|
|
22
|
+
jobId: string;
|
|
23
|
+
events: TraceEvent[];
|
|
24
|
+
droppedEvents: number;
|
|
25
|
+
persistence: "available" | "degraded";
|
|
26
|
+
}
|
package/src/tracing.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { OperationRuntime } from "./core";
|
|
2
|
+
import { ContractViolation } from "./core";
|
|
3
|
+
import type { TraceEvent } from "./trace-model";
|
|
4
|
+
|
|
5
|
+
export interface TraceLink {
|
|
6
|
+
traceId: string;
|
|
7
|
+
spanId: string;
|
|
8
|
+
definitionRevision: string;
|
|
9
|
+
}
|
|
10
|
+
export interface TraceFrame {
|
|
11
|
+
owner: object;
|
|
12
|
+
traceId: string;
|
|
13
|
+
spanId?: string;
|
|
14
|
+
linkedSpanId?: string;
|
|
15
|
+
linkedTraceId?: string;
|
|
16
|
+
correlation: { jobId?: string; pending: TraceEvent[] };
|
|
17
|
+
}
|
|
18
|
+
export interface AsyncTraceScope {
|
|
19
|
+
getStore(): TraceFrame | undefined;
|
|
20
|
+
run<T>(frame: TraceFrame, callback: () => T): T;
|
|
21
|
+
}
|
|
22
|
+
/** Async context is supplied by the host; the core remains usable in a browser. */
|
|
23
|
+
export class TraceRuntime implements OperationRuntime {
|
|
24
|
+
constructor(
|
|
25
|
+
private readonly options: {
|
|
26
|
+
owner: object;
|
|
27
|
+
definitionRevision: string;
|
|
28
|
+
codeRevision?: string;
|
|
29
|
+
scope: AsyncTraceScope;
|
|
30
|
+
emit: (jobId: string, event: TraceEvent) => void;
|
|
31
|
+
observeJobStatus?: (
|
|
32
|
+
jobId: string,
|
|
33
|
+
contract: string,
|
|
34
|
+
) => string | undefined;
|
|
35
|
+
},
|
|
36
|
+
) {}
|
|
37
|
+
root<T>(
|
|
38
|
+
jobId: string | undefined,
|
|
39
|
+
predecessor: TraceLink | undefined,
|
|
40
|
+
execute: () => Promise<T>,
|
|
41
|
+
fresh = false,
|
|
42
|
+
): Promise<T> {
|
|
43
|
+
const current = this.current();
|
|
44
|
+
if (current && !fresh) {
|
|
45
|
+
if (!jobId || current.correlation.jobId === jobId) return execute();
|
|
46
|
+
if (!current.correlation.jobId) {
|
|
47
|
+
this.associate(jobId);
|
|
48
|
+
return execute();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const frame: TraceFrame = {
|
|
52
|
+
owner: this.options.owner,
|
|
53
|
+
traceId: crypto.randomUUID(),
|
|
54
|
+
linkedSpanId: predecessor?.spanId,
|
|
55
|
+
linkedTraceId: predecessor?.traceId,
|
|
56
|
+
correlation: { jobId, pending: [] },
|
|
57
|
+
};
|
|
58
|
+
return this.options.scope.run(frame, execute);
|
|
59
|
+
}
|
|
60
|
+
private current() {
|
|
61
|
+
const frame = this.options.scope.getStore();
|
|
62
|
+
return frame?.owner === this.options.owner ? frame : undefined;
|
|
63
|
+
}
|
|
64
|
+
associate(jobId: string) {
|
|
65
|
+
const frame = this.current();
|
|
66
|
+
if (!frame) throw new Error("Job correlation requires an active trace");
|
|
67
|
+
if (frame.correlation.jobId && frame.correlation.jobId !== jobId)
|
|
68
|
+
throw new Error("A trace cannot change job identity");
|
|
69
|
+
frame.correlation.jobId = jobId;
|
|
70
|
+
for (const event of frame.correlation.pending.splice(0))
|
|
71
|
+
this.emit(jobId, event);
|
|
72
|
+
}
|
|
73
|
+
reference(): TraceLink | undefined {
|
|
74
|
+
const frame = this.current();
|
|
75
|
+
return frame?.spanId
|
|
76
|
+
? {
|
|
77
|
+
traceId: frame.traceId,
|
|
78
|
+
spanId: frame.spanId,
|
|
79
|
+
definitionRevision: this.options.definitionRevision,
|
|
80
|
+
}
|
|
81
|
+
: undefined;
|
|
82
|
+
}
|
|
83
|
+
private emit(jobId: string, event: TraceEvent) {
|
|
84
|
+
try {
|
|
85
|
+
this.options.emit(jobId, event);
|
|
86
|
+
} catch {
|
|
87
|
+
/* Observation cannot change execution semantics. */
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
invoke<T>(
|
|
91
|
+
boundary: { elementId: string; operation: string; contract: string },
|
|
92
|
+
execute: () => Promise<T>,
|
|
93
|
+
): Promise<T> {
|
|
94
|
+
const parent = this.current();
|
|
95
|
+
if (!parent)
|
|
96
|
+
return this.root(undefined, undefined, () =>
|
|
97
|
+
this.invoke(boundary, execute),
|
|
98
|
+
);
|
|
99
|
+
const spanId = crypto.randomUUID();
|
|
100
|
+
const frame: TraceFrame = { ...parent, spanId };
|
|
101
|
+
const started = performance.now();
|
|
102
|
+
const publish = (
|
|
103
|
+
status: TraceEvent["status"],
|
|
104
|
+
failureCode?: TraceEvent["failureCode"],
|
|
105
|
+
) => {
|
|
106
|
+
let jobStatus: string | undefined;
|
|
107
|
+
if (status !== "started" && frame.correlation.jobId) {
|
|
108
|
+
try {
|
|
109
|
+
jobStatus = this.options.observeJobStatus?.(
|
|
110
|
+
frame.correlation.jobId,
|
|
111
|
+
boundary.contract,
|
|
112
|
+
);
|
|
113
|
+
} catch {
|
|
114
|
+
/* observation only */
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const event: TraceEvent = {
|
|
118
|
+
id: crypto.randomUUID(),
|
|
119
|
+
traceId: frame.traceId,
|
|
120
|
+
spanId,
|
|
121
|
+
...(parent.spanId ? { parentSpanId: parent.spanId } : {}),
|
|
122
|
+
...(!parent.spanId && parent.linkedSpanId
|
|
123
|
+
? {
|
|
124
|
+
linkedSpanId: parent.linkedSpanId,
|
|
125
|
+
linkedTraceId: parent.linkedTraceId,
|
|
126
|
+
}
|
|
127
|
+
: {}),
|
|
128
|
+
elementId: boundary.elementId,
|
|
129
|
+
contract: boundary.contract,
|
|
130
|
+
definitionRevision: this.options.definitionRevision,
|
|
131
|
+
...(this.options.codeRevision
|
|
132
|
+
? { codeRevision: this.options.codeRevision }
|
|
133
|
+
: {}),
|
|
134
|
+
timestamp: Date.now(),
|
|
135
|
+
status,
|
|
136
|
+
...(status !== "started"
|
|
137
|
+
? { durationMs: performance.now() - started }
|
|
138
|
+
: {}),
|
|
139
|
+
...(failureCode ? { failureCode } : {}),
|
|
140
|
+
...(jobStatus ? { jobStatus } : {}),
|
|
141
|
+
};
|
|
142
|
+
if (frame.correlation.jobId) this.emit(frame.correlation.jobId, event);
|
|
143
|
+
else if (frame.correlation.pending.length < 64)
|
|
144
|
+
frame.correlation.pending.push(event);
|
|
145
|
+
};
|
|
146
|
+
return this.options.scope.run(frame, async () => {
|
|
147
|
+
publish("started");
|
|
148
|
+
try {
|
|
149
|
+
const value = await execute();
|
|
150
|
+
publish("completed");
|
|
151
|
+
return value;
|
|
152
|
+
} catch (error) {
|
|
153
|
+
publish(
|
|
154
|
+
"failed",
|
|
155
|
+
error instanceof ContractViolation
|
|
156
|
+
? error.phase === "input"
|
|
157
|
+
? "InvalidInput"
|
|
158
|
+
: "InvalidOutput"
|
|
159
|
+
: "OperationFailed",
|
|
160
|
+
);
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { blockNoteFile } from "./workspace-notes";
|
|
2
|
+
import { readReport } from "./reports";
|
|
3
|
+
import type { DefinitionGraph } from "./model";
|
|
4
|
+
import { changedPaths } from "./git-code";
|
|
5
|
+
import { readGit, resolveComparisonRef } from "./git-refs";
|
|
6
|
+
import { parseWorkingStatus } from "./working-code";
|
|
7
|
+
import { readWorkPlan, workBaseline } from "./work-context";
|
|
8
|
+
import { scopeBlocks } from "./work-model";
|
|
9
|
+
|
|
10
|
+
/** Conservative file ownership check. Shared and unknown ownership never produce a pass. */
|
|
11
|
+
export async function checkWorkScope(
|
|
12
|
+
root: string,
|
|
13
|
+
id: string,
|
|
14
|
+
currentGraph: DefinitionGraph,
|
|
15
|
+
) {
|
|
16
|
+
const { entry, plan } = readWorkPlan(root, id);
|
|
17
|
+
const baseline = workBaseline(root, id);
|
|
18
|
+
const head = resolveComparisonRef(entry.root, "HEAD");
|
|
19
|
+
const committed = changedPaths(entry.root, plan.baseCommit, head).map(
|
|
20
|
+
(file) => file.path,
|
|
21
|
+
);
|
|
22
|
+
const working = parseWorkingStatus(
|
|
23
|
+
readGit(entry.root, [
|
|
24
|
+
"status",
|
|
25
|
+
"--porcelain=v2",
|
|
26
|
+
"-z",
|
|
27
|
+
"--untracked-files=all",
|
|
28
|
+
]),
|
|
29
|
+
);
|
|
30
|
+
const paths = [
|
|
31
|
+
...new Set([
|
|
32
|
+
...committed,
|
|
33
|
+
...working.flatMap((path) => [
|
|
34
|
+
path.path,
|
|
35
|
+
...(path.originalPath ? [path.originalPath] : []),
|
|
36
|
+
]),
|
|
37
|
+
]),
|
|
38
|
+
].sort();
|
|
39
|
+
if (paths.length > 20000)
|
|
40
|
+
throw Error("Scope check exceeds the path budget; no pass was issued.");
|
|
41
|
+
const allowed = scopeBlocks(currentGraph, plan.scope, plan.excluded);
|
|
42
|
+
const baseAllowed = scopeBlocks(baseline, plan.scope, plan.excluded);
|
|
43
|
+
function owners(graph: DefinitionGraph, path: string) {
|
|
44
|
+
if (/^docs\/fractory\/reports\/[a-f0-9-]{36}\.md$/.test(path))
|
|
45
|
+
try {
|
|
46
|
+
const report = readReport(
|
|
47
|
+
entry.root,
|
|
48
|
+
path.split("/").at(-1)!.slice(0, -3),
|
|
49
|
+
graph === baseline ? plan.baseCommit : undefined,
|
|
50
|
+
);
|
|
51
|
+
return report.blocks.filter((id) =>
|
|
52
|
+
graph.elements.some((n) => n.id === id),
|
|
53
|
+
);
|
|
54
|
+
} catch {}
|
|
55
|
+
|
|
56
|
+
const candidates = graph.elements.filter(
|
|
57
|
+
(node) =>
|
|
58
|
+
(node.sources || (node.source ? [node.source] : [])).some(
|
|
59
|
+
(source) =>
|
|
60
|
+
source.file === path ||
|
|
61
|
+
(path.endsWith("/") && source.file.startsWith(path)),
|
|
62
|
+
) ||
|
|
63
|
+
(node.attachments?.tests || []).includes(path) ||
|
|
64
|
+
(node.attachments?.docs || []).includes(path) ||
|
|
65
|
+
blockNoteFile(node.id) === path ||
|
|
66
|
+
path.startsWith(blockNoteFile(node.id).replace(/\.md$/, "/")),
|
|
67
|
+
);
|
|
68
|
+
for (const test of graph.tests.filter((test) => test.source.file === path))
|
|
69
|
+
for (const target of test.targets) {
|
|
70
|
+
const node = graph.elements.find((node) => node.id === target);
|
|
71
|
+
if (node && !candidates.some((item) => item.id === node.id))
|
|
72
|
+
candidates.push(node);
|
|
73
|
+
}
|
|
74
|
+
// Parent sources often describe the same module; the most specific mapped owners decide.
|
|
75
|
+
return candidates
|
|
76
|
+
.filter(
|
|
77
|
+
(node) =>
|
|
78
|
+
!candidates.some(
|
|
79
|
+
(other) =>
|
|
80
|
+
other.id !== node.id && isAncestor(graph, node.id, other.id),
|
|
81
|
+
),
|
|
82
|
+
)
|
|
83
|
+
.map((node) => node.id);
|
|
84
|
+
}
|
|
85
|
+
const files = paths.map((path) => {
|
|
86
|
+
if (
|
|
87
|
+
[
|
|
88
|
+
".agents/skills/fractory/SKILL.md",
|
|
89
|
+
".agents/skills/fractory/references/fractory-guide.md",
|
|
90
|
+
].includes(path)
|
|
91
|
+
)
|
|
92
|
+
return { path, status: "setup" as const, blocks: [] };
|
|
93
|
+
if (path === entry.planFile)
|
|
94
|
+
return {
|
|
95
|
+
path,
|
|
96
|
+
status: "plan" as const,
|
|
97
|
+
blocks: [graphRoot(currentGraph)],
|
|
98
|
+
};
|
|
99
|
+
const baseOwners = owners(baseline, path);
|
|
100
|
+
const selected = baseOwners.length ? baseAllowed : allowed;
|
|
101
|
+
const blocks = baseOwners.length ? baseOwners : owners(currentGraph, path);
|
|
102
|
+
const inside = blocks.filter((block) => selected.has(block));
|
|
103
|
+
const status = !blocks.length
|
|
104
|
+
? "unassigned"
|
|
105
|
+
: !inside.length
|
|
106
|
+
? "outside"
|
|
107
|
+
: inside.length !== blocks.length
|
|
108
|
+
? "shared"
|
|
109
|
+
: "inside";
|
|
110
|
+
return { path, status, blocks };
|
|
111
|
+
});
|
|
112
|
+
const uncertain = files.filter((file) =>
|
|
113
|
+
["unassigned", "shared"].includes(file.status),
|
|
114
|
+
);
|
|
115
|
+
const outside = files.filter((file) => file.status === "outside");
|
|
116
|
+
return {
|
|
117
|
+
work: id,
|
|
118
|
+
base: plan.baseCommit,
|
|
119
|
+
head,
|
|
120
|
+
pass: !outside.length && !uncertain.length,
|
|
121
|
+
files,
|
|
122
|
+
outside: outside.length,
|
|
123
|
+
uncertain: uncertain.length,
|
|
124
|
+
basis: "pinned-file-ownership",
|
|
125
|
+
notice:
|
|
126
|
+
"File ownership is conservative: shared and unassigned files require review. This check is not a filesystem sandbox or a protected-branch rule.",
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function graphRoot(graph: DefinitionGraph) {
|
|
130
|
+
return graph.id;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function isAncestor(graph: DefinitionGraph, parent: string, child: string) {
|
|
134
|
+
const byId = new Map(graph.elements.map((n) => [n.id, n]));
|
|
135
|
+
const seen = new Set<string>();
|
|
136
|
+
let id: string | undefined = child;
|
|
137
|
+
while (id && !seen.has(id)) {
|
|
138
|
+
if (id === parent) return true;
|
|
139
|
+
seen.add(id);
|
|
140
|
+
id = byId.get(id)?.parent;
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|
package/src/work-cli.ts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import {
|
|
5
|
+
createWorkContext,
|
|
6
|
+
adoptWorkContext,
|
|
7
|
+
listWorkContexts,
|
|
8
|
+
mainReference,
|
|
9
|
+
readFactoryMap,
|
|
10
|
+
resolveWorkContext,
|
|
11
|
+
updateWorkPlan,
|
|
12
|
+
workBaseline,
|
|
13
|
+
workDeepLink,
|
|
14
|
+
workHandoff,
|
|
15
|
+
updateWorkIntent,
|
|
16
|
+
} from "./work-context";
|
|
17
|
+
import { workIntentStates } from "./work-intents";
|
|
18
|
+
import { readGit } from "./git-refs";
|
|
19
|
+
import { checkWorkScope } from "./work-check";
|
|
20
|
+
|
|
21
|
+
export async function runWork(args: string[]) {
|
|
22
|
+
if (args.includes("--help"))
|
|
23
|
+
return `fractory work list\nfractory work create --title TITLE --block ID [--block ID] [--from REF]\nfractory work adopt ID --block ID [--block ID] [--title TITLE]\nfractory work show ID\nfractory work handoff ID\nfractory work open ID\nfractory work plan ID --file PLAN.json --revision REVISION\nfractory work check ID\nfractory work review ID\nfractory work intent ID --proposal PROPOSAL_ID --status planned|done|dropped --revision REV [--implementation BLOCK_OR_CONNECTION_ID]\nfractory work pr ID --url URL --title TITLE\nUse --root PATH to select a repository. Creating a work adds a worktree; it never switches the current checkout. Plan JSON contains a proposals array and optional scope. Shared or unknown file ownership makes check fail.`;
|
|
24
|
+
const option = (name: string) => {
|
|
25
|
+
const i = args.indexOf(name);
|
|
26
|
+
if (i < 0) return undefined;
|
|
27
|
+
if (!args[i + 1] || args[i + 1].startsWith("--"))
|
|
28
|
+
throw Error(`${name} needs a value.`);
|
|
29
|
+
return args[i + 1];
|
|
30
|
+
};
|
|
31
|
+
const root = readGit(resolve(option("--root") || process.cwd()), [
|
|
32
|
+
"rev-parse",
|
|
33
|
+
"--show-toplevel",
|
|
34
|
+
]).trim();
|
|
35
|
+
const action = args[1] || "list";
|
|
36
|
+
if (action === "list")
|
|
37
|
+
return JSON.stringify(
|
|
38
|
+
{ main: mainReference(root), targets: listWorkContexts(root) },
|
|
39
|
+
null,
|
|
40
|
+
2,
|
|
41
|
+
);
|
|
42
|
+
if (action === "create") {
|
|
43
|
+
const graph = await readFactoryMap(root);
|
|
44
|
+
if (!graph)
|
|
45
|
+
throw Error("Map this repository before starting block-scoped work.");
|
|
46
|
+
const scope = args.flatMap((value, index) =>
|
|
47
|
+
value === "--block" ? [args[index + 1]] : [],
|
|
48
|
+
);
|
|
49
|
+
const work = await createWorkContext(root, graph, {
|
|
50
|
+
title: option("--title") || "",
|
|
51
|
+
scope,
|
|
52
|
+
from: option("--from"),
|
|
53
|
+
});
|
|
54
|
+
return JSON.stringify(
|
|
55
|
+
{
|
|
56
|
+
...work,
|
|
57
|
+
url: workDeepLink(root, work.id),
|
|
58
|
+
handoff: workHandoff(work, graph),
|
|
59
|
+
},
|
|
60
|
+
null,
|
|
61
|
+
2,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
const id = args[2];
|
|
65
|
+
if (!id || id.startsWith("--"))
|
|
66
|
+
throw Error("Choose a work context from fractory work list.");
|
|
67
|
+
let work = resolveWorkContext(root, id);
|
|
68
|
+
const graph =
|
|
69
|
+
(await readFactoryMap(work.root)) ||
|
|
70
|
+
(work.plan ? workBaseline(root, id) : await readFactoryMap(root));
|
|
71
|
+
if (!graph) throw Error("No factory map is available for this work context.");
|
|
72
|
+
if (action === "adopt") {
|
|
73
|
+
const scope = args.flatMap((value, index) =>
|
|
74
|
+
value === "--block" ? [args[index + 1]] : [],
|
|
75
|
+
);
|
|
76
|
+
const adopted = await adoptWorkContext(root, id, graph, {
|
|
77
|
+
scope,
|
|
78
|
+
title: option("--title"),
|
|
79
|
+
});
|
|
80
|
+
return JSON.stringify(
|
|
81
|
+
{
|
|
82
|
+
...adopted,
|
|
83
|
+
url: workDeepLink(root, adopted.id),
|
|
84
|
+
handoff: workHandoff(adopted, graph),
|
|
85
|
+
},
|
|
86
|
+
null,
|
|
87
|
+
2,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
const intents = () =>
|
|
91
|
+
workIntentStates(
|
|
92
|
+
work.root,
|
|
93
|
+
graph,
|
|
94
|
+
work.plan,
|
|
95
|
+
work.plan ? workBaseline(root, id) : undefined,
|
|
96
|
+
);
|
|
97
|
+
if (action === "show")
|
|
98
|
+
return JSON.stringify(
|
|
99
|
+
{ ...work, intents: intents(), url: workDeepLink(root, id) },
|
|
100
|
+
null,
|
|
101
|
+
2,
|
|
102
|
+
);
|
|
103
|
+
if (action === "intent") {
|
|
104
|
+
if (
|
|
105
|
+
!option("--proposal") ||
|
|
106
|
+
!option("--revision") ||
|
|
107
|
+
!["planned", "done", "dropped"].includes(option("--status") || "")
|
|
108
|
+
)
|
|
109
|
+
throw Error(
|
|
110
|
+
"Use --proposal ID --status planned|done|dropped --revision REVISION, with --implementation ID to link actual code.",
|
|
111
|
+
);
|
|
112
|
+
work = updateWorkIntent(root, id, graph, {
|
|
113
|
+
revision: option("--revision")!,
|
|
114
|
+
proposal: option("--proposal")!,
|
|
115
|
+
status: option("--status") as "planned" | "done" | "dropped",
|
|
116
|
+
implementation: option("--implementation"),
|
|
117
|
+
});
|
|
118
|
+
return JSON.stringify({ ...work, intents: intents() }, null, 2);
|
|
119
|
+
}
|
|
120
|
+
if (action === "handoff") return workHandoff(work, graph);
|
|
121
|
+
if (action === "open") {
|
|
122
|
+
const url = workDeepLink(root, id);
|
|
123
|
+
execFileSync("open", [url], { stdio: "ignore", timeout: 5000 });
|
|
124
|
+
return url;
|
|
125
|
+
}
|
|
126
|
+
if (action === "review") {
|
|
127
|
+
const report = await checkWorkScope(root, id, graph);
|
|
128
|
+
const states = intents();
|
|
129
|
+
const labels = new Map(graph.elements.map((n) => [n.id, n.label]));
|
|
130
|
+
return [
|
|
131
|
+
`## ${work.title}`,
|
|
132
|
+
"",
|
|
133
|
+
`[Open the factory work view](${workDeepLink(root, id)})`,
|
|
134
|
+
"",
|
|
135
|
+
`Base: ${work.baseCommit} · Head: ${work.head}`,
|
|
136
|
+
"",
|
|
137
|
+
`Scope: ${(work.plan?.scope || []).map((id) => labels.get(id) || id).join(", ")}`,
|
|
138
|
+
"",
|
|
139
|
+
`Scope check: ${report.pass ? "passed" : `${report.outside} outside; ${report.uncertain} shared or unmapped`}`,
|
|
140
|
+
"",
|
|
141
|
+
"| Change | Files |",
|
|
142
|
+
"| --- | ---: |",
|
|
143
|
+
...["inside", "outside", "shared", "unassigned"].map(
|
|
144
|
+
(status) =>
|
|
145
|
+
`| ${status} | ${report.files.filter((f) => f.status === status).length} |`,
|
|
146
|
+
),
|
|
147
|
+
"",
|
|
148
|
+
...(work.plan?.proposals.length
|
|
149
|
+
? [
|
|
150
|
+
"### Intended changes",
|
|
151
|
+
...work.plan.proposals.map(
|
|
152
|
+
(p) =>
|
|
153
|
+
`- [${states[p.id]?.status === "changed" ? "needs recheck" : states[p.id]?.status || "planned"}] ${p.kind}: ${p.label}${p.kind === "connection" ? ` (${labels.get(p.source!) || p.source} → ${labels.get(p.target!) || p.target})` : ""}${p.implementation ? ` → ${labels.get(p.implementation) || p.implementation}` : ""} — ${p.note.replace(/\n/g, " ")}`,
|
|
154
|
+
),
|
|
155
|
+
]
|
|
156
|
+
: []),
|
|
157
|
+
"",
|
|
158
|
+
"The plan shows intent. File ownership is checked against the pinned map; this is not test evidence or merge protection.",
|
|
159
|
+
].join("\n");
|
|
160
|
+
}
|
|
161
|
+
if (action === "check") {
|
|
162
|
+
const report = await checkWorkScope(root, id, graph);
|
|
163
|
+
if (!report.pass) process.exitCode = 1;
|
|
164
|
+
return JSON.stringify(report, null, 2);
|
|
165
|
+
}
|
|
166
|
+
if (action === "plan" || action === "pr") {
|
|
167
|
+
if (!work.plan || !work.revision)
|
|
168
|
+
throw Error("Start a block-scoped work context first.");
|
|
169
|
+
const file = option("--file");
|
|
170
|
+
if (action === "plan" && (!file || !option("--revision")))
|
|
171
|
+
throw Error("Choose --file and --revision from work show.");
|
|
172
|
+
if (file && statSync(resolve(file)).size > 150000)
|
|
173
|
+
throw Error("Keep the plan below 150 KB.");
|
|
174
|
+
const value =
|
|
175
|
+
action === "plan" && file
|
|
176
|
+
? JSON.parse(readFileSync(resolve(file), "utf8"))
|
|
177
|
+
: {};
|
|
178
|
+
work = updateWorkPlan(root, id, graph, {
|
|
179
|
+
revision: option("--revision") || work.revision,
|
|
180
|
+
proposals: value.proposals || work.plan.proposals,
|
|
181
|
+
scope: value.scope,
|
|
182
|
+
excluded: value.excluded,
|
|
183
|
+
...(action === "pr"
|
|
184
|
+
? {
|
|
185
|
+
pullRequest: {
|
|
186
|
+
url: option("--url") || "",
|
|
187
|
+
title: option("--title") || "Pull request",
|
|
188
|
+
},
|
|
189
|
+
}
|
|
190
|
+
: {}),
|
|
191
|
+
});
|
|
192
|
+
return JSON.stringify(work, null, 2);
|
|
193
|
+
}
|
|
194
|
+
throw Error(`Unknown work command: ${action}`);
|
|
195
|
+
}
|