@flyingrobots/graft 0.3.5 → 0.5.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/ARCHITECTURE.md +386 -0
- package/CHANGELOG.md +69 -0
- package/CODE_OF_CONDUCT.md +65 -0
- package/README.md +153 -17
- package/bin/graft.js +4 -11
- package/docs/ADVANCED_GUIDE.md +49 -0
- package/docs/CLI.md +43 -0
- package/docs/GUIDE.md +321 -32
- package/docs/MCP.md +44 -0
- package/package.json +17 -4
- package/src/adapters/node-fs.ts +4 -0
- package/src/adapters/node-git.ts +47 -0
- package/src/adapters/node-process-runner.ts +27 -0
- package/src/cli/index-cmd.ts +86 -0
- package/src/cli/init.ts +808 -57
- package/src/cli/main.ts +437 -0
- package/src/contracts/capabilities.ts +341 -0
- package/src/contracts/causal-ontology.ts +622 -0
- package/src/contracts/causal-surface-next-action.ts +18 -0
- package/src/contracts/output-schemas.ts +1169 -0
- package/src/git/diff.ts +25 -21
- package/src/git/target-git-hook-bootstrap.ts +56 -0
- package/src/hooks/posttooluse-read.ts +21 -74
- package/src/hooks/pretooluse-read.ts +20 -56
- package/src/hooks/read-governor.ts +95 -0
- package/src/hooks/read-messages.ts +53 -0
- package/src/mcp/burden.ts +123 -0
- package/src/mcp/cache.ts +51 -0
- package/src/mcp/cached-file.ts +10 -8
- package/src/mcp/context.ts +67 -2
- package/src/mcp/daemon-control-plane.ts +554 -0
- package/src/mcp/daemon-job-scheduler.ts +279 -0
- package/src/mcp/daemon-repos.ts +216 -0
- package/src/mcp/daemon-server.ts +396 -0
- package/src/mcp/daemon-worker-pool.ts +310 -0
- package/src/mcp/daemon-worker-process.ts +52 -0
- package/src/mcp/metrics.ts +108 -1
- package/src/mcp/monitor-tick-job.ts +99 -0
- package/src/mcp/persisted-local-history.ts +1246 -0
- package/src/mcp/persistent-monitor-runtime.ts +549 -0
- package/src/mcp/policy.ts +84 -0
- package/src/mcp/receipt.ts +82 -12
- package/src/mcp/repo-concurrency.ts +318 -0
- package/src/mcp/repo-state.ts +777 -0
- package/src/mcp/repo-tool-job.ts +302 -0
- package/src/mcp/run-capture-config.ts +33 -0
- package/src/mcp/runtime-causal-context.ts +72 -0
- package/src/mcp/runtime-observability.ts +219 -0
- package/src/mcp/runtime-staged-target.ts +161 -0
- package/src/mcp/runtime-workspace-overlay.ts +255 -0
- package/src/mcp/semantic-transition-guidance.ts +60 -0
- package/src/mcp/semantic-transition-summary.ts +130 -0
- package/src/mcp/server.ts +704 -45
- package/src/mcp/stdio-server.ts +12 -0
- package/src/mcp/stdio.ts +2 -5
- package/src/mcp/tools/activity-view.ts +325 -0
- package/src/mcp/tools/causal-attach.ts +67 -0
- package/src/mcp/tools/causal-status.ts +58 -0
- package/src/mcp/tools/changed-since.ts +13 -11
- package/src/mcp/tools/code-find.ts +164 -0
- package/src/mcp/tools/code-refs.ts +466 -0
- package/src/mcp/tools/code-show.ts +252 -0
- package/src/mcp/tools/daemon-monitors.ts +14 -0
- package/src/mcp/tools/daemon-repos.ts +22 -0
- package/src/mcp/tools/daemon-sessions.ts +14 -0
- package/src/mcp/tools/daemon-status.ts +12 -0
- package/src/mcp/tools/doctor.ts +45 -2
- package/src/mcp/tools/explain.ts +4 -0
- package/src/mcp/tools/file-outline.ts +7 -3
- package/src/mcp/tools/git-files.ts +73 -0
- package/src/mcp/tools/graft-diff.ts +12 -4
- package/src/mcp/tools/map.ts +136 -0
- package/src/mcp/tools/monitor-pause.ts +18 -0
- package/src/mcp/tools/monitor-resume.ts +18 -0
- package/src/mcp/tools/monitor-start.ts +20 -0
- package/src/mcp/tools/monitor-stop.ts +18 -0
- package/src/mcp/tools/precision-match.ts +51 -0
- package/src/mcp/tools/precision-query.ts +127 -0
- package/src/mcp/tools/precision.ts +312 -0
- package/src/mcp/tools/run-capture.ts +126 -44
- package/src/mcp/tools/safe-read.ts +14 -12
- package/src/mcp/tools/since.ts +49 -0
- package/src/mcp/tools/state.ts +11 -3
- package/src/mcp/tools/stats.ts +5 -1
- package/src/mcp/tools/workspace-authorizations.ts +14 -0
- package/src/mcp/tools/workspace-authorize.ts +20 -0
- package/src/mcp/tools/workspace-bind.ts +25 -0
- package/src/mcp/tools/workspace-rebind.ts +25 -0
- package/src/mcp/tools/workspace-revoke.ts +18 -0
- package/src/mcp/tools/workspace-status.ts +12 -0
- package/src/mcp/warp-pool.ts +36 -0
- package/src/mcp/workspace-router.ts +984 -0
- package/src/operations/file-outline.ts +12 -2
- package/src/operations/graft-diff.ts +56 -10
- package/src/operations/safe-read.ts +27 -4
- package/src/operations/state.ts +6 -9
- package/src/parser/lang.ts +19 -3
- package/src/parser/outline.ts +191 -2
- package/src/parser/types.ts +9 -1
- package/src/policy/types.ts +4 -3
- package/src/ports/filesystem.ts +1 -0
- package/src/ports/git.ts +16 -0
- package/src/ports/process-runner.ts +22 -0
- package/src/release/security-gate.ts +102 -0
- package/src/session/tracker.ts +31 -0
- package/src/version.ts +3 -0
- package/src/warp/indexer.ts +513 -0
- package/src/warp/observers.ts +105 -0
- package/src/warp/open.ts +31 -0
- package/src/warp/plumbing.d.ts +15 -0
- package/src/warp/writer-id.ts +30 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WARP Observer Factory — canonical observer lenses for graft queries.
|
|
3
|
+
*
|
|
4
|
+
* Observer Law: this module READS through observers. It never
|
|
5
|
+
* walks the graph directly, maintains shadow state, or implements
|
|
6
|
+
* traversal algorithms.
|
|
7
|
+
*
|
|
8
|
+
* Each function returns an observer with a focused lens. The lens
|
|
9
|
+
* determines the aperture — what the observer can see.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type WarpApp from "@git-stunts/git-warp";
|
|
13
|
+
import type { Observer } from "@git-stunts/git-warp";
|
|
14
|
+
|
|
15
|
+
/** Lens config for creating focused observers. */
|
|
16
|
+
export interface Lens {
|
|
17
|
+
match: string;
|
|
18
|
+
expose?: string[];
|
|
19
|
+
redact?: string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Observe all symbols in a specific file.
|
|
24
|
+
* Aperture: sym:<path>:*
|
|
25
|
+
*/
|
|
26
|
+
export function fileSymbolsLens(filePath: string): Lens {
|
|
27
|
+
return {
|
|
28
|
+
match: `sym:${filePath}:*`,
|
|
29
|
+
expose: ["name", "kind", "signature", "exported", "startLine", "endLine"],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Observe all symbols in the project.
|
|
35
|
+
* Aperture: sym:*
|
|
36
|
+
*/
|
|
37
|
+
export function allSymbolsLens(): Lens {
|
|
38
|
+
return {
|
|
39
|
+
match: "sym:*",
|
|
40
|
+
expose: ["name", "kind", "signature", "exported", "startLine", "endLine"],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Observe all files in the project.
|
|
46
|
+
* Aperture: file:*
|
|
47
|
+
*/
|
|
48
|
+
export function allFilesLens(): Lens {
|
|
49
|
+
return {
|
|
50
|
+
match: "file:*",
|
|
51
|
+
expose: ["path", "lang"],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Observe a single symbol by name across all files.
|
|
57
|
+
* Aperture: sym:*:<name>
|
|
58
|
+
*/
|
|
59
|
+
export function symbolByNameLens(symbolName: string): Lens {
|
|
60
|
+
return {
|
|
61
|
+
match: `sym:*:${symbolName}`,
|
|
62
|
+
expose: ["name", "kind", "signature", "exported", "startLine", "endLine"],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Observe a directory subtree.
|
|
68
|
+
* Aperture: dir:<path>*
|
|
69
|
+
*/
|
|
70
|
+
export function directoryLens(dirPath: string): Lens {
|
|
71
|
+
return {
|
|
72
|
+
match: `dir:${dirPath}*`,
|
|
73
|
+
expose: ["path"],
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Observe all files under a directory.
|
|
79
|
+
* Aperture: file:<path>/*
|
|
80
|
+
*/
|
|
81
|
+
export function directoryFilesLens(dirPath: string): Lens {
|
|
82
|
+
return {
|
|
83
|
+
match: `file:${dirPath}/*`,
|
|
84
|
+
expose: ["path", "lang"],
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Observe commit metadata.
|
|
90
|
+
* Aperture: commit:*
|
|
91
|
+
*/
|
|
92
|
+
export function commitsLens(): Lens {
|
|
93
|
+
return {
|
|
94
|
+
match: "commit:*",
|
|
95
|
+
expose: ["sha", "message", "timestamp", "author", "email"],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Create an observer on the current frontier with a given lens.
|
|
101
|
+
* Observers are static snapshots — create a new one after writes.
|
|
102
|
+
*/
|
|
103
|
+
export function observe(warp: WarpApp, lens: Lens): Promise<Observer> {
|
|
104
|
+
return warp.observer(lens);
|
|
105
|
+
}
|
package/src/warp/open.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WARP graph initialization — opens the graft-ast graph backed by
|
|
3
|
+
* the repo's own .git directory.
|
|
4
|
+
*
|
|
5
|
+
* Single entry point. Returns a WarpApp instance ready for patch
|
|
6
|
+
* writes and observer reads.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import WarpApp, { GitGraphAdapter } from "@git-stunts/git-warp";
|
|
10
|
+
import GitPlumbing from "@git-stunts/plumbing";
|
|
11
|
+
import { DEFAULT_WARP_WRITER_ID } from "./writer-id.js";
|
|
12
|
+
|
|
13
|
+
export const GRAPH_NAME = "graft-ast";
|
|
14
|
+
|
|
15
|
+
export interface OpenWarpOptions {
|
|
16
|
+
readonly cwd: string;
|
|
17
|
+
readonly writerId?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function openWarp(options: OpenWarpOptions): Promise<WarpApp> {
|
|
21
|
+
// createDefault() wires the ShellRunnerFactory (required port)
|
|
22
|
+
const plumbing = GitPlumbing.createDefault({ cwd: options.cwd });
|
|
23
|
+
const persistence = new GitGraphAdapter({ plumbing });
|
|
24
|
+
|
|
25
|
+
return WarpApp.open({
|
|
26
|
+
persistence,
|
|
27
|
+
graphName: GRAPH_NAME,
|
|
28
|
+
writerId: options.writerId ?? DEFAULT_WARP_WRITER_ID,
|
|
29
|
+
onDeleteWithData: "cascade",
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare module "@git-stunts/plumbing" {
|
|
2
|
+
import type { GitPlumbing as GitPlumbingInterface } from "@git-stunts/git-warp";
|
|
3
|
+
|
|
4
|
+
export default class GitPlumbing implements GitPlumbingInterface {
|
|
5
|
+
readonly emptyTree: string;
|
|
6
|
+
constructor(options: { runner: unknown; cwd?: string });
|
|
7
|
+
static createDefault(options?: { cwd?: string; env?: string }): GitPlumbing;
|
|
8
|
+
execute(options: { args: string[]; input?: string | Uint8Array }): Promise<string>;
|
|
9
|
+
executeStream(options: { args: string[] }): Promise<{
|
|
10
|
+
finished: Promise<{ code: number; stderr: string; error?: Error }>;
|
|
11
|
+
collect(opts?: { maxBytes?: number; asString?: boolean; encoding?: string }): Promise<Uint8Array | string>;
|
|
12
|
+
[Symbol.asyncIterator](): AsyncIterator<Uint8Array>;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as crypto from "node:crypto";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_WARP_WRITER_ID = "graft";
|
|
4
|
+
|
|
5
|
+
function sanitizeSegment(input: string): string {
|
|
6
|
+
const normalized = input
|
|
7
|
+
.trim()
|
|
8
|
+
.toLowerCase()
|
|
9
|
+
.replace(/[^a-z0-9_-]+/g, "_")
|
|
10
|
+
.replace(/^_+|_+$/g, "");
|
|
11
|
+
return normalized.length > 0 ? normalized : "lane";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function buildWarpWriterId(kind: string, scope?: string): string {
|
|
15
|
+
const lane = sanitizeSegment(kind);
|
|
16
|
+
if (scope === undefined || scope.trim().length === 0) {
|
|
17
|
+
return `graft_${lane}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const digest = crypto.createHash("sha256").update(scope).digest("hex").slice(0, 12);
|
|
21
|
+
return `graft_${lane}_${digest}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function buildSessionWarpWriterId(sessionId: string): string {
|
|
25
|
+
return buildWarpWriterId("session", sessionId);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function buildMonitorWarpWriterId(repoId: string): string {
|
|
29
|
+
return buildWarpWriterId("monitor", repoId);
|
|
30
|
+
}
|