pilotswarm-sdk 0.2.0 → 0.2.2

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.
Files changed (173) hide show
  1. package/dist/agent-loader.d.ts +9 -0
  2. package/dist/agent-loader.d.ts.map +1 -1
  3. package/dist/agent-loader.js +3 -0
  4. package/dist/agent-loader.js.map +1 -1
  5. package/dist/child-notifications.d.ts +10 -0
  6. package/dist/child-notifications.d.ts.map +1 -1
  7. package/dist/child-notifications.js +15 -1
  8. package/dist/child-notifications.js.map +1 -1
  9. package/dist/client.d.ts +2 -2
  10. package/dist/client.d.ts.map +1 -1
  11. package/dist/client.js +14 -20
  12. package/dist/client.js.map +1 -1
  13. package/dist/cms-migrations.d.ts.map +1 -1
  14. package/dist/cms-migrations.js +321 -0
  15. package/dist/cms-migrations.js.map +1 -1
  16. package/dist/cms.d.ts +132 -8
  17. package/dist/cms.d.ts.map +1 -1
  18. package/dist/cms.js +142 -6
  19. package/dist/cms.js.map +1 -1
  20. package/dist/duroxide-schema-migration.d.ts +19 -0
  21. package/dist/duroxide-schema-migration.d.ts.map +1 -0
  22. package/dist/duroxide-schema-migration.js +122 -0
  23. package/dist/duroxide-schema-migration.js.map +1 -0
  24. package/dist/facts-migrations.d.ts.map +1 -1
  25. package/dist/facts-migrations.js +923 -0
  26. package/dist/facts-migrations.js.map +1 -1
  27. package/dist/facts-store.d.ts +278 -28
  28. package/dist/facts-store.d.ts.map +1 -1
  29. package/dist/facts-store.js +262 -32
  30. package/dist/facts-store.js.map +1 -1
  31. package/dist/facts-tools.d.ts +8 -1
  32. package/dist/facts-tools.d.ts.map +1 -1
  33. package/dist/facts-tools.js +458 -25
  34. package/dist/facts-tools.js.map +1 -1
  35. package/dist/graph-store.d.ts +243 -0
  36. package/dist/graph-store.d.ts.map +1 -0
  37. package/dist/graph-store.js +63 -0
  38. package/dist/graph-store.js.map +1 -0
  39. package/dist/graph-tools.d.ts +47 -0
  40. package/dist/graph-tools.d.ts.map +1 -0
  41. package/dist/graph-tools.js +554 -0
  42. package/dist/graph-tools.js.map +1 -0
  43. package/dist/horizon-env.d.ts +61 -0
  44. package/dist/horizon-env.d.ts.map +1 -0
  45. package/dist/horizon-env.js +120 -0
  46. package/dist/horizon-env.js.map +1 -0
  47. package/dist/index.d.ts +15 -4
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +10 -2
  50. package/dist/index.js.map +1 -1
  51. package/dist/inspect-tools.d.ts +2 -2
  52. package/dist/inspect-tools.d.ts.map +1 -1
  53. package/dist/inspect-tools.js +303 -6
  54. package/dist/inspect-tools.js.map +1 -1
  55. package/dist/knowledge-index.d.ts +33 -2
  56. package/dist/knowledge-index.d.ts.map +1 -1
  57. package/dist/knowledge-index.js +90 -19
  58. package/dist/knowledge-index.js.map +1 -1
  59. package/dist/managed-session.d.ts.map +1 -1
  60. package/dist/managed-session.js +61 -2
  61. package/dist/managed-session.js.map +1 -1
  62. package/dist/management-client.d.ts +81 -3
  63. package/dist/management-client.d.ts.map +1 -1
  64. package/dist/management-client.js +97 -20
  65. package/dist/management-client.js.map +1 -1
  66. package/dist/orchestration/agents.d.ts +4 -1
  67. package/dist/orchestration/agents.d.ts.map +1 -1
  68. package/dist/orchestration/agents.js +27 -4
  69. package/dist/orchestration/agents.js.map +1 -1
  70. package/dist/orchestration/index.d.ts +2 -2
  71. package/dist/orchestration/index.js +1 -1
  72. package/dist/orchestration/lifecycle.d.ts +3 -0
  73. package/dist/orchestration/lifecycle.d.ts.map +1 -1
  74. package/dist/orchestration/lifecycle.js +6 -1
  75. package/dist/orchestration/lifecycle.js.map +1 -1
  76. package/dist/orchestration/queue.d.ts.map +1 -1
  77. package/dist/orchestration/queue.js +10 -1
  78. package/dist/orchestration/queue.js.map +1 -1
  79. package/dist/orchestration/runtime.d.ts +1 -1
  80. package/dist/orchestration/state.d.ts +1 -0
  81. package/dist/orchestration/state.d.ts.map +1 -1
  82. package/dist/orchestration/state.js +1 -0
  83. package/dist/orchestration/state.js.map +1 -1
  84. package/dist/orchestration/turn.d.ts +2 -2
  85. package/dist/orchestration/turn.d.ts.map +1 -1
  86. package/dist/orchestration/turn.js +42 -12
  87. package/dist/orchestration/turn.js.map +1 -1
  88. package/dist/orchestration-registry.d.ts.map +1 -1
  89. package/dist/orchestration-registry.js +4 -2
  90. package/dist/orchestration-registry.js.map +1 -1
  91. package/dist/orchestration-version.d.ts +1 -1
  92. package/dist/orchestration-version.js +1 -1
  93. package/dist/orchestration.d.ts +2 -2
  94. package/dist/orchestration.js +1 -1
  95. package/dist/orchestration_1_0_46.d.ts +1 -1
  96. package/dist/orchestration_1_0_47.d.ts +1 -1
  97. package/dist/orchestration_1_0_48.d.ts +1 -1
  98. package/dist/orchestration_1_0_49.d.ts +1 -1
  99. package/dist/orchestration_1_0_50.d.ts +1 -1
  100. package/dist/orchestration_1_0_52/agents.d.ts +38 -0
  101. package/dist/orchestration_1_0_52/agents.d.ts.map +1 -0
  102. package/dist/orchestration_1_0_52/agents.js +735 -0
  103. package/dist/orchestration_1_0_52/agents.js.map +1 -0
  104. package/dist/orchestration_1_0_52/index.d.ts +24 -0
  105. package/dist/orchestration_1_0_52/index.d.ts.map +1 -0
  106. package/dist/orchestration_1_0_52/index.js +13 -0
  107. package/dist/orchestration_1_0_52/index.js.map +1 -0
  108. package/dist/orchestration_1_0_52/lifecycle.d.ts +38 -0
  109. package/dist/orchestration_1_0_52/lifecycle.d.ts.map +1 -0
  110. package/dist/orchestration_1_0_52/lifecycle.js +504 -0
  111. package/dist/orchestration_1_0_52/lifecycle.js.map +1 -0
  112. package/dist/orchestration_1_0_52/queue.d.ts +7 -0
  113. package/dist/orchestration_1_0_52/queue.d.ts.map +1 -0
  114. package/dist/orchestration_1_0_52/queue.js +635 -0
  115. package/dist/orchestration_1_0_52/queue.js.map +1 -0
  116. package/dist/orchestration_1_0_52/runtime.d.ts +29 -0
  117. package/dist/orchestration_1_0_52/runtime.d.ts.map +1 -0
  118. package/dist/orchestration_1_0_52/runtime.js +190 -0
  119. package/dist/orchestration_1_0_52/runtime.js.map +1 -0
  120. package/dist/orchestration_1_0_52/state.d.ts +124 -0
  121. package/dist/orchestration_1_0_52/state.d.ts.map +1 -0
  122. package/dist/orchestration_1_0_52/state.js +104 -0
  123. package/dist/orchestration_1_0_52/state.js.map +1 -0
  124. package/dist/orchestration_1_0_52/turn.d.ts +6 -0
  125. package/dist/orchestration_1_0_52/turn.d.ts.map +1 -0
  126. package/dist/orchestration_1_0_52/turn.js +834 -0
  127. package/dist/orchestration_1_0_52/turn.js.map +1 -0
  128. package/dist/orchestration_1_0_52/utils.d.ts +22 -0
  129. package/dist/orchestration_1_0_52/utils.d.ts.map +1 -0
  130. package/dist/orchestration_1_0_52/utils.js +226 -0
  131. package/dist/orchestration_1_0_52/utils.js.map +1 -0
  132. package/dist/resourcemgr-tools.d.ts +2 -2
  133. package/dist/resourcemgr-tools.d.ts.map +1 -1
  134. package/dist/resourcemgr-tools.js +1 -1
  135. package/dist/resourcemgr-tools.js.map +1 -1
  136. package/dist/session-dumper.d.ts +2 -2
  137. package/dist/session-dumper.d.ts.map +1 -1
  138. package/dist/session-dumper.js.map +1 -1
  139. package/dist/session-manager.d.ts +8 -2
  140. package/dist/session-manager.d.ts.map +1 -1
  141. package/dist/session-manager.js +86 -4
  142. package/dist/session-manager.js.map +1 -1
  143. package/dist/session-messages.d.ts +2 -2
  144. package/dist/session-messages.d.ts.map +1 -1
  145. package/dist/session-messages.js +0 -6
  146. package/dist/session-messages.js.map +1 -1
  147. package/dist/session-proxy.d.ts +47 -2
  148. package/dist/session-proxy.d.ts.map +1 -1
  149. package/dist/session-proxy.js +79 -59
  150. package/dist/session-proxy.js.map +1 -1
  151. package/dist/storage-config.d.ts +62 -0
  152. package/dist/storage-config.d.ts.map +1 -0
  153. package/dist/storage-config.js +138 -0
  154. package/dist/storage-config.js.map +1 -0
  155. package/dist/storage-providers.d.ts +25 -0
  156. package/dist/storage-providers.d.ts.map +1 -0
  157. package/dist/storage-providers.js +150 -0
  158. package/dist/storage-providers.js.map +1 -0
  159. package/dist/sweeper-tools.d.ts +2 -2
  160. package/dist/sweeper-tools.d.ts.map +1 -1
  161. package/dist/system-agents.d.ts +2 -2
  162. package/dist/system-agents.d.ts.map +1 -1
  163. package/dist/types.d.ts +103 -2
  164. package/dist/types.d.ts.map +1 -1
  165. package/dist/types.js.map +1 -1
  166. package/dist/worker.d.ts +5 -4
  167. package/dist/worker.d.ts.map +1 -1
  168. package/dist/worker.js +108 -33
  169. package/dist/worker.js.map +1 -1
  170. package/package.json +3 -1
  171. package/plugins/mgmt/agents/agent-tuner.agent.md +56 -4
  172. package/plugins/mgmt/agents/facts-manager.agent.md +81 -3
  173. package/plugins/mgmt/skills/graph-debug/SKILL.md +133 -0
