@nebutra/agent-runtime 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 (137) hide show
  1. package/LICENSE +21 -676
  2. package/README.md +2 -0
  3. package/dist/adapters/dispatcher-sse.js +1 -0
  4. package/dist/adapters/index.d.ts +24 -5
  5. package/dist/adapters/index.js +28 -0
  6. package/dist/adapters/index.js.map +1 -1
  7. package/dist/adapters/mcp-catalog.js +1 -0
  8. package/dist/adapters/prisma-rollout.js +1 -0
  9. package/dist/chunk-424PT5DM.js +23 -0
  10. package/dist/chunk-424PT5DM.js.map +1 -0
  11. package/dist/{chunk-NN7DATXA.js → chunk-4Y25ZTKI.js} +3 -3
  12. package/dist/chunk-4Y25ZTKI.js.map +1 -0
  13. package/dist/{chunk-BJBBR3QA.js → chunk-D4YAPLOW.js} +4 -4
  14. package/dist/chunk-D4YAPLOW.js.map +1 -0
  15. package/dist/{chunk-ZMYX5VBU.js → chunk-GQZKYWFT.js} +23 -7
  16. package/dist/chunk-GQZKYWFT.js.map +1 -0
  17. package/dist/chunk-KCNN4QUQ.js +255 -0
  18. package/dist/chunk-KCNN4QUQ.js.map +1 -0
  19. package/dist/{chunk-PGGWSUTM.js → chunk-NI4EDT4T.js} +2 -2
  20. package/dist/chunk-NI4EDT4T.js.map +1 -0
  21. package/dist/chunk-Q62VKHIT.js +178 -0
  22. package/dist/chunk-Q62VKHIT.js.map +1 -0
  23. package/dist/{chunk-MUF7ZZTO.js → chunk-R5HOSQUW.js} +2 -1
  24. package/dist/{chunk-MUF7ZZTO.js.map → chunk-R5HOSQUW.js.map} +1 -1
  25. package/dist/{chunk-5N4644PB.js → chunk-SD2ZJ7XG.js} +4 -4
  26. package/dist/cli.d.ts +2 -0
  27. package/dist/cli.js +52 -0
  28. package/dist/cli.js.map +1 -0
  29. package/dist/commands.js +1 -0
  30. package/dist/definitions.js +1 -0
  31. package/dist/dispatcher.js +1 -0
  32. package/dist/durable-turn.js +3 -2
  33. package/dist/hook-pipeline.js +1 -0
  34. package/dist/index.d.ts +8 -85
  35. package/dist/index.js +249 -134
  36. package/dist/index.js.map +1 -1
  37. package/dist/loop.d.ts +2 -2
  38. package/dist/loop.js +3 -2
  39. package/dist/mcp-bridge.d.ts +3 -3
  40. package/dist/mcp-bridge.js +3 -2
  41. package/dist/model.js +1 -0
  42. package/dist/orchestration.d.ts +84 -0
  43. package/dist/orchestration.js +16 -0
  44. package/dist/orchestration.js.map +1 -0
  45. package/dist/policy.js +1 -0
  46. package/dist/protocol.js +1 -0
  47. package/dist/pulsar.d.ts +78 -0
  48. package/dist/pulsar.js +17 -0
  49. package/dist/pulsar.js.map +1 -0
  50. package/dist/rollout-store-persistent.js +1 -0
  51. package/dist/rollout.js +1 -0
  52. package/dist/sandbox.js +2 -1
  53. package/dist/skills.js +2 -1
  54. package/dist/subagents.js +1 -0
  55. package/dist/tools.d.ts +4 -3
  56. package/dist/tools.js +5 -3
  57. package/package.json +84 -27
  58. package/.turbo/turbo-build.log +0 -115
  59. package/.turbo/turbo-test.log +0 -44
  60. package/.turbo/turbo-typecheck.log +0 -4
  61. package/CHANGELOG.md +0 -253
  62. package/dist/chunk-BJBBR3QA.js.map +0 -1
  63. package/dist/chunk-NN7DATXA.js.map +0 -1
  64. package/dist/chunk-PGGWSUTM.js.map +0 -1
  65. package/dist/chunk-ZMYX5VBU.js.map +0 -1
  66. package/src/adapters/dispatcher-sse.test.ts +0 -218
  67. package/src/adapters/dispatcher-sse.ts +0 -222
  68. package/src/adapters/index.ts +0 -18
  69. package/src/adapters/mcp-catalog.test.ts +0 -213
  70. package/src/adapters/mcp-catalog.ts +0 -188
  71. package/src/adapters/prisma-rollout.test.ts +0 -153
  72. package/src/adapters/prisma-rollout.ts +0 -104
  73. package/src/agent-runtime.test.ts +0 -176
  74. package/src/artifact-stream.test.ts +0 -330
  75. package/src/artifact-stream.ts +0 -453
  76. package/src/channel-gateway.test.ts +0 -432
  77. package/src/channel-gateway.ts +0 -357
  78. package/src/code-review.test.ts +0 -501
  79. package/src/code-review.ts +0 -495
  80. package/src/command-suggestions.test.ts +0 -251
  81. package/src/command-suggestions.ts +0 -338
  82. package/src/commands.test.ts +0 -184
  83. package/src/commands.ts +0 -140
  84. package/src/commit-message.test.ts +0 -249
  85. package/src/commit-message.ts +0 -180
  86. package/src/context-compaction.test.ts +0 -522
  87. package/src/context-compaction.ts +0 -434
  88. package/src/definitions.test.ts +0 -78
  89. package/src/definitions.ts +0 -190
  90. package/src/deployment-status.test.ts +0 -215
  91. package/src/deployment-status.ts +0 -227
  92. package/src/design-context.test.ts +0 -195
  93. package/src/design-context.ts +0 -198
  94. package/src/dispatcher.test.ts +0 -234
  95. package/src/dispatcher.ts +0 -189
  96. package/src/durable-turn.test.ts +0 -209
  97. package/src/durable-turn.ts +0 -135
  98. package/src/edit-planner.test.ts +0 -204
  99. package/src/edit-planner.ts +0 -325
  100. package/src/fuzzy-match.test.ts +0 -311
  101. package/src/fuzzy-match.ts +0 -444
  102. package/src/hook-pipeline.test.ts +0 -279
  103. package/src/hook-pipeline.ts +0 -373
  104. package/src/inbound-admission.test.ts +0 -394
  105. package/src/inbound-admission.ts +0 -246
  106. package/src/index.ts +0 -47
  107. package/src/loop.test.ts +0 -161
  108. package/src/loop.ts +0 -211
  109. package/src/mcp-bridge.test.ts +0 -165
  110. package/src/mcp-bridge.ts +0 -76
  111. package/src/memory-provider.test.ts +0 -232
  112. package/src/memory-provider.ts +0 -257
  113. package/src/model.ts +0 -168
  114. package/src/permission-ruleset.test.ts +0 -301
  115. package/src/permission-ruleset.ts +0 -200
  116. package/src/policy.ts +0 -151
  117. package/src/project-repo.test.ts +0 -232
  118. package/src/project-repo.ts +0 -311
  119. package/src/protocol.ts +0 -159
  120. package/src/rollout-store-persistent.test.ts +0 -217
  121. package/src/rollout-store-persistent.ts +0 -166
  122. package/src/rollout.ts +0 -150
  123. package/src/sandbox.ts +0 -113
  124. package/src/session-share.test.ts +0 -360
  125. package/src/session-share.ts +0 -310
  126. package/src/skill-distillation.test.ts +0 -177
  127. package/src/skill-distillation.ts +0 -369
  128. package/src/skills.test.ts +0 -277
  129. package/src/skills.ts +0 -255
  130. package/src/subagents.test.ts +0 -290
  131. package/src/subagents.ts +0 -332
  132. package/src/tools.ts +0 -126
  133. package/src/workbench.test.ts +0 -0
  134. package/src/workbench.ts +0 -0
  135. package/tsconfig.json +0 -12
  136. package/tsup.config.ts +0 -33
  137. /package/dist/{chunk-5N4644PB.js.map → chunk-SD2ZJ7XG.js.map} +0 -0
