@swarmvaultai/engine 0.6.7 → 0.6.8

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.
@@ -0,0 +1,146 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/hooks/marker-state.ts
4
+ import crypto from "crypto";
5
+ import fs from "fs/promises";
6
+ import os from "os";
7
+ import path from "path";
8
+ function markerState(cwd, agentKey) {
9
+ const hash = crypto.createHash("sha256").update(cwd).digest("hex");
10
+ const dir = path.join(os.tmpdir(), "swarmvault-agent-hooks", agentKey, hash);
11
+ return {
12
+ dir,
13
+ markerPath: path.join(dir, "report-read")
14
+ };
15
+ }
16
+ function isReportPath(value, cwd) {
17
+ if (typeof value !== "string" || value.length === 0) {
18
+ return false;
19
+ }
20
+ const reportSuffix = path.join("wiki", "graph", "report.md");
21
+ const normalized = value.replaceAll("\\", "/");
22
+ const reportNormalized = reportSuffix.replaceAll("\\", "/");
23
+ if (normalized.endsWith(reportNormalized)) {
24
+ return true;
25
+ }
26
+ return path.resolve(cwd, value) === path.resolve(cwd, reportSuffix);
27
+ }
28
+ function collectCandidatePaths(node, acc = []) {
29
+ if (typeof node === "string") {
30
+ acc.push(node);
31
+ return acc;
32
+ }
33
+ if (!node || typeof node !== "object") {
34
+ return acc;
35
+ }
36
+ if (Array.isArray(node)) {
37
+ for (const item of node) {
38
+ collectCandidatePaths(item, acc);
39
+ }
40
+ return acc;
41
+ }
42
+ for (const [key, value] of Object.entries(node)) {
43
+ if (["path", "filePath", "file_path", "paths", "target", "targets"].includes(key)) {
44
+ collectCandidatePaths(value, acc);
45
+ continue;
46
+ }
47
+ collectCandidatePaths(value, acc);
48
+ }
49
+ return acc;
50
+ }
51
+ function resolveInputCwd(input) {
52
+ const shaped = input ?? {};
53
+ const candidate = typeof shaped.cwd === "string" && shaped.cwd || typeof shaped.directory === "string" && shaped.directory || typeof shaped.workspace?.cwd === "string" && shaped.workspace.cwd || typeof shaped.toolInput?.cwd === "string" && shaped.toolInput.cwd || process.cwd();
54
+ return path.resolve(candidate);
55
+ }
56
+ function resolveToolName(input) {
57
+ const shaped = input ?? {};
58
+ return String(shaped.toolName ?? shaped.tool_name ?? shaped.tool?.name ?? shaped.name ?? "");
59
+ }
60
+ async function hasReport(cwd) {
61
+ try {
62
+ await fs.access(path.join(cwd, "wiki", "graph", "report.md"));
63
+ return true;
64
+ } catch {
65
+ return false;
66
+ }
67
+ }
68
+ async function markReportRead(cwd, agentKey) {
69
+ const state = markerState(cwd, agentKey);
70
+ await fs.mkdir(state.dir, { recursive: true });
71
+ await fs.writeFile(state.markerPath, "seen\n", "utf8");
72
+ }
73
+ async function hasSeenReport(cwd, agentKey) {
74
+ const state = markerState(cwd, agentKey);
75
+ try {
76
+ await fs.access(state.markerPath);
77
+ return true;
78
+ } catch {
79
+ return false;
80
+ }
81
+ }
82
+ async function resetSession(cwd, agentKey) {
83
+ const state = markerState(cwd, agentKey);
84
+ await fs.rm(state.dir, { recursive: true, force: true });
85
+ }
86
+ function isBroadSearchTool(toolName) {
87
+ return /grep|glob|search|find/i.test(toolName);
88
+ }
89
+ async function readHookInput() {
90
+ let body = "";
91
+ for await (const chunk of process.stdin) {
92
+ body += chunk;
93
+ }
94
+ if (!body.trim()) {
95
+ return {};
96
+ }
97
+ try {
98
+ return JSON.parse(body);
99
+ } catch {
100
+ return {};
101
+ }
102
+ }
103
+ var REPORT_NOTE = "SwarmVault graph report exists at wiki/graph/report.md. Read it before broad grep/glob searching.";
104
+
105
+ // src/hooks/claude.ts
106
+ var AGENT_KEY = "claude";
107
+ function emit(value) {
108
+ process.stdout.write(`${JSON.stringify(value)}
109
+ `);
110
+ }
111
+ async function main() {
112
+ const mode = process.argv[2] ?? "";
113
+ const input = await readHookInput();
114
+ const cwd = resolveInputCwd(input);
115
+ if (!await hasReport(cwd)) {
116
+ emit({});
117
+ process.exit(0);
118
+ }
119
+ if (mode === "session-start") {
120
+ await resetSession(cwd, AGENT_KEY);
121
+ emit({
122
+ hookSpecificOutput: {
123
+ hookEventName: "SessionStart",
124
+ additionalContext: REPORT_NOTE
125
+ }
126
+ });
127
+ process.exit(0);
128
+ }
129
+ const toolName = resolveToolName(input);
130
+ if (collectCandidatePaths(input).some((value) => isReportPath(value, cwd))) {
131
+ await markReportRead(cwd, AGENT_KEY);
132
+ emit({});
133
+ process.exit(0);
134
+ }
135
+ if (isBroadSearchTool(toolName) && !await hasSeenReport(cwd, AGENT_KEY)) {
136
+ emit({
137
+ hookSpecificOutput: {
138
+ hookEventName: "PreToolUse",
139
+ additionalContext: REPORT_NOTE
140
+ }
141
+ });
142
+ process.exit(0);
143
+ }
144
+ emit({});
145
+ }
146
+ await main();
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/hooks/marker-state.ts
4
+ import crypto from "crypto";
5
+ import fs from "fs/promises";
6
+ import os from "os";
7
+ import path from "path";
8
+ function markerState(cwd, agentKey) {
9
+ const hash = crypto.createHash("sha256").update(cwd).digest("hex");
10
+ const dir = path.join(os.tmpdir(), "swarmvault-agent-hooks", agentKey, hash);
11
+ return {
12
+ dir,
13
+ markerPath: path.join(dir, "report-read")
14
+ };
15
+ }
16
+ function isReportPath(value, cwd) {
17
+ if (typeof value !== "string" || value.length === 0) {
18
+ return false;
19
+ }
20
+ const reportSuffix = path.join("wiki", "graph", "report.md");
21
+ const normalized = value.replaceAll("\\", "/");
22
+ const reportNormalized = reportSuffix.replaceAll("\\", "/");
23
+ if (normalized.endsWith(reportNormalized)) {
24
+ return true;
25
+ }
26
+ return path.resolve(cwd, value) === path.resolve(cwd, reportSuffix);
27
+ }
28
+ function collectCandidatePaths(node, acc = []) {
29
+ if (typeof node === "string") {
30
+ acc.push(node);
31
+ return acc;
32
+ }
33
+ if (!node || typeof node !== "object") {
34
+ return acc;
35
+ }
36
+ if (Array.isArray(node)) {
37
+ for (const item of node) {
38
+ collectCandidatePaths(item, acc);
39
+ }
40
+ return acc;
41
+ }
42
+ for (const [key, value] of Object.entries(node)) {
43
+ if (["path", "filePath", "file_path", "paths", "target", "targets"].includes(key)) {
44
+ collectCandidatePaths(value, acc);
45
+ continue;
46
+ }
47
+ collectCandidatePaths(value, acc);
48
+ }
49
+ return acc;
50
+ }
51
+ function resolveInputCwd(input) {
52
+ const shaped = input ?? {};
53
+ const candidate = typeof shaped.cwd === "string" && shaped.cwd || typeof shaped.directory === "string" && shaped.directory || typeof shaped.workspace?.cwd === "string" && shaped.workspace.cwd || typeof shaped.toolInput?.cwd === "string" && shaped.toolInput.cwd || process.cwd();
54
+ return path.resolve(candidate);
55
+ }
56
+ function resolveToolName(input) {
57
+ const shaped = input ?? {};
58
+ return String(shaped.toolName ?? shaped.tool_name ?? shaped.tool?.name ?? shaped.name ?? "");
59
+ }
60
+ async function hasReport(cwd) {
61
+ try {
62
+ await fs.access(path.join(cwd, "wiki", "graph", "report.md"));
63
+ return true;
64
+ } catch {
65
+ return false;
66
+ }
67
+ }
68
+ async function markReportRead(cwd, agentKey) {
69
+ const state = markerState(cwd, agentKey);
70
+ await fs.mkdir(state.dir, { recursive: true });
71
+ await fs.writeFile(state.markerPath, "seen\n", "utf8");
72
+ }
73
+ async function hasSeenReport(cwd, agentKey) {
74
+ const state = markerState(cwd, agentKey);
75
+ try {
76
+ await fs.access(state.markerPath);
77
+ return true;
78
+ } catch {
79
+ return false;
80
+ }
81
+ }
82
+ async function resetSession(cwd, agentKey) {
83
+ const state = markerState(cwd, agentKey);
84
+ await fs.rm(state.dir, { recursive: true, force: true });
85
+ }
86
+ function isBroadSearchTool(toolName) {
87
+ return /grep|glob|search|find/i.test(toolName);
88
+ }
89
+ async function readHookInput() {
90
+ let body = "";
91
+ for await (const chunk of process.stdin) {
92
+ body += chunk;
93
+ }
94
+ if (!body.trim()) {
95
+ return {};
96
+ }
97
+ try {
98
+ return JSON.parse(body);
99
+ } catch {
100
+ return {};
101
+ }
102
+ }
103
+ var REPORT_NOTE = "SwarmVault graph report exists at wiki/graph/report.md. Read it before broad grep/glob searching.";
104
+
105
+ // src/hooks/copilot.ts
106
+ var AGENT_KEY = "copilot";
107
+ function emit(value) {
108
+ if (value !== void 0) {
109
+ process.stdout.write(`${JSON.stringify(value)}
110
+ `);
111
+ }
112
+ }
113
+ async function main() {
114
+ const mode = process.argv[2] ?? "";
115
+ const input = await readHookInput();
116
+ const cwd = resolveInputCwd(input);
117
+ if (!await hasReport(cwd)) {
118
+ emit({});
119
+ process.exit(0);
120
+ }
121
+ if (mode === "session-start") {
122
+ await resetSession(cwd, AGENT_KEY);
123
+ emit({});
124
+ process.exit(0);
125
+ }
126
+ const toolName = resolveToolName(input);
127
+ if (collectCandidatePaths(input).some((value) => isReportPath(value, cwd))) {
128
+ await markReportRead(cwd, AGENT_KEY);
129
+ emit({});
130
+ process.exit(0);
131
+ }
132
+ if (isBroadSearchTool(toolName) && !await hasSeenReport(cwd, AGENT_KEY)) {
133
+ emit({
134
+ permissionDecision: "deny",
135
+ permissionDecisionReason: REPORT_NOTE
136
+ });
137
+ process.exit(0);
138
+ }
139
+ emit({});
140
+ }
141
+ await main();
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/hooks/marker-state.ts
4
+ import crypto from "crypto";
5
+ import fs from "fs/promises";
6
+ import os from "os";
7
+ import path from "path";
8
+ function markerState(cwd, agentKey) {
9
+ const hash = crypto.createHash("sha256").update(cwd).digest("hex");
10
+ const dir = path.join(os.tmpdir(), "swarmvault-agent-hooks", agentKey, hash);
11
+ return {
12
+ dir,
13
+ markerPath: path.join(dir, "report-read")
14
+ };
15
+ }
16
+ function isReportPath(value, cwd) {
17
+ if (typeof value !== "string" || value.length === 0) {
18
+ return false;
19
+ }
20
+ const reportSuffix = path.join("wiki", "graph", "report.md");
21
+ const normalized = value.replaceAll("\\", "/");
22
+ const reportNormalized = reportSuffix.replaceAll("\\", "/");
23
+ if (normalized.endsWith(reportNormalized)) {
24
+ return true;
25
+ }
26
+ return path.resolve(cwd, value) === path.resolve(cwd, reportSuffix);
27
+ }
28
+ function collectCandidatePaths(node, acc = []) {
29
+ if (typeof node === "string") {
30
+ acc.push(node);
31
+ return acc;
32
+ }
33
+ if (!node || typeof node !== "object") {
34
+ return acc;
35
+ }
36
+ if (Array.isArray(node)) {
37
+ for (const item of node) {
38
+ collectCandidatePaths(item, acc);
39
+ }
40
+ return acc;
41
+ }
42
+ for (const [key, value] of Object.entries(node)) {
43
+ if (["path", "filePath", "file_path", "paths", "target", "targets"].includes(key)) {
44
+ collectCandidatePaths(value, acc);
45
+ continue;
46
+ }
47
+ collectCandidatePaths(value, acc);
48
+ }
49
+ return acc;
50
+ }
51
+ function resolveInputCwd(input) {
52
+ const shaped = input ?? {};
53
+ const candidate = typeof shaped.cwd === "string" && shaped.cwd || typeof shaped.directory === "string" && shaped.directory || typeof shaped.workspace?.cwd === "string" && shaped.workspace.cwd || typeof shaped.toolInput?.cwd === "string" && shaped.toolInput.cwd || process.cwd();
54
+ return path.resolve(candidate);
55
+ }
56
+ function resolveToolName(input) {
57
+ const shaped = input ?? {};
58
+ return String(shaped.toolName ?? shaped.tool_name ?? shaped.tool?.name ?? shaped.name ?? "");
59
+ }
60
+ async function hasReport(cwd) {
61
+ try {
62
+ await fs.access(path.join(cwd, "wiki", "graph", "report.md"));
63
+ return true;
64
+ } catch {
65
+ return false;
66
+ }
67
+ }
68
+ async function markReportRead(cwd, agentKey) {
69
+ const state = markerState(cwd, agentKey);
70
+ await fs.mkdir(state.dir, { recursive: true });
71
+ await fs.writeFile(state.markerPath, "seen\n", "utf8");
72
+ }
73
+ async function hasSeenReport(cwd, agentKey) {
74
+ const state = markerState(cwd, agentKey);
75
+ try {
76
+ await fs.access(state.markerPath);
77
+ return true;
78
+ } catch {
79
+ return false;
80
+ }
81
+ }
82
+ async function resetSession(cwd, agentKey) {
83
+ const state = markerState(cwd, agentKey);
84
+ await fs.rm(state.dir, { recursive: true, force: true });
85
+ }
86
+ function isBroadSearchTool(toolName) {
87
+ return /grep|glob|search|find/i.test(toolName);
88
+ }
89
+ async function readHookInput() {
90
+ let body = "";
91
+ for await (const chunk of process.stdin) {
92
+ body += chunk;
93
+ }
94
+ if (!body.trim()) {
95
+ return {};
96
+ }
97
+ try {
98
+ return JSON.parse(body);
99
+ } catch {
100
+ return {};
101
+ }
102
+ }
103
+ var REPORT_NOTE = "SwarmVault graph report exists at wiki/graph/report.md. Read it before broad grep/glob searching.";
104
+
105
+ // src/hooks/gemini.ts
106
+ var AGENT_KEY = "gemini";
107
+ function emit(value) {
108
+ process.stdout.write(`${JSON.stringify(value)}
109
+ `);
110
+ }
111
+ async function main() {
112
+ const mode = process.argv[2] ?? "";
113
+ const input = await readHookInput();
114
+ const cwd = resolveInputCwd(input);
115
+ if (!await hasReport(cwd)) {
116
+ emit({});
117
+ process.exit(0);
118
+ }
119
+ if (mode === "session-start") {
120
+ await resetSession(cwd, AGENT_KEY);
121
+ emit({
122
+ systemMessage: REPORT_NOTE,
123
+ hookSpecificOutput: {
124
+ hookEventName: "SessionStart",
125
+ additionalContext: "SwarmVault graph report: wiki/graph/report.md"
126
+ }
127
+ });
128
+ process.exit(0);
129
+ }
130
+ const toolName = resolveToolName(input);
131
+ if (collectCandidatePaths(input).some((value) => isReportPath(value, cwd))) {
132
+ await markReportRead(cwd, AGENT_KEY);
133
+ emit({});
134
+ process.exit(0);
135
+ }
136
+ if (isBroadSearchTool(toolName) && !await hasSeenReport(cwd, AGENT_KEY)) {
137
+ emit({ systemMessage: REPORT_NOTE });
138
+ process.exit(0);
139
+ }
140
+ emit({});
141
+ }
142
+ await main();
@@ -0,0 +1,50 @@
1
+ // src/hooks/opencode.ts
2
+ import path from "path";
3
+ var reportRelativePath = path.join("wiki", "graph", "report.md");
4
+ var name = "swarmvault-graph-first";
5
+ async function swarmvaultGraphFirst({ client }) {
6
+ let reportSeen = false;
7
+ async function hasReport(cwd) {
8
+ try {
9
+ await Bun.file(path.join(cwd, reportRelativePath)).arrayBuffer();
10
+ return true;
11
+ } catch {
12
+ return false;
13
+ }
14
+ }
15
+ async function note(message) {
16
+ if (client?.app?.log) {
17
+ await client.app.log({
18
+ level: "info",
19
+ message
20
+ });
21
+ }
22
+ }
23
+ return {
24
+ async "session.created"(input) {
25
+ reportSeen = false;
26
+ const cwd = input?.session?.cwd ?? process.cwd();
27
+ if (await hasReport(cwd)) {
28
+ await note("SwarmVault graph report exists. Read wiki/graph/report.md before broad workspace searching.");
29
+ }
30
+ },
31
+ async "tool.execute.before"(input) {
32
+ const cwd = input?.session?.cwd ?? process.cwd();
33
+ if (!await hasReport(cwd)) {
34
+ return;
35
+ }
36
+ const argsText = JSON.stringify(input?.args ?? {});
37
+ if (argsText.includes("wiki/graph/report.md")) {
38
+ reportSeen = true;
39
+ return;
40
+ }
41
+ if (!reportSeen && ["glob", "grep"].includes(String(input?.tool ?? ""))) {
42
+ await note("SwarmVault graph report exists. Read wiki/graph/report.md before broad workspace searching.");
43
+ }
44
+ }
45
+ };
46
+ }
47
+ export {
48
+ swarmvaultGraphFirst as default,
49
+ name
50
+ };
package/dist/index.d.ts CHANGED
@@ -1053,7 +1053,6 @@ interface BenchmarkArtifact {
1053
1053
  reductionRatio: number;
1054
1054
  sampleQuestions: string[];
1055
1055
  perQuestion: BenchmarkQuestionResult[];
1056
- questionResults: BenchmarkQuestionResult[];
1057
1056
  summary: BenchmarkSummary;
1058
1057
  }
1059
1058
  interface EmbeddingCacheEntry {