@@ -0,0 +1,554 @@
1
+ import { defineTool } from "@github/copilot-sdk";
2
+ // Roles that may run the privileged crawl work queue (`facts_read_uncrawled` /
3
+ // `facts_mark_crawled`, which read facts across ALL scopes). The app assigns the
4
+ // harvester role to its own agent; the facts-manager holds the queue too but is
5
+ // dormant by default (07 §1.5). agent-tuner is read-only and never harvests.
6
+ // NOTE: graph write/delete is NOT gated by this role — it is open to every
7
+ // non-tuner session (the knowledge graph is shared).
8
+ const TUNER_AGENT_ID = "agent-tuner";
9
+ const FACTS_MANAGER_AGENT_ID = "facts-manager";
10
+ const DEFAULT_GRAPH_NAMESPACE = "default";
11
+ function namespaceKey(namespace) {
12
+ const clean = String(namespace ?? "").trim().replace(/\/+$/g, "");
13
+ return clean.length === 0 ? DEFAULT_GRAPH_NAMESPACE : clean;
14
+ }
15
+ function isDefaultNamespace(namespace) {
16
+ return namespaceKey(namespace).toLowerCase() === DEFAULT_GRAPH_NAMESPACE;
17
+ }
18
+ function normalizeNamespace(value) {
19
+ const clean = typeof value === "string" ? value.trim().replace(/\/+$/g, "") : "";
20
+ return clean.length > 0 && clean.toLowerCase() !== DEFAULT_GRAPH_NAMESPACE ? clean : null;
21
+ }
22
+ function boundedPreview(value, max = 80) {
23
+ const text = typeof value === "string" ? value.trim() : "";
24
+ if (!text)
25
+ return undefined;
26
+ return text.length > max ? text.slice(0, max) : text;
27
+ }
28
+ function isFactSeed(seed) {
29
+ return /^(shared|session):/.test(seed);
30
+ }
31
+ function isLikelyNodeKey(seed) {
32
+ return !isFactSeed(seed) && /^[a-z][a-z0-9_-]*:/i.test(seed);
33
+ }
34
+ /**
35
+ * Build the graph + crawl-queue tools (enhancedfactstore 07 P4). Registered
36
+ * ONLY when a `graphStore` is present. Reader tools (search/neighbourhood) go to
37
+ * every session; graph write/delete (`graph_upsert_*` / `graph_merge_nodes` /
38
+ * `graph_delete_*`) go to EVERY session EXCEPT the read-only agent-tuner, so any
39
+ * agent can incorporate into the SHARED graph; the crawl work queue
40
+ * (`facts_read_uncrawled` / `facts_mark_crawled`) stays harvester-role +
41
+ * facts-manager only (it reads facts across ALL scopes, bypassing per-session
42
+ * ACL); `graph_stats` (read-only) goes to facts-manager + agent-tuner.
43
+ * agent-tuner never gets a mutating tool.
44
+ */
45
+ export function createGraphTools(opts) {
46
+ const { graphStore, factStore, agentIdentity, isHarvester, recordEvent } = opts;
47
+ const agentId = opts.agentId ?? agentIdentity ?? "harvester";
48
+ const isTuner = agentIdentity === TUNER_AGENT_ID;
49
+ const isFactsManager = agentIdentity === FACTS_MANAGER_AGENT_ID;
50
+ // ACL resolver. FAIL CLOSED: with no resolver, restrict reads to the
51
+ // caller's own session (readerSessionId only) — never unrestricted. The
52
+ // tuner is always unrestricted (privileged read-only investigator), matching
53
+ // the read_facts model.
54
+ const resolveAccess = async (sessionId) => {
55
+ if (isTuner)
56
+ return { unrestricted: true };
57
+ if (opts.resolveAccess)
58
+ return opts.resolveAccess(sessionId);
59
+ return { readerSessionId: sessionId ?? null, grantedSessionIds: [] };
60
+ };
61
+ // Harvester powers (the crawl work queue): the app-assigned harvester role OR
62
+ // the facts-manager (which holds them dormant). Never the tuner.
63
+ const canHarvest = !isTuner && (isHarvester === true || isFactsManager);
64
+ // Graph write/delete is open to EVERY session that can run tools, so any
65
+ // agent can incorporate into the SHARED knowledge graph. The only exception
66
+ // is the read-only agent-tuner, which never receives a mutating tool.
67
+ const canWriteGraph = !isTuner;
68
+ // Namespace registry tools are optional: older/third-party GraphStore
69
+ // providers may implement graph search but not the registry sidecar.
70
+ const canReadNamespaces = typeof graphStore.listGraphNamespaces === "function"
71
+ && typeof graphStore.getGraphNamespace === "function";
72
+ const canUpsertNamespace = typeof graphStore.upsertGraphNamespace === "function";
73
+ const canArchiveNamespace = typeof graphStore.archiveGraphNamespace === "function";
74
+ const canDeleteNamespace = typeof graphStore.deleteGraphNamespace === "function";
75
+ const tools = [];
76
+ // Record a graph search for tuner forensics — best-effort, never blocks.
77
+ const recordSearch = (sessionId, eventType, data) => {
78
+ if (!recordEvent || !sessionId)
79
+ return;
80
+ recordEvent(sessionId, eventType, { ...data, callerAgentId: agentId }).catch(() => { });
81
+ };
82
+ const recordNamespaceMutation = (sessionId, action, namespace, data = {}) => {
83
+ if (!recordEvent || !sessionId)
84
+ return;
85
+ recordEvent(sessionId, "graph.namespace_mutated", {
86
+ action,
87
+ namespace,
88
+ ...((data && typeof data === "object") ? data : {}),
89
+ at: new Date().toISOString(),
90
+ }).catch(() => { });
91
+ };
92
+ // ── Reader tools (every session) ─────────────────────────────────────────
93
+ if (canReadNamespaces) {
94
+ tools.push(defineTool("graph_list_namespaces", {
95
+ description: "List registered graph knowledge-base namespaces. Use this FIRST when a task may benefit from " +
96
+ "graph/domain enrichment: inspect each row's compact frontmatter (name + description) to decide " +
97
+ "which corpus is relevant before deeper graph traversal. Compact by default; set includeDetails " +
98
+ "only when frontmatter is insufficient.",
99
+ parameters: {
100
+ type: "object",
101
+ properties: {
102
+ prefix: { type: "string", description: "Optional string-prefix filter over registered namespace keys." },
103
+ includeArchived: { type: "boolean", description: "Include archived namespaces. Default false." },
104
+ includeDetails: { type: "boolean", description: "Include source/schema/harvest details. Default false." },
105
+ },
106
+ },
107
+ handler: (a = {}) => graphStore.listGraphNamespaces({
108
+ prefix: a.prefix,
109
+ includeArchived: a.includeArchived === true,
110
+ includeDetails: a.includeDetails === true,
111
+ }),
112
+ }));
113
+ tools.push(defineTool("graph_get_namespace", {
114
+ description: "Get the full descriptor for one graph namespace after graph_list_namespaces frontmatter suggests it is relevant. " +
115
+ "Do not call this for every namespace by default; use it lazily when details are needed.",
116
+ parameters: {
117
+ type: "object",
118
+ properties: {
119
+ namespace: { type: "string", description: "Registered graph namespace key, e.g. 'default' or 'corpus/acme'." },
120
+ },
121
+ required: ["namespace"],
122
+ },
123
+ handler: (a) => graphStore.getGraphNamespace(a.namespace),
124
+ }));
125
+ }
126
+ tools.push(defineTool("graph_search_nodes", {
127
+ description: "Find / expand knowledge-graph nodes. RESOLVE (does this entity exist? — pass kind + nameLike before " +
128
+ "creating anything) and PIVOT (seeds = fact scopeKeys from facts_search, expanded via EVIDENCED_BY; node " +
129
+ "keys expand directly; depth bounds the hops). Each hit carries its evidence fact scopeKeys — feed those " +
130
+ "into read_facts({ scopeKeys }) to get the underlying facts.",
131
+ parameters: {
132
+ type: "object",
133
+ properties: {
134
+ kind: { type: "string", description: "Free-text node kind filter (person, patch, file, …)." },
135
+ nameLike: { type: "string", description: "Lexical match on node name or any alias. The resolve key." },
136
+ namespace: {
137
+ type: "string",
138
+ description: "Optional graph namespace subtree. Matches this exact namespace and descendants, e.g. 'corpus/acme' includes 'corpus/acme/services'.",
139
+ },
140
+ seeds: { type: "array", items: { type: "string" }, description: "Fact scopeKeys OR node keys to anchor from." },
141
+ depth: { type: "number", description: "Hops to expand from seeds (1..5)." },
142
+ limit: { type: "number" },
143
+ },
144
+ },
145
+ handler: async (a, ctx) => {
146
+ const startedAt = Date.now();
147
+ const access = await resolveAccess(ctx?.sessionId);
148
+ const hits = await graphStore.searchGraphNodes({ kind: a.kind, nameLike: a.nameLike, namespace: a.namespace, seeds: a.seeds, depth: a.depth, limit: a.limit }, access);
149
+ const seeds = Array.isArray(a.seeds) ? a.seeds.filter((seed) => typeof seed === "string" && seed.trim().length > 0) : [];
150
+ const nodeKeySeeds = seeds.filter(isLikelyNodeKey);
151
+ recordSearch(ctx?.sessionId, "graph.searched", {
152
+ operation: "graph_search_nodes",
153
+ kind: a.kind ?? null,
154
+ nameLikePreview: boundedPreview(a.nameLike),
155
+ namespace: normalizeNamespace(a.namespace),
156
+ seedCount: seeds.length,
157
+ nodeKeySeedCount: nodeKeySeeds.length,
158
+ depth: a.depth ?? null,
159
+ limit: a.limit ?? 50,
160
+ resultCount: hits.length,
161
+ durationMs: Date.now() - startedAt,
162
+ });
163
+ for (const nodeKey of nodeKeySeeds) {
164
+ recordSearch(ctx?.sessionId, "graph.node_searched", {
165
+ operation: "graph_search_nodes",
166
+ nodeKey,
167
+ namespace: normalizeNamespace(a.namespace),
168
+ durationMs: Date.now() - startedAt,
169
+ });
170
+ }
171
+ return hits;
172
+ },
173
+ }));
174
+ tools.push(defineTool("graph_search_edges", {
175
+ description: "Find graph edges, two ways: anchor-and-explore (set fromKey and/or toKey) or exact-predicate " +
176
+ "(predicate / predicateKey — exact equality, no fuzzy match).",
177
+ parameters: {
178
+ type: "object",
179
+ properties: {
180
+ predicate: { type: "string", description: "EXACT predicate text." },
181
+ predicateKey: { type: "string", description: "EXACT normalized key (preferred)." },
182
+ fromKey: { type: "string" },
183
+ toKey: { type: "string" },
184
+ namespace: {
185
+ type: "string",
186
+ description: "Optional graph namespace subtree. An edge matches when the edge itself or either endpoint is in the namespace subtree.",
187
+ },
188
+ minConfidence: { type: "number" },
189
+ limit: { type: "number" },
190
+ },
191
+ },
192
+ handler: async (a, ctx) => {
193
+ const startedAt = Date.now();
194
+ const access = await resolveAccess(ctx?.sessionId);
195
+ const hits = await graphStore.searchGraphEdges(a, access);
196
+ const normalizedPredicateKey = a.predicateKey
197
+ ?? (typeof a.predicate === "string" && typeof graphStore.normalizePredicateKey === "function"
198
+ ? graphStore.normalizePredicateKey(a.predicate)
199
+ : null);
200
+ recordSearch(ctx?.sessionId, "graph.searched", {
201
+ operation: "graph_search_edges",
202
+ predicateKey: normalizedPredicateKey,
203
+ fromKey: a.fromKey ?? null,
204
+ toKey: a.toKey ?? null,
205
+ namespace: normalizeNamespace(a.namespace),
206
+ minConfidence: a.minConfidence ?? null,
207
+ limit: a.limit ?? 50,
208
+ resultCount: hits.length,
209
+ durationMs: Date.now() - startedAt,
210
+ });
211
+ return hits;
212
+ },
213
+ }));
214
+ tools.push(defineTool("graph_neighbourhood", {
215
+ description: "Bounded subgraph around a node — 'show me everything connected to X'.",
216
+ parameters: {
217
+ type: "object",
218
+ properties: {
219
+ nodeKey: { type: "string" },
220
+ depth: { type: "number", description: "Hops (clamped 1..5)." },
221
+ namespace: {
222
+ type: "string",
223
+ description: "Optional graph namespace subtree for returned nodes/edges. Matches exact namespace and descendants.",
224
+ },
225
+ },
226
+ required: ["nodeKey", "depth"],
227
+ },
228
+ handler: async (a, ctx) => {
229
+ const startedAt = Date.now();
230
+ const access = await resolveAccess(ctx?.sessionId);
231
+ const sub = await graphStore.graphNeighbourhood(a.nodeKey, a.depth, access, { namespace: a.namespace });
232
+ const durationMs = Date.now() - startedAt;
233
+ recordSearch(ctx?.sessionId, "graph.searched", {
234
+ operation: "graph_neighbourhood",
235
+ nodeKey: a.nodeKey,
236
+ namespace: normalizeNamespace(a.namespace),
237
+ depth: a.depth,
238
+ resultCount: sub.nodes.length + sub.edges.length,
239
+ nodeCount: sub.nodes.length,
240
+ edgeCount: sub.edges.length,
241
+ durationMs,
242
+ });
243
+ recordSearch(ctx?.sessionId, "graph.node_loaded", {
244
+ operation: "graph_neighbourhood",
245
+ nodeKey: a.nodeKey,
246
+ namespace: normalizeNamespace(a.namespace),
247
+ durationMs,
248
+ });
249
+ return sub;
250
+ },
251
+ }));
252
+ // ── graph_stats (read-only) — facts-manager + agent-tuner reporting ──────
253
+ if (isFactsManager || isTuner) {
254
+ tools.push(defineTool("graph_stats", {
255
+ description: "Read-only graph report: node + edge counts and crawl-queue status (how many facts remain " +
256
+ "uncrawled, reported up to a bounded probe). Use for status/health reporting — it never mutates the graph.",
257
+ parameters: {
258
+ type: "object",
259
+ properties: {
260
+ namespace: {
261
+ type: "string",
262
+ description: "Optional graph namespace subtree for node/edge counts and crawl backlog. Matches exact namespace and descendants.",
263
+ },
264
+ },
265
+ },
266
+ handler: async (a = {}) => {
267
+ // Prefer a provider aggregate (single cheap query). If the store
268
+ // does not implement graphStats(), fall back to a BOUNDED count —
269
+ // never a fan-out traversal (that would be a multi-minute DoS on a
270
+ // large graph).
271
+ //
272
+ // Crawl backlog: read a BOUNDED probe of the pending queue and
273
+ // report its size. readUncrawledFacts returns `count = rows
274
+ // returned` (capped by `limit`), so a limit:1 read would always
275
+ // report 0 or 1 — useless as a backlog signal. We probe up to
276
+ // BACKLOG_PROBE and flag `uncrawledFactsCapped` when the queue is
277
+ // at least that deep ("harvester is well behind"); the exact depth
278
+ // beyond the probe is not needed for a health report.
279
+ const BACKLOG_PROBE = 500;
280
+ const statsFn = graphStore.graphStats;
281
+ const uncrawled = await factStore.readUncrawledFacts({ namespace: a.namespace, limit: BACKLOG_PROBE });
282
+ const uncrawledFacts = uncrawled.count;
283
+ const uncrawledFactsCapped = uncrawled.count >= BACKLOG_PROBE;
284
+ if (typeof statsFn === "function") {
285
+ const s = await statsFn.call(graphStore, { namespace: a.namespace });
286
+ return {
287
+ nodeCount: s.nodeCount,
288
+ edgeCount: s.edgeCount,
289
+ uncrawledFacts: s.uncrawledFacts ?? uncrawledFacts,
290
+ uncrawledFactsCapped: s.uncrawledFacts != null ? undefined : uncrawledFactsCapped,
291
+ };
292
+ }
293
+ // Bounded fallback: report whether the graph is non-empty + the
294
+ // crawl backlog, without an O(N) traversal. nodeCount is a lower
295
+ // bound (capped sample) so callers know it is approximate.
296
+ const SAMPLE = 1000;
297
+ const sample = await graphStore.searchGraphNodes({ namespace: a.namespace, limit: SAMPLE }, { unrestricted: true });
298
+ return {
299
+ nodeCountAtLeast: sample.length,
300
+ nodeCountExact: sample.length < SAMPLE ? sample.length : undefined,
301
+ uncrawledFacts,
302
+ uncrawledFactsCapped,
303
+ note: typeof statsFn !== "function"
304
+ ? "Provider has no graphStats(); nodeCount is a bounded sample. Edge count omitted to avoid fan-out."
305
+ : undefined,
306
+ };
307
+ },
308
+ }));
309
+ }
310
+ // ── Crawl-queue tools (HARVESTER / facts-manager — privileged, all scopes) ─
311
+ // The crawl work queue reads facts across ALL scopes (bypassing per-session
312
+ // ACL), so it stays restricted to the harvester role and the (dormant)
313
+ // facts-manager — it is NOT opened up to every session.
314
+ if (canHarvest) {
315
+ tools.push(defineTool("facts_read_uncrawled", {
316
+ description: "PRIVILEGED harvester work queue: facts not yet incorporated into the graph (new or edited since the " +
317
+ "last crawl), across ALL scopes. Keep each fact's scopeKey and etag — both are the receipt facts_mark_crawled needs.",
318
+ parameters: {
319
+ type: "object",
320
+ properties: {
321
+ namespace: { type: "string", description: "Restrict the queue to a literal key prefix." },
322
+ limit: { type: "number", description: "Max facts this batch (default 20)." },
323
+ },
324
+ },
325
+ handler: (a) => factStore.readUncrawledFacts({ namespace: a.namespace, limit: a.limit }),
326
+ }));
327
+ tools.push(defineTool("facts_mark_crawled", {
328
+ description: "Stamp facts as incorporated so they leave the queue. Pass each fact's scopeKey and etag from facts_read_uncrawled. " +
329
+ "A skipped stamp means the fact was already marked, changed since your read, or no longer exists; re-read if needed.",
330
+ parameters: {
331
+ type: "object",
332
+ properties: {
333
+ stamps: {
334
+ type: "array",
335
+ items: {
336
+ type: "object",
337
+ properties: {
338
+ scopeKey: { type: "string" },
339
+ etag: { type: "number" },
340
+ },
341
+ required: ["scopeKey", "etag"],
342
+ },
343
+ },
344
+ },
345
+ required: ["stamps"],
346
+ },
347
+ handler: (a) => factStore.markFactsCrawled(a.stamps),
348
+ }));
349
+ tools.push(defineTool("graph_remove_evidence", {
350
+ description: "Reconcile a soft-deleted fact with the graph: remove this fact scopeKey from node EVIDENCED_BY anchors " +
351
+ "and edge evidence arrays, deleting graph nodes/edges that become evidence-less. Call this for " +
352
+ "facts_read_uncrawled rows where deletedAt/deleted_at is set, then mark the fact crawled with its scopeKey and etag.",
353
+ parameters: {
354
+ type: "object",
355
+ properties: {
356
+ scopeKey: { type: "string", description: "Deleted fact scopeKey from facts_read_uncrawled." },
357
+ namespace: { type: "string", description: "Optional graph namespace guard, e.g. corpus/northwind." },
358
+ },
359
+ required: ["scopeKey"],
360
+ },
361
+ handler: (a) => graphStore.removeGraphEvidence(a.scopeKey, { namespace: a.namespace }),
362
+ }));
363
+ }
364
+ // ── Namespace registry writes. Upsert follows normal graph-write policy so
365
+ // ordinary graph-aware agents can register corpora they just incorporated.
366
+ // Archive remains harvester/facts-manager only; delete is facts-manager only.
367
+ if (canWriteGraph && canUpsertNamespace) {
368
+ tools.push(defineTool("graph_upsert_namespace", {
369
+ description: "Register or update a graph namespace/corpus descriptor. Available to graph-writing sessions. " +
370
+ "Use when a corpus starts, before first crawl, or when static source/schema/harvest details change. " +
371
+ "frontmatter must be compact name/description discovery text; do not write per-crawl stats or secrets.",
372
+ parameters: {
373
+ type: "object",
374
+ properties: {
375
+ namespace: { type: "string", description: "Namespace key. Use 'default' only for the unscoped/NULL partition." },
376
+ frontmatter: {
377
+ type: "object",
378
+ properties: {
379
+ name: { type: "string", description: "Short display label. Defaults to namespace if omitted." },
380
+ description: { type: "string", description: "Compact when-to-use-this-corpus hint. Required." },
381
+ },
382
+ required: ["description"],
383
+ },
384
+ source: { type: "string", description: "How source fact keys map/link to this graph namespace. No secrets." },
385
+ nodeSchema: { type: "object", description: "Expected node kinds/properties/examples. Details only." },
386
+ edgeSchema: { type: "object", description: "Expected predicates/direction/semantics. Details only." },
387
+ harvestConfig: { type: "object", description: "Static, non-secret harvest shape/config handles. No per-crawl stats." },
388
+ archived: { type: "boolean", description: "Set archived state. Upsert normally clears archived to false." },
389
+ },
390
+ required: ["namespace", "frontmatter"],
391
+ },
392
+ handler: async (a, ctx) => {
393
+ const result = await graphStore.upsertGraphNamespace({
394
+ namespace: a.namespace,
395
+ frontmatter: a.frontmatter,
396
+ source: a.source,
397
+ nodeSchema: a.nodeSchema,
398
+ edgeSchema: a.edgeSchema,
399
+ harvestConfig: a.harvestConfig,
400
+ archived: a.archived,
401
+ });
402
+ recordNamespaceMutation(ctx?.sessionId, "upsert", result.namespace, { archived: result.archived });
403
+ return result;
404
+ },
405
+ }));
406
+ }
407
+ if (canHarvest && canArchiveNamespace) {
408
+ tools.push(defineTool("graph_archive_namespace", {
409
+ description: "Archive a graph namespace so it disappears from ordinary discovery. Non-destructive: graph data remains searchable when directly targeted. Harvester/facts-manager only. 'default' cannot be archived.",
410
+ parameters: {
411
+ type: "object",
412
+ properties: {
413
+ namespace: { type: "string", description: "Registered namespace key to archive." },
414
+ },
415
+ required: ["namespace"],
416
+ },
417
+ handler: async (a, ctx) => {
418
+ if (isDefaultNamespace(a.namespace)) {
419
+ throw new Error("graph_archive_namespace: the 'default' namespace cannot be archived");
420
+ }
421
+ const key = namespaceKey(a.namespace);
422
+ const archived = await graphStore.archiveGraphNamespace(key);
423
+ recordNamespaceMutation(ctx?.sessionId, "archive", key, { archived });
424
+ return { archived };
425
+ },
426
+ }));
427
+ }
428
+ if (isFactsManager && canDeleteNamespace) {
429
+ tools.push(defineTool("graph_delete_namespace", {
430
+ description: "DESTRUCTIVE facts-manager-only deletion. Deletes graph data for the exact namespace and then the registry row. " +
431
+ "Does not delete source facts and does not delete child namespaces. Use only on explicit user request. 'default' cannot be deleted.",
432
+ parameters: {
433
+ type: "object",
434
+ properties: {
435
+ namespace: { type: "string", description: "Exact namespace key to delete. Child namespaces are not deleted." },
436
+ confirmDestructiveDelete: { type: "boolean", description: "Must be true to confirm the destructive delete was explicitly requested by the user." },
437
+ reason: { type: "string", description: "Short reason / user request summary for auditability." },
438
+ },
439
+ required: ["namespace", "confirmDestructiveDelete", "reason"],
440
+ },
441
+ handler: async (a, ctx) => {
442
+ const key = namespaceKey(a.namespace);
443
+ if (key.toLowerCase() === DEFAULT_GRAPH_NAMESPACE) {
444
+ throw new Error("graph_delete_namespace: the 'default' namespace cannot be deleted");
445
+ }
446
+ if (a.confirmDestructiveDelete !== true) {
447
+ throw new Error("graph_delete_namespace requires confirmDestructiveDelete=true");
448
+ }
449
+ if (!String(a.reason ?? "").trim()) {
450
+ throw new Error("graph_delete_namespace requires a non-empty reason");
451
+ }
452
+ const result = await graphStore.deleteGraphNamespace(key);
453
+ recordNamespaceMutation(ctx?.sessionId, "delete", key, { reason: String(a.reason).trim(), result });
454
+ return result;
455
+ },
456
+ }));
457
+ }
458
+ // ── Graph write / delete — every session EXCEPT the read-only agent-tuner ─
459
+ // The shared knowledge graph is writable by any agent that can run tools;
460
+ // graph population is app-owned and is not a facts-manager-only job.
461
+ if (!canWriteGraph)
462
+ return tools;
463
+ tools.push(defineTool("graph_upsert_node", {
464
+ description: "Create a node, or merge into an existing one (idempotent; aliases + evidence union in). RESOLVE BEFORE " +
465
+ "YOU CREATE: graph_search_nodes by nameLike first. Pass the source fact's scopeKey as evidence — it is " +
466
+ "the provenance and what makes reinforcement dedup work. The graph is SHARED: anything you incorporate " +
467
+ "is visible to every reader.",
468
+ parameters: {
469
+ type: "object",
470
+ properties: {
471
+ kind: { type: "string", description: "Free text: person, patch, code_file, thread…" },
472
+ name: { type: "string", description: "Canonical surface form." },
473
+ namespace: {
474
+ type: "string",
475
+ description: "Optional graph namespace, aligned with fact key prefixes (e.g. 'corpus/acme' or 'corpus/acme/services').",
476
+ },
477
+ aliases: { type: "array", items: { type: "string" }, description: "Other observed surface forms." },
478
+ evidence: { type: "array", items: { type: "string" }, description: "Fact scopeKeys justifying this node." },
479
+ },
480
+ required: ["kind", "name"],
481
+ },
482
+ handler: (a) => graphStore.upsertGraphNode({ ...a, agentId }),
483
+ }));
484
+ tools.push(defineTool("graph_upsert_edge", {
485
+ description: "Assert a free-text relationship, or reinforce an existing one. Re-stating the same (fromKey, predicate, " +
486
+ "toKey) does not duplicate — it bumps observations and combines confidence (noisy-OR) ONLY when you bring " +
487
+ "new evidence; same-evidence replays are harmless no-ops. Pass RESOLVED nodeKeys, not raw names.",
488
+ parameters: {
489
+ type: "object",
490
+ properties: {
491
+ fromKey: { type: "string", description: "Source node key." },
492
+ toKey: { type: "string", description: "Target node key." },
493
+ predicate: { type: "string", description: "Free-text verb, e.g. 'revives argument from'." },
494
+ namespace: {
495
+ type: "string",
496
+ description: "Optional graph namespace for this edge assertion. Use the same namespace as the source evidence/domain when known.",
497
+ },
498
+ confidence: { type: "number", description: "0..1 for THIS observation (default 1.0)." },
499
+ evidence: { type: "array", items: { type: "string" }, description: "Fact scopeKeys justifying the edge." },
500
+ },
501
+ required: ["fromKey", "toKey", "predicate"],
502
+ },
503
+ handler: (a) => graphStore.upsertGraphEdge({ ...a, agentId }),
504
+ }));
505
+ tools.push(defineTool("graph_merge_nodes", {
506
+ description: "Entity resolution: fold a duplicate node into the survivor (union aliases, repoint edges, delete the " +
507
+ "duplicate). Use when you discover two nodes are the same entity after the fact.",
508
+ parameters: {
509
+ type: "object",
510
+ properties: {
511
+ fromKey: { type: "string", description: "Duplicate to remove." },
512
+ intoKey: { type: "string", description: "Survivor to keep." },
513
+ namespace: {
514
+ type: "string",
515
+ description: "Optional namespace guard. Merge only when both duplicate and survivor are in this namespace subtree.",
516
+ },
517
+ reason: { type: "string", description: "Why they're the same (audit)." },
518
+ },
519
+ required: ["fromKey", "intoKey", "reason"],
520
+ },
521
+ handler: async (a) => { await graphStore.mergeGraphNodes(a.fromKey, a.intoKey, a.reason, { namespace: a.namespace }); return { merged: true }; },
522
+ }));
523
+ tools.push(defineTool("graph_delete_node", {
524
+ description: "Remove a node and all its edges (DETACH DELETE). No cascade to facts.",
525
+ parameters: {
526
+ type: "object",
527
+ properties: {
528
+ nodeKey: { type: "string" },
529
+ namespace: { type: "string", description: "Optional namespace guard. Delete only when the node is in this namespace subtree." },
530
+ },
531
+ required: ["nodeKey"],
532
+ },
533
+ handler: async (a) => ({ deleted: await graphStore.deleteGraphNode(a.nodeKey, { namespace: a.namespace }) }),
534
+ }));
535
+ tools.push(defineTool("graph_delete_edge", {
536
+ description: "Remove one exact edge triple. Returns whether something matched.",
537
+ parameters: {
538
+ type: "object",
539
+ properties: {
540
+ fromKey: { type: "string" },
541
+ toKey: { type: "string" },
542
+ predicateKey: { type: "string" },
543
+ namespace: {
544
+ type: "string",
545
+ description: "Optional namespace guard. Delete only when the edge itself or either endpoint is in this namespace subtree.",
546
+ },
547
+ },
548
+ required: ["fromKey", "toKey", "predicateKey"],
549
+ },
550
+ handler: async (a) => ({ deleted: await graphStore.deleteGraphEdge(a.fromKey, a.toKey, a.predicateKey, { namespace: a.namespace }) }),
551
+ }));
552
+ return tools;
553
+ }
554
+ //# sourceMappingURL=graph-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-tools.js","sourceRoot":"","sources":["../src/graph-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAKjD,+EAA+E;AAC/E,iFAAiF;AACjF,gFAAgF;AAChF,6EAA6E;AAC7E,2EAA2E;AAC3E,qDAAqD;AACrD,MAAM,cAAc,GAAG,aAAa,CAAC;AACrC,MAAM,sBAAsB,GAAG,eAAe,CAAC;AAC/C,MAAM,uBAAuB,GAAG,SAAS,CAAC;AAE1C,SAAS,YAAY,CAAC,SAAkB;IACpC,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAClE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,KAAK,CAAC;AAChE,CAAC;AAED,SAAS,kBAAkB,CAAC,SAAkB;IAC1C,OAAO,YAAY,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,KAAK,uBAAuB,CAAC;AAC7E,CAAC;AAED,SAAS,kBAAkB,CAAC,KA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BAChC,SAAS,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,6GAA6G;iBAC7H;aACJ;YACD,QAAQ,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,cAAc,CAAU;SAC1D;QACD,OAAO,EAAE,KAAK,EAAE,CAAM,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC;KAC7I,CAAC,CAAC,CAAC;IAEJ,OAAO,KAAK,CAAC;AACjB,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Convenience: build the optional EnhancedFactStore + knowledge-graph worker
3
+ * config from the canonical `HORIZON_*` environment variables.
4
+ *
5
+ * The `PilotSwarmWorker` intentionally does NOT read `process.env` itself — app
6
+ * entrypoints own env parsing and pass explicit config. This helper exists so the
7
+ * shipped CLI/portal embedded worker, the standalone K8s worker, and the examples
8
+ * all map the same env vars to the same worker fields, with no drift.
9
+ *
10
+ * Returns an EMPTY object when none of the `HORIZON_*` vars are set (the default —
11
+ * plain `PgFactStore`, no enhanced provider, no graph). The enhanced facts store and
12
+ * the knowledge graph are INDEPENDENT axes: setting only `HORIZON_GRAPH_DATABASE_URL`
13
+ * yields a graph over the base fact store (graph tools, no search). Spread the result
14
+ * into the worker options:
15
+ *
16
+ * ```ts
17
+ * const worker = new PilotSwarmWorker({
18
+ * store: process.env.DATABASE_URL,
19
+ * githubToken: process.env.GITHUB_TOKEN,
20
+ * ...horizonConfigFromEnv(),
21
+ * });
22
+ * ```
23
+ *
24
+ * Env vars (all optional except the database URL):
25
+ * HORIZON_DATABASE_URL → enhancedFactsDatabaseUrl (enables the enhanced
26
+ * provider; worker infers factsProvider="horizon")
27
+ * HORIZON_FACTS_SCHEMA → enhancedFactsSchema (default "horizon_facts")
28
+ * HORIZON_GRAPH_DATABASE_URL → graphDatabaseUrl (opt-in graph; unset ⇒ no graph)
29
+ * HORIZON_GRAPH_SCHEMA → graphSchema (default "horizon_graph")
30
+ * HORIZON_GRAPH_REGISTRY_SCHEMA → graphRegistrySchema (default
31
+ * `${graphSchema}_registry`; MUST differ from graphSchema)
32
+ * HORIZON_NAMESPACE_CACHE_TTL_MS → graphNamespaceCacheTtlMs (default 60000; 0 disables cache)
33
+ * HORIZON_EMBED_URL/MODEL/DIM → horizonEmbed (durable embedder; all three
34
+ * required, else the embedder is omitted and
35
+ * search runs lexical-only)
36
+ * HORIZON_EMBED_API_KEY → horizonEmbed.apiKey
37
+ * HORIZON_EMBED_API_KEY_HEADER→ horizonEmbed.apiKeyHeader (default "api-key")
38
+ * HORIZON_EMBED_BEARER → horizonEmbed.bearer (sends "Bearer <key>");
39
+ * inferred true when the header is "Authorization"
40
+ *
41
+ * @module
42
+ */
43
+ import type { EmbeddingEndpointConfig } from "./facts-store.js";
44
+ /** The subset of `PilotSwarmWorkerOptions` that the `HORIZON_*` env vars map to. */
45
+ export interface HorizonEnvConfig {
46
+ enhancedFactsDatabaseUrl?: string;
47
+ enhancedFactsSchema?: string;
48
+ horizonEmbed?: EmbeddingEndpointConfig;
49
+ graphDatabaseUrl?: string;
50
+ graphSchema?: string;
51
+ graphRegistrySchema?: string;
52
+ graphNamespaceCacheTtlMs?: number;
53
+ }
54
+ /**
55
+ * Map the `HORIZON_*` environment variables to the worker's enhanced-facts /
56
+ * knowledge-graph config. Pure and side-effect-free; safe to call at startup.
57
+ *
58
+ * @param env - Environment source (defaults to `process.env`).
59
+ */
60
+ export declare function horizonConfigFromEnv(env?: Record<string, string | undefined>): HorizonEnvConfig;
61
+ //# sourceMappingURL=horizon-env.d.ts.map