@@ -1,311 +0,0 @@
1
- /**
2
- * Tests for the fuzzy-match primitive.
3
- *
4
- * Pure, deterministic subsequence fuzzy matcher with smart-case behaviour,
5
- * a case-insensitive variant, an ignore-spaces variant, a glob-style wildcard
6
- * matcher, and a generic ranking helper. No external deps, no I/O, no state.
7
- *
8
- * Scoring is asserted by ORDERING (boundary/contiguous > scattered), never by
9
- * exact magnitudes — the heuristic is documented in fuzzy-match.ts and only its
10
- * ordering contract is part of the public surface.
11
- */
12
-
13
- import { describe, expect, it } from "vitest";
14
- import {
15
- matchIndices,
16
- matchIndicesCaseInsensitive,
17
- matchIndicesCaseInsensitiveIgnoreSpaces,
18
- matchWildcardPattern,
19
- matchWildcardPatternCaseInsensitive,
20
- rankByFuzzy,
21
- } from "./fuzzy-match.js";
22
-
23
- describe("matchIndices — subsequence fuzzy match", () => {
24
- it("returns ordered indices for a subsequence hit", () => {
25
- // "foobar": f=0 o=1 o=2 b=3 a=4 r=5 → f@0, b@3, r@5
26
- const result = matchIndices("foobar", "fbr");
27
- expect(result).not.toBeNull();
28
- expect(result?.indices).toEqual([0, 3, 5]);
29
- // indices must be strictly increasing and point at the matched chars
30
- expect(result?.indices).toEqual([...(result?.indices ?? [])].sort((a, b) => a - b));
31
- for (const i of result?.indices ?? []) {
32
- expect(i).toBeGreaterThanOrEqual(0);
33
- expect(i).toBeLessThan("foobar".length);
34
- }
35
- });
36
-
37
- it("returns null when query is not a subsequence", () => {
38
- expect(matchIndices("foobar", "xyz")).toBeNull();
39
- expect(matchIndices("abc", "abcd")).toBeNull();
40
- // out-of-order chars are not a subsequence
41
- expect(matchIndices("abc", "ba")).toBeNull();
42
- });
43
-
44
- it("matches a full exact string", () => {
45
- const result = matchIndices("hello", "hello");
46
- expect(result?.indices).toEqual([0, 1, 2, 3, 4]);
47
- });
48
-
49
- it("treats empty query as matching everything with score 0 and empty indices", () => {
50
- const result = matchIndices("anything", "");
51
- expect(result).not.toBeNull();
52
- expect(result?.indices).toEqual([]);
53
- expect(result?.score).toBe(0);
54
- });
55
-
56
- it("empty query matches even empty text", () => {
57
- const result = matchIndices("", "");
58
- expect(result?.indices).toEqual([]);
59
- expect(result?.score).toBe(0);
60
- });
61
-
62
- it("non-empty query against empty text is null", () => {
63
- expect(matchIndices("", "a")).toBeNull();
64
- });
65
-
66
- describe("smart-case", () => {
67
- it("all-lowercase query matches case-insensitively", () => {
68
- const result = matchIndices("FooBar", "fb");
69
- expect(result).not.toBeNull();
70
- expect(result?.indices).toEqual([0, 3]);
71
- });
72
-
73
- it("query with an uppercase char matches case-sensitively", () => {
74
- // 'B' must match an uppercase B; 'foobar' has none → null
75
- expect(matchIndices("foobar", "B")).toBeNull();
76
- // but it matches against a real uppercase B
77
- const result = matchIndices("fooBar", "B");
78
- expect(result?.indices).toEqual([3]);
79
- });
80
-
81
- it("mixed-case query: lowercase letters still match insensitively per char? (case-sensitive whole query)", () => {
82
- // Spec: presence of ANY uppercase makes the WHOLE query case-sensitive.
83
- // 'Fb' → 'F' needs uppercase F, 'b' needs lowercase b (case-sensitive).
84
- expect(matchIndices("foobar", "Fb")).toBeNull();
85
- const result = matchIndices("Foobar", "Fb");
86
- expect(result?.indices).toEqual([0, 3]);
87
- });
88
- });
89
-
90
- describe("boundary / contiguity scoring (ordering only)", () => {
91
- it("contiguous run outranks a scattered match", () => {
92
- const contiguous = matchIndices("foobar", "foo");
93
- const scattered = matchIndices("fxoxox foo", "foo");
94
- expect(contiguous).not.toBeNull();
95
- expect(scattered).not.toBeNull();
96
- expect((contiguous?.score ?? 0) > (scattered?.score ?? 0)).toBe(true);
97
- });
98
-
99
- it("word-boundary match outranks a mid-word match", () => {
100
- // "ab" right after a separator vs "ab" buried mid-token
101
- const boundary = matchIndices("foo/abc", "abc");
102
- const midword = matchIndices("xabcyyyabc", "abc");
103
- expect(boundary).not.toBeNull();
104
- expect(midword).not.toBeNull();
105
- expect((boundary?.score ?? 0) > (midword?.score ?? 0)).toBe(true);
106
- });
107
-
108
- it("match at string start outranks a later contiguous match", () => {
109
- const atStart = matchIndices("abcxxxx", "abc");
110
- const later = matchIndices("zzzzabc", "abc");
111
- expect((atStart?.score ?? 0) > (later?.score ?? 0)).toBe(true);
112
- });
113
-
114
- it("prefers the boundary subsequence when several exist", () => {
115
- // "fb" can match index 0/1 (mid 'foo bar' f..) or the boundary 'f' of
116
- // 'foo' + boundary 'b' of 'bar'. Boundary-preferring heuristic should pick
117
- // the word-start 'f' (0) and word-start 'b' (4).
118
- const result = matchIndices("foo bar", "fb");
119
- expect(result?.indices).toEqual([0, 4]);
120
- });
121
- });
122
- });
123
-
124
- describe("matchIndicesCaseInsensitive", () => {
125
- it("always ignores case even with uppercase in query", () => {
126
- // "foobar": f@0, b@3, r@5 — uppercase query, but ci variant folds it.
127
- const result = matchIndicesCaseInsensitive("foobar", "FBR");
128
- expect(result?.indices).toEqual([0, 3, 5]);
129
- });
130
-
131
- it("still returns null for non-subsequence", () => {
132
- expect(matchIndicesCaseInsensitive("foobar", "zzz")).toBeNull();
133
- });
134
-
135
- it("empty query → score 0, empty indices", () => {
136
- const result = matchIndicesCaseInsensitive("abc", "");
137
- expect(result?.score).toBe(0);
138
- expect(result?.indices).toEqual([]);
139
- });
140
- });
141
-
142
- describe("matchIndicesCaseInsensitiveIgnoreSpaces", () => {
143
- it("ignores spaces in query and text but returns original-text indices", () => {
144
- // text "foo bar" with query "f b" → spaces ignored on both sides.
145
- const result = matchIndicesCaseInsensitiveIgnoreSpaces("foo bar", "f b");
146
- expect(result).not.toBeNull();
147
- // indices must point at original positions of 'f' (0) and 'b' (4),
148
- // never at the space at index 3.
149
- expect(result?.indices).toEqual([0, 4]);
150
- expect(result?.indices).not.toContain(3);
151
- });
152
-
153
- it("is case-insensitive", () => {
154
- const result = matchIndicesCaseInsensitiveIgnoreSpaces("Foo Bar", "FB");
155
- expect(result?.indices).toEqual([0, 4]);
156
- });
157
-
158
- it("query that is only spaces behaves like empty query", () => {
159
- const result = matchIndicesCaseInsensitiveIgnoreSpaces("foo bar", " ");
160
- expect(result?.score).toBe(0);
161
- expect(result?.indices).toEqual([]);
162
- });
163
-
164
- it("returns null when non-space chars are not a subsequence", () => {
165
- expect(matchIndicesCaseInsensitiveIgnoreSpaces("foo bar", "zq")).toBeNull();
166
- });
167
-
168
- it("matched index never lands on a skipped space", () => {
169
- const result = matchIndicesCaseInsensitiveIgnoreSpaces("a b c d", "abcd");
170
- expect(result?.indices).toEqual([0, 2, 4, 6]);
171
- for (const i of result?.indices ?? []) {
172
- expect("a b c d"[i]).not.toBe(" ");
173
- }
174
- });
175
- });
176
-
177
- describe("matchWildcardPattern — glob-style, anchored full-string", () => {
178
- it("matches '*' as any run including empty", () => {
179
- expect(matchWildcardPattern("anything", "*")).toBe(true);
180
- expect(matchWildcardPattern("", "*")).toBe(true);
181
- expect(matchWildcardPattern("src/foo.ts", "src/*")).toBe(true);
182
- expect(matchWildcardPattern("src/", "src/*")).toBe(true);
183
- expect(matchWildcardPattern("abc", "a*c")).toBe(true);
184
- expect(matchWildcardPattern("ac", "a*c")).toBe(true);
185
- });
186
-
187
- it("'?' matches exactly one char", () => {
188
- expect(matchWildcardPattern("abc", "a?c")).toBe(true);
189
- expect(matchWildcardPattern("ac", "a?c")).toBe(false);
190
- expect(matchWildcardPattern("abbc", "a?c")).toBe(false);
191
- });
192
-
193
- it("char classes [abc] and ranges [a-z]", () => {
194
- expect(matchWildcardPattern("cat", "[cb]at")).toBe(true);
195
- expect(matchWildcardPattern("bat", "[cb]at")).toBe(true);
196
- expect(matchWildcardPattern("rat", "[cb]at")).toBe(false);
197
- expect(matchWildcardPattern("file9.txt", "file[0-9].txt")).toBe(true);
198
- expect(matchWildcardPattern("fileA.txt", "file[0-9].txt")).toBe(false);
199
- expect(matchWildcardPattern("x", "[a-z]")).toBe(true);
200
- expect(matchWildcardPattern("X", "[a-z]")).toBe(false);
201
- });
202
-
203
- it("escape with backslash treats metachars literally", () => {
204
- expect(matchWildcardPattern("a*b", "a\\*b")).toBe(true);
205
- expect(matchWildcardPattern("axb", "a\\*b")).toBe(false);
206
- expect(matchWildcardPattern("a?b", "a\\?b")).toBe(true);
207
- expect(matchWildcardPattern("a[b", "a\\[b")).toBe(true);
208
- });
209
-
210
- it("is anchored (full-string) — partial does not match", () => {
211
- expect(matchWildcardPattern("foobar", "foo")).toBe(false);
212
- expect(matchWildcardPattern("foobar", "foo*")).toBe(true);
213
- expect(matchWildcardPattern("foobar", "*bar")).toBe(true);
214
- expect(matchWildcardPattern("foobar", "bar")).toBe(false);
215
- });
216
-
217
- it("treats '/' as an ordinary char (path-like)", () => {
218
- expect(matchWildcardPattern("a/b/c", "a/*/c")).toBe(true);
219
- expect(matchWildcardPattern("a/b/c", "a*c")).toBe(true);
220
- expect(matchWildcardPattern("a/b/c", "*/*/*")).toBe(true);
221
- });
222
-
223
- it("is case-sensitive by default; case-insensitive variant ignores case", () => {
224
- expect(matchWildcardPattern("FOO", "foo")).toBe(false);
225
- expect(matchWildcardPatternCaseInsensitive("FOO", "foo")).toBe(true);
226
- expect(matchWildcardPatternCaseInsensitive("FoO.TS", "*.ts")).toBe(true);
227
- expect(matchWildcardPatternCaseInsensitive("Bat", "[CB]at")).toBe(true);
228
- });
229
-
230
- it("does not catastrophically backtrack on adversarial '*' input", () => {
231
- const text = "a".repeat(50);
232
- const pattern = `${"*".repeat(30)}b`;
233
- const start = Date.now();
234
- const matched = matchWildcardPattern(text, pattern);
235
- expect(matched).toBe(false);
236
- expect(Date.now() - start).toBeLessThan(1000);
237
- });
238
- });
239
-
240
- describe("rankByFuzzy", () => {
241
- interface Row {
242
- id: number;
243
- label: string;
244
- }
245
-
246
- const rows: Row[] = [
247
- { id: 1, label: "foobar" },
248
- { id: 2, label: "no match here" },
249
- { id: 3, label: "fxoxoxbar" },
250
- { id: 4, label: "foo/bar" },
251
- ];
252
-
253
- it("filters out non-matches", () => {
254
- const ranked = rankByFuzzy(rows, "fbr", (r) => r.label);
255
- expect(ranked.every((r) => r.item.id !== 2)).toBe(true);
256
- });
257
-
258
- it("sorts by score descending", () => {
259
- const ranked = rankByFuzzy(rows, "fbr", (r) => r.label);
260
- for (let i = 1; i < ranked.length; i++) {
261
- expect(ranked[i - 1]!.score).toBeGreaterThanOrEqual(ranked[i]!.score);
262
- }
263
- });
264
-
265
- it("returns score + indices alongside the item", () => {
266
- const ranked = rankByFuzzy(rows, "foo", (r) => r.label);
267
- const first = ranked[0]!;
268
- expect(typeof first.score).toBe("number");
269
- expect(Array.isArray(first.indices)).toBe(true);
270
- expect(first.indices.length).toBe(3);
271
- });
272
-
273
- it("is stable for equal scores (preserves input order)", () => {
274
- const tied: Row[] = [
275
- { id: 10, label: "abc" },
276
- { id: 11, label: "abc" },
277
- { id: 12, label: "abc" },
278
- ];
279
- const ranked = rankByFuzzy(tied, "abc", (r) => r.label);
280
- expect(ranked.map((r) => r.item.id)).toEqual([10, 11, 12]);
281
- });
282
-
283
- it("does not mutate the input array or its items", () => {
284
- const input: Row[] = [
285
- { id: 1, label: "foobar" },
286
- { id: 2, label: "barbaz" },
287
- ];
288
- const snapshot = JSON.parse(JSON.stringify(input));
289
- rankByFuzzy(input, "bar", (r) => r.label);
290
- expect(input).toEqual(snapshot);
291
- expect(input.length).toBe(2);
292
- });
293
-
294
- it("respects caseInsensitive option", () => {
295
- const list = [{ id: 1, label: "foobar" }];
296
- // Query 'fB' has an uppercase → smart-case makes it case-sensitive, so
297
- // 'B' cannot match lowercase 'b' in 'foobar' → filtered out.
298
- expect(rankByFuzzy(list, "fB", (r) => r.label).length).toBe(0);
299
- // With caseInsensitive forced, 'B' folds to 'b' and it matches.
300
- expect(rankByFuzzy(list, "fB", (r) => r.label, { caseInsensitive: true }).length).toBe(1);
301
- });
302
-
303
- it("empty query matches all items with score 0", () => {
304
- const ranked = rankByFuzzy(rows, "", (r) => r.label);
305
- expect(ranked.length).toBe(rows.length);
306
- expect(ranked.every((r) => r.score === 0)).toBe(true);
307
- expect(ranked.every((r) => r.indices.length === 0)).toBe(true);
308
- // stable order preserved
309
- expect(ranked.map((r) => r.item.id)).toEqual([1, 2, 3, 4]);
310
- });
311
- });