@namzu/sdk 71.0.0 → 71.1.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/CHANGELOG.md +100 -0
- package/dist/authorization/readonly-commands.d.ts +9 -1
- package/dist/authorization/readonly-commands.d.ts.map +1 -1
- package/dist/authorization/readonly-commands.js +70 -4
- package/dist/authorization/readonly-commands.js.map +1 -1
- package/dist/authorization/shell-paths.d.ts.map +1 -1
- package/dist/authorization/shell-paths.js +68 -16
- package/dist/authorization/shell-paths.js.map +1 -1
- package/dist/compaction/model-summary.d.ts.map +1 -1
- package/dist/compaction/model-summary.js +44 -5
- package/dist/compaction/model-summary.js.map +1 -1
- package/dist/config/registry.d.ts +2 -0
- package/dist/config/registry.d.ts.map +1 -1
- package/dist/config/registry.js +76 -5
- package/dist/config/registry.js.map +1 -1
- package/dist/connector/mcp/adapter.d.ts +8 -0
- package/dist/connector/mcp/adapter.d.ts.map +1 -1
- package/dist/connector/mcp/adapter.js +131 -1
- package/dist/connector/mcp/adapter.js.map +1 -1
- package/dist/connector/mcp/stdio.d.ts +12 -0
- package/dist/connector/mcp/stdio.d.ts.map +1 -1
- package/dist/connector/mcp/stdio.js +49 -5
- package/dist/connector/mcp/stdio.js.map +1 -1
- package/dist/constants/mcp/index.d.ts +29 -0
- package/dist/constants/mcp/index.d.ts.map +1 -1
- package/dist/constants/mcp/index.js +29 -0
- package/dist/constants/mcp/index.js.map +1 -1
- package/dist/manager/agent/lifecycle.d.ts +18 -1
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +52 -7
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/shell-hook.d.ts +44 -2
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +74 -5
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/public-runtime.d.ts +2 -2
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +1 -1
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-types.d.ts +2 -2
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/query/path-escalation.d.ts.map +1 -1
- package/dist/runtime/query/path-escalation.js +90 -17
- package/dist/runtime/query/path-escalation.js.map +1 -1
- package/dist/runtime/query/steering.d.ts +15 -0
- package/dist/runtime/query/steering.d.ts.map +1 -1
- package/dist/runtime/query/steering.js +27 -3
- package/dist/runtime/query/steering.js.map +1 -1
- package/dist/session/workspace/driver.d.ts +12 -0
- package/dist/session/workspace/driver.d.ts.map +1 -1
- package/dist/session/workspace/git-worktree.d.ts +16 -0
- package/dist/session/workspace/git-worktree.d.ts.map +1 -1
- package/dist/session/workspace/git-worktree.js +35 -0
- package/dist/session/workspace/git-worktree.js.map +1 -1
- package/dist/session/workspace/holds.d.ts +78 -0
- package/dist/session/workspace/holds.d.ts.map +1 -0
- package/dist/session/workspace/holds.js +150 -0
- package/dist/session/workspace/holds.js.map +1 -0
- package/dist/session/workspace/index.d.ts +3 -1
- package/dist/session/workspace/index.d.ts.map +1 -1
- package/dist/session/workspace/index.js +2 -1
- package/dist/session/workspace/index.js.map +1 -1
- package/dist/store/config/index.d.ts +3 -0
- package/dist/store/config/index.d.ts.map +1 -1
- package/dist/store/config/index.js +3 -0
- package/dist/store/config/index.js.map +1 -1
- package/dist/store/session-index/index.d.ts +5 -0
- package/dist/store/session-index/index.d.ts.map +1 -1
- package/dist/store/session-index/index.js +5 -1
- package/dist/store/session-index/index.js.map +1 -1
- package/dist/store/session-index/rebuild.d.ts +18 -0
- package/dist/store/session-index/rebuild.d.ts.map +1 -1
- package/dist/store/session-index/rebuild.js +79 -5
- package/dist/store/session-index/rebuild.js.map +1 -1
- package/dist/store/session-index/sqlite.d.ts +8 -0
- package/dist/store/session-index/sqlite.d.ts.map +1 -1
- package/dist/store/session-index/sqlite.js +23 -1
- package/dist/store/session-index/sqlite.js.map +1 -1
- package/dist/tools/builtins/grep.d.ts.map +1 -1
- package/dist/tools/builtins/grep.js +57 -0
- package/dist/tools/builtins/grep.js.map +1 -1
- package/dist/tools/builtins/lsp.d.ts.map +1 -1
- package/dist/tools/builtins/lsp.js +41 -4
- package/dist/tools/builtins/lsp.js.map +1 -1
- package/dist/types/code-navigation/index.d.ts +34 -4
- package/dist/types/code-navigation/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/authorization/readonly-commands.ts +72 -4
- package/src/authorization/shell-paths.ts +75 -18
- package/src/compaction/model-summary.ts +45 -5
- package/src/config/registry.ts +87 -5
- package/src/connector/mcp/adapter.ts +137 -1
- package/src/connector/mcp/stdio.ts +56 -5
- package/src/constants/mcp/index.ts +31 -0
- package/src/manager/agent/lifecycle.ts +57 -12
- package/src/plugin/index.ts +3 -0
- package/src/plugin/shell-hook.ts +131 -6
- package/src/public-runtime.ts +5 -0
- package/src/public-types.ts +7 -0
- package/src/runtime/query/path-escalation.ts +102 -16
- package/src/runtime/query/steering.ts +38 -3
- package/src/session/workspace/driver.ts +12 -0
- package/src/session/workspace/git-worktree.ts +49 -0
- package/src/session/workspace/holds.ts +201 -0
- package/src/session/workspace/index.ts +13 -1
- package/src/store/config/index.ts +6 -0
- package/src/store/session-index/index.ts +10 -1
- package/src/store/session-index/rebuild.ts +81 -5
- package/src/store/session-index/sqlite.ts +30 -1
- package/src/tools/builtins/grep.ts +52 -0
- package/src/tools/builtins/lsp.ts +47 -4
- package/src/types/code-navigation/index.ts +48 -4
|
@@ -657,6 +657,10 @@ export const GrepTool = defineTool({
|
|
|
657
657
|
if ((endState?.ignoredDirectories ?? 0) > 0 && offset === 0) {
|
|
658
658
|
summary = `${summary}\n${ignoredHint(endState?.ignoredDirectories ?? 0)}`
|
|
659
659
|
}
|
|
660
|
+
// An empty result a line break in the pattern forced is not evidence that
|
|
661
|
+
// the text is absent, so the pattern is named rather than left to read so.
|
|
662
|
+
const breakHint = totalMatches === 0 ? lineBreakHint(input.pattern, multiline) : undefined
|
|
663
|
+
if (breakHint !== undefined) summary = `${summary}\n${breakHint}`
|
|
660
664
|
} else if (mode === 'files_with_matches') {
|
|
661
665
|
body = `Found ${page.length} ${page.length === 1 ? 'file' : 'files'}${paging ? ` (${paging})` : ''}\n${page.join('\n')}`
|
|
662
666
|
} else if (mode === 'count') {
|
|
@@ -721,6 +725,54 @@ function byPath(a: string, b: string): number {
|
|
|
721
725
|
return a < b ? -1 : a > b ? 1 : 0
|
|
722
726
|
}
|
|
723
727
|
|
|
728
|
+
/**
|
|
729
|
+
* Whether a pattern is written to match a line break: one in the pattern
|
|
730
|
+
* itself, or an escape that names one, `\n` and `\r` among them. A pattern
|
|
731
|
+
* like that cannot be found inside a single line, and every line is tested on
|
|
732
|
+
* its own while `multiline` is off.
|
|
733
|
+
*/
|
|
734
|
+
function patternNeedsLineBreak(pattern: string): boolean {
|
|
735
|
+
for (let index = 0; index < pattern.length; index += 1) {
|
|
736
|
+
const char = pattern[index]
|
|
737
|
+
if (char === '\n' || char === '\r' || char === '\u2028' || char === '\u2029') return true
|
|
738
|
+
if (char === '[' && pattern[index + 1] === '^') {
|
|
739
|
+
// A negated class such as `[^\n]` excludes a line break; it does not ask for one.
|
|
740
|
+
index = skipNegatedClass(pattern, index + 2)
|
|
741
|
+
continue
|
|
742
|
+
}
|
|
743
|
+
if (char !== '\\') continue
|
|
744
|
+
const next = pattern[index + 1]
|
|
745
|
+
// An escaped backslash and the `n` after it are a literal `\n` in the
|
|
746
|
+
// text being searched, so the two are stepped over together.
|
|
747
|
+
if (next === '\\') {
|
|
748
|
+
index += 1
|
|
749
|
+
continue
|
|
750
|
+
}
|
|
751
|
+
if (next === 'n' || next === 'r') return true
|
|
752
|
+
if (next === 'u' && ['2028', '2029'].includes(pattern.slice(index + 2, index + 6))) return true
|
|
753
|
+
}
|
|
754
|
+
return false
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/** The index of the `]` that closes a negated class whose body starts at `from`, or the end of the pattern. */
|
|
758
|
+
function skipNegatedClass(pattern: string, from: number): number {
|
|
759
|
+
for (let index = from; index < pattern.length; index += 1) {
|
|
760
|
+
if (pattern[index] === '\\') index += 1
|
|
761
|
+
else if (pattern[index] === ']') return index
|
|
762
|
+
}
|
|
763
|
+
return pattern.length
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* A sentence for the emptiest of evidence: a pattern that needs a line break,
|
|
768
|
+
* searched one line at a time, can only come back with nothing. Naming the
|
|
769
|
+
* pattern and the flag that changes that is worth more than "no matches".
|
|
770
|
+
*/
|
|
771
|
+
function lineBreakHint(pattern: string, multiline: boolean): string | undefined {
|
|
772
|
+
if (multiline || !patternNeedsLineBreak(pattern)) return undefined
|
|
773
|
+
return `The pattern ${JSON.stringify(pattern)} contains a line break, and multiline is off: each line is tested on its own, so a match that spans lines cannot be found. Pass multiline: true to search across lines.`
|
|
774
|
+
}
|
|
775
|
+
|
|
724
776
|
/**
|
|
725
777
|
* Newest modification first; ties by path. A file that cannot be stat'ed, and
|
|
726
778
|
* every file in a sandbox (which reports no modification time), sorts as
|
|
@@ -110,8 +110,22 @@ export const LspTool = defineTool({
|
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
// Checked before anything is spawned. A turn that was stopped must not
|
|
114
|
+
// pay for starting a language server, and the server must not be asked a
|
|
115
|
+
// question whose answer nobody will read.
|
|
116
|
+
if (context.abortSignal?.aborted) {
|
|
117
|
+
return interruptedResult(
|
|
118
|
+
input.operation,
|
|
119
|
+
'The turn was stopped before the language server was asked.',
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
// The turn's own signal, so Esc reaches the request instead of leaving it
|
|
123
|
+
// to the provider's deadline: a server that is still indexing would hold
|
|
124
|
+
// the turn open with nothing able to end it.
|
|
125
|
+
const options = { signal: context.abortSignal }
|
|
126
|
+
|
|
113
127
|
if (input.operation === 'symbols') {
|
|
114
|
-
const result = await provider.symbols(input.query, absolute)
|
|
128
|
+
const result = await provider.symbols(input.query, absolute, options)
|
|
115
129
|
switch (result.kind) {
|
|
116
130
|
case 'symbols': {
|
|
117
131
|
if (result.symbols.length === 0) {
|
|
@@ -133,11 +147,13 @@ export const LspTool = defineTool({
|
|
|
133
147
|
return { success: false, output: '', error: unsupportedMessage(result.reason) }
|
|
134
148
|
case 'failed':
|
|
135
149
|
return { success: false, output: '', error: failedMessage(result.error) }
|
|
150
|
+
case 'interrupted':
|
|
151
|
+
return interruptedResult('symbols', result.reason)
|
|
136
152
|
}
|
|
137
153
|
}
|
|
138
154
|
|
|
139
155
|
if (input.operation === 'hover') {
|
|
140
|
-
const result = await provider.hover(absolute as string, input.line, input.character)
|
|
156
|
+
const result = await provider.hover(absolute as string, input.line, input.character, options)
|
|
141
157
|
switch (result.kind) {
|
|
142
158
|
case 'hover':
|
|
143
159
|
return {
|
|
@@ -154,13 +170,15 @@ export const LspTool = defineTool({
|
|
|
154
170
|
return { success: false, output: '', error: unsupportedMessage(result.reason) }
|
|
155
171
|
case 'failed':
|
|
156
172
|
return { success: false, output: '', error: failedMessage(result.error) }
|
|
173
|
+
case 'interrupted':
|
|
174
|
+
return interruptedResult('hover', result.reason)
|
|
157
175
|
}
|
|
158
176
|
}
|
|
159
177
|
|
|
160
178
|
const result =
|
|
161
179
|
input.operation === 'definition'
|
|
162
|
-
? await provider.definition(absolute as string, input.line, input.character)
|
|
163
|
-
: await provider.references(absolute as string, input.line, input.character)
|
|
180
|
+
? await provider.definition(absolute as string, input.line, input.character, options)
|
|
181
|
+
: await provider.references(absolute as string, input.line, input.character, options)
|
|
164
182
|
|
|
165
183
|
switch (result.kind) {
|
|
166
184
|
case 'locations': {
|
|
@@ -189,6 +207,8 @@ export const LspTool = defineTool({
|
|
|
189
207
|
return { success: false, output: '', error: unsupportedMessage(result.reason) }
|
|
190
208
|
case 'failed':
|
|
191
209
|
return { success: false, output: '', error: failedMessage(result.error) }
|
|
210
|
+
case 'interrupted':
|
|
211
|
+
return interruptedResult(input.operation, result.reason)
|
|
192
212
|
}
|
|
193
213
|
},
|
|
194
214
|
})
|
|
@@ -203,6 +223,29 @@ function failedMessage(error: string): string {
|
|
|
203
223
|
return `Code navigation failed, so this answer is unknown rather than empty: ${error}`
|
|
204
224
|
}
|
|
205
225
|
|
|
226
|
+
/**
|
|
227
|
+
* An answer nobody finished asking for.
|
|
228
|
+
*
|
|
229
|
+
* The ordinary end of a call the person stopped, and the one case that must
|
|
230
|
+
* not read as a broken server: the next move is to ask again, not to fall
|
|
231
|
+
* back to `grep` or to conclude the symbol has no callers. It says "unknown
|
|
232
|
+
* rather than empty" for the same reason a failure does — a model acts on the
|
|
233
|
+
* absence of an answer.
|
|
234
|
+
*/
|
|
235
|
+
function interruptedMessage(reason: string): string {
|
|
236
|
+
return `The call was interrupted before the language server answered, so this answer is unknown rather than empty: ${reason} Ask again if the answer is still needed.`
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Structured as well as worded, because a host renders a stopped call differently. */
|
|
240
|
+
function interruptedResult(operation: LspInput['operation'], reason: string): ToolResult {
|
|
241
|
+
return {
|
|
242
|
+
success: false,
|
|
243
|
+
output: '',
|
|
244
|
+
error: interruptedMessage(reason),
|
|
245
|
+
data: { operation, interrupted: true },
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
206
249
|
/**
|
|
207
250
|
* The tool, only when there is something for it to call.
|
|
208
251
|
*
|
|
@@ -36,11 +36,19 @@ export interface SourceLocation {
|
|
|
36
36
|
* looked, and there are none", which is a real answer and the one a
|
|
37
37
|
* deletion depends on; conflating it with a failure is how an agent
|
|
38
38
|
* concludes a symbol has no callers because the server never started.
|
|
39
|
+
*
|
|
40
|
+
* `interrupted` is the fourth case and it is neither of the other two: the
|
|
41
|
+
* caller aborted the request (the turn was stopped) before the server
|
|
42
|
+
* answered, so nobody finished asking. Reporting that as `failed` says the
|
|
43
|
+
* resolver broke, which is false and invites a retry against a server that
|
|
44
|
+
* is fine; reporting it as an empty list says the symbol has no callers,
|
|
45
|
+
* which is how a deletion gets made on an answer nobody gave.
|
|
39
46
|
*/
|
|
40
47
|
export type CodeNavigationResult =
|
|
41
48
|
| { readonly kind: 'locations'; readonly locations: readonly SourceLocation[] }
|
|
42
49
|
| { readonly kind: 'unsupported'; readonly reason: string }
|
|
43
50
|
| { readonly kind: 'failed'; readonly error: string }
|
|
51
|
+
| { readonly kind: 'interrupted'; readonly reason: string }
|
|
44
52
|
|
|
45
53
|
/** A symbol found by name rather than by position. */
|
|
46
54
|
export interface SymbolLocation extends SourceLocation {
|
|
@@ -63,19 +71,51 @@ export type HoverResult =
|
|
|
63
71
|
| { readonly kind: 'hover'; readonly contents: string }
|
|
64
72
|
| { readonly kind: 'unsupported'; readonly reason: string }
|
|
65
73
|
| { readonly kind: 'failed'; readonly error: string }
|
|
74
|
+
| { readonly kind: 'interrupted'; readonly reason: string }
|
|
66
75
|
|
|
67
76
|
export type SymbolSearchResult =
|
|
68
77
|
| { readonly kind: 'symbols'; readonly symbols: readonly SymbolLocation[] }
|
|
69
78
|
| { readonly kind: 'unsupported'; readonly reason: string }
|
|
70
79
|
| { readonly kind: 'failed'; readonly error: string }
|
|
80
|
+
| { readonly kind: 'interrupted'; readonly reason: string }
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Per-call control, passed alongside a request.
|
|
84
|
+
*
|
|
85
|
+
* `signal` is the turn's abort signal, so a Stop ends the request instead of
|
|
86
|
+
* leaving it to the provider's own deadline: a language server that is still
|
|
87
|
+
* indexing, wedged, or waiting on a binary that never became ready would
|
|
88
|
+
* otherwise hold the turn open with nothing able to end it. A provider that
|
|
89
|
+
* receives an aborted signal answers `interrupted` — never `failed`, and
|
|
90
|
+
* never an empty result — because the answer is unknown for a reason that
|
|
91
|
+
* says nothing about the server.
|
|
92
|
+
*/
|
|
93
|
+
export interface CodeNavigationRequestOptions {
|
|
94
|
+
readonly signal?: AbortSignal
|
|
95
|
+
}
|
|
71
96
|
|
|
72
97
|
export interface CodeNavigationProvider {
|
|
73
98
|
/** Where the symbol under this position is declared. */
|
|
74
|
-
definition(
|
|
99
|
+
definition(
|
|
100
|
+
file: string,
|
|
101
|
+
line: number,
|
|
102
|
+
character: number,
|
|
103
|
+
options?: CodeNavigationRequestOptions,
|
|
104
|
+
): Promise<CodeNavigationResult>
|
|
75
105
|
/** Everywhere the symbol under this position is used. */
|
|
76
|
-
references(
|
|
106
|
+
references(
|
|
107
|
+
file: string,
|
|
108
|
+
line: number,
|
|
109
|
+
character: number,
|
|
110
|
+
options?: CodeNavigationRequestOptions,
|
|
111
|
+
): Promise<CodeNavigationResult>
|
|
77
112
|
/** The symbol's type and documentation, without opening the file. */
|
|
78
|
-
hover(
|
|
113
|
+
hover(
|
|
114
|
+
file: string,
|
|
115
|
+
line: number,
|
|
116
|
+
character: number,
|
|
117
|
+
options?: CodeNavigationRequestOptions,
|
|
118
|
+
): Promise<HoverResult>
|
|
79
119
|
/**
|
|
80
120
|
* Find a declaration by NAME, with no position.
|
|
81
121
|
*
|
|
@@ -88,7 +128,11 @@ export interface CodeNavigationProvider {
|
|
|
88
128
|
* `scope` is a file path or an extension that picks which language's
|
|
89
129
|
* server answers. Absent means every configured language.
|
|
90
130
|
*/
|
|
91
|
-
symbols(
|
|
131
|
+
symbols(
|
|
132
|
+
query: string,
|
|
133
|
+
scope?: string,
|
|
134
|
+
options?: CodeNavigationRequestOptions,
|
|
135
|
+
): Promise<SymbolSearchResult>
|
|
92
136
|
/**
|
|
93
137
|
* Stop whatever backs it.
|
|
94
138
|
*
|