@namzu/sdk 71.1.0 → 72.0.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 +32 -0
- package/dist/agents/QueryAgent.d.ts.map +1 -1
- package/dist/agents/QueryAgent.js +1 -0
- package/dist/agents/QueryAgent.js.map +1 -1
- package/dist/compaction/index.d.ts +1 -1
- package/dist/compaction/index.d.ts.map +1 -1
- package/dist/compaction/index.js +1 -1
- package/dist/compaction/index.js.map +1 -1
- package/dist/compaction/manual.d.ts +8 -0
- package/dist/compaction/manual.d.ts.map +1 -1
- package/dist/compaction/manual.js +18 -14
- package/dist/compaction/manual.js.map +1 -1
- package/dist/compaction/model-summary.d.ts +24 -6
- package/dist/compaction/model-summary.d.ts.map +1 -1
- package/dist/compaction/model-summary.js +108 -23
- package/dist/compaction/model-summary.js.map +1 -1
- package/dist/compaction/restore.d.ts +23 -0
- package/dist/compaction/restore.d.ts.map +1 -1
- package/dist/compaction/restore.js +59 -1
- package/dist/compaction/restore.js.map +1 -1
- package/dist/compaction/summary.d.ts +37 -2
- package/dist/compaction/summary.d.ts.map +1 -1
- package/dist/compaction/summary.js +46 -6
- package/dist/compaction/summary.js.map +1 -1
- package/dist/config/runtime.js +3 -3
- package/dist/config/runtime.js.map +1 -1
- package/dist/connector/index.d.ts +2 -2
- package/dist/connector/index.d.ts.map +1 -1
- package/dist/connector/index.js +1 -1
- package/dist/connector/index.js.map +1 -1
- package/dist/connector/mcp/client.d.ts +26 -6
- package/dist/connector/mcp/client.d.ts.map +1 -1
- package/dist/connector/mcp/client.js +49 -7
- package/dist/connector/mcp/client.js.map +1 -1
- package/dist/connector/mcp/index.d.ts +2 -0
- package/dist/connector/mcp/index.d.ts.map +1 -1
- package/dist/connector/mcp/index.js +1 -0
- package/dist/connector/mcp/index.js.map +1 -1
- package/dist/connector/mcp/sandbox-stdio.d.ts +67 -0
- package/dist/connector/mcp/sandbox-stdio.d.ts.map +1 -0
- package/dist/connector/mcp/sandbox-stdio.js +178 -0
- package/dist/connector/mcp/sandbox-stdio.js.map +1 -0
- package/dist/connector/mcp/stdio-program.d.ts +34 -0
- package/dist/connector/mcp/stdio-program.d.ts.map +1 -0
- package/dist/connector/mcp/stdio-program.js +47 -0
- package/dist/connector/mcp/stdio-program.js.map +1 -0
- package/dist/connector/mcp/stdio.d.ts.map +1 -1
- package/dist/connector/mcp/stdio.js +5 -2
- package/dist/connector/mcp/stdio.js.map +1 -1
- package/dist/connector/web/guarded-fetch.d.ts +51 -2
- package/dist/connector/web/guarded-fetch.d.ts.map +1 -1
- package/dist/connector/web/guarded-fetch.js +140 -19
- package/dist/connector/web/guarded-fetch.js.map +1 -1
- package/dist/connector/web/index.d.ts +2 -2
- package/dist/connector/web/index.d.ts.map +1 -1
- package/dist/connector/web/index.js +1 -1
- package/dist/connector/web/index.js.map +1 -1
- package/dist/manager/agent/lifecycle.js +1 -1
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/plugin/hook-module/capabilities.d.ts.map +1 -1
- package/dist/plugin/hook-module/capabilities.js +24 -13
- package/dist/plugin/hook-module/capabilities.js.map +1 -1
- package/dist/plugin/hook-module/host.d.ts +31 -0
- package/dist/plugin/hook-module/host.d.ts.map +1 -1
- package/dist/plugin/hook-module/host.js +56 -13
- package/dist/plugin/hook-module/host.js.map +1 -1
- package/dist/plugin/hook-module/index.d.ts +3 -2
- package/dist/plugin/hook-module/index.d.ts.map +1 -1
- package/dist/plugin/hook-module/index.js +2 -1
- package/dist/plugin/hook-module/index.js.map +1 -1
- package/dist/plugin/index.d.ts +1 -0
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +1 -0
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/shell-hook-execute.d.ts +55 -0
- package/dist/plugin/shell-hook-execute.d.ts.map +1 -0
- package/dist/plugin/shell-hook-execute.js +73 -0
- package/dist/plugin/shell-hook-execute.js.map +1 -0
- package/dist/plugin/shell-hook-restrict.d.ts +31 -0
- package/dist/plugin/shell-hook-restrict.d.ts.map +1 -0
- package/dist/plugin/shell-hook-restrict.js +69 -0
- package/dist/plugin/shell-hook-restrict.js.map +1 -0
- package/dist/plugin/shell-hook.d.ts +29 -2
- package/dist/plugin/shell-hook.d.ts.map +1 -1
- package/dist/plugin/shell-hook.js +44 -12
- package/dist/plugin/shell-hook.js.map +1 -1
- package/dist/public-runtime.d.ts +7 -5
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +5 -4
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-types.d.ts +2 -0
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/jobs/websocket-source.d.ts +2 -22
- package/dist/runtime/jobs/websocket-source.d.ts.map +1 -1
- package/dist/runtime/jobs/websocket-source.js +2 -33
- package/dist/runtime/jobs/websocket-source.js.map +1 -1
- package/dist/runtime/query/compact-session.d.ts.map +1 -1
- package/dist/runtime/query/compact-session.js +5 -0
- package/dist/runtime/query/compact-session.js.map +1 -1
- package/dist/runtime/query/events.d.ts +7 -0
- package/dist/runtime/query/events.d.ts.map +1 -1
- package/dist/runtime/query/events.js +29 -11
- package/dist/runtime/query/events.js.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.d.ts.map +1 -1
- package/dist/runtime/query/executor/tool-call-admission.js +51 -10
- package/dist/runtime/query/executor/tool-call-admission.js.map +1 -1
- package/dist/runtime/query/index.d.ts +6 -0
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +3 -0
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/compaction.js +21 -3
- package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
- package/dist/runtime/query/iteration/phases/context.d.ts +4 -0
- package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/context.js.map +1 -1
- package/dist/scheduler/completion-inbox.d.ts.map +1 -1
- package/dist/scheduler/completion-inbox.js +15 -0
- package/dist/scheduler/completion-inbox.js.map +1 -1
- package/dist/store/session-index/index.d.ts +13 -0
- package/dist/store/session-index/index.d.ts.map +1 -1
- package/dist/store/session-index/index.js +1 -0
- package/dist/store/session-index/index.js.map +1 -1
- package/dist/store/session-index/rebuild.d.ts +12 -0
- package/dist/store/session-index/rebuild.d.ts.map +1 -1
- package/dist/store/session-index/rebuild.js +20 -4
- package/dist/store/session-index/rebuild.js.map +1 -1
- package/dist/store/session-index/sqlite.d.ts +20 -0
- package/dist/store/session-index/sqlite.d.ts.map +1 -1
- package/dist/store/session-index/sqlite.js +50 -12
- package/dist/store/session-index/sqlite.js.map +1 -1
- package/dist/tools/admit-facts.d.ts.map +1 -1
- package/dist/tools/admit-facts.js +59 -0
- package/dist/tools/admit-facts.js.map +1 -1
- package/dist/tools/coordinator/ask-user-question.d.ts.map +1 -1
- package/dist/tools/coordinator/ask-user-question.js +67 -3
- package/dist/tools/coordinator/ask-user-question.js.map +1 -1
- package/dist/turn/memory-promoter.d.ts.map +1 -1
- package/dist/turn/memory-promoter.js +20 -4
- package/dist/turn/memory-promoter.js.map +1 -1
- package/dist/types/agent/base.d.ts +6 -0
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/task.d.ts +5 -0
- package/dist/types/agent/task.d.ts.map +1 -1
- package/dist/types/agent/task.js.map +1 -1
- package/dist/types/hitl/index.d.ts +8 -0
- package/dist/types/hitl/index.d.ts.map +1 -1
- package/dist/types/hitl/index.js.map +1 -1
- package/dist/types/message/index.d.ts +7 -0
- package/dist/types/message/index.d.ts.map +1 -1
- package/dist/types/message/index.js.map +1 -1
- package/dist/types/tool/presentation.d.ts +21 -0
- package/dist/types/tool/presentation.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/agents/QueryAgent.ts +1 -0
- package/src/compaction/index.ts +1 -0
- package/src/compaction/manual.ts +48 -12
- package/src/compaction/model-summary.ts +118 -23
- package/src/compaction/restore.ts +74 -1
- package/src/compaction/summary.ts +69 -3
- package/src/config/runtime.ts +3 -3
- package/src/connector/index.ts +3 -0
- package/src/connector/mcp/client.ts +49 -7
- package/src/connector/mcp/index.ts +5 -0
- package/src/connector/mcp/sandbox-stdio.ts +214 -0
- package/src/connector/mcp/stdio-program.ts +68 -0
- package/src/connector/mcp/stdio.ts +5 -2
- package/src/connector/web/guarded-fetch.ts +197 -30
- package/src/connector/web/index.ts +4 -1
- package/src/manager/agent/lifecycle.ts +1 -1
- package/src/plugin/hook-module/capabilities.ts +36 -14
- package/src/plugin/hook-module/host.ts +86 -13
- package/src/plugin/hook-module/index.ts +3 -0
- package/src/plugin/index.ts +1 -0
- package/src/plugin/shell-hook-execute.ts +126 -0
- package/src/plugin/shell-hook-restrict.ts +66 -0
- package/src/plugin/shell-hook.ts +78 -10
- package/src/public-runtime.ts +14 -0
- package/src/public-types.ts +13 -0
- package/src/runtime/jobs/websocket-source.ts +2 -46
- package/src/runtime/query/compact-session.ts +5 -0
- package/src/runtime/query/events.ts +29 -11
- package/src/runtime/query/executor/tool-call-admission.ts +62 -17
- package/src/runtime/query/index.ts +10 -0
- package/src/runtime/query/iteration/phases/compaction.ts +26 -2
- package/src/runtime/query/iteration/phases/context.ts +6 -0
- package/src/scheduler/completion-inbox.ts +14 -0
- package/src/store/session-index/index.ts +14 -0
- package/src/store/session-index/rebuild.ts +22 -4
- package/src/store/session-index/sqlite.ts +63 -14
- package/src/tools/admit-facts.ts +64 -0
- package/src/tools/coordinator/ask-user-question.ts +88 -4
- package/src/turn/memory-promoter.ts +24 -3
- package/src/types/agent/base.ts +7 -0
- package/src/types/agent/task.ts +5 -0
- package/src/types/hitl/index.ts +8 -0
- package/src/types/message/index.ts +7 -0
- package/src/types/tool/presentation.ts +22 -0
package/src/public-runtime.ts
CHANGED
|
@@ -344,6 +344,7 @@ export {
|
|
|
344
344
|
withFileLock,
|
|
345
345
|
withFileLockSync,
|
|
346
346
|
} from './utils/file-lock.js'
|
|
347
|
+
export { temporaryPathFor } from './utils/atomic-write.js'
|
|
347
348
|
export {
|
|
348
349
|
STATE_BACKUPS_DIR,
|
|
349
350
|
STATE_BACKUP_KEEP,
|
|
@@ -875,6 +876,11 @@ export {
|
|
|
875
876
|
scanHookModule,
|
|
876
877
|
startHookModule,
|
|
877
878
|
summarizeHookModule,
|
|
879
|
+
HOOK_WORKER_SOURCE,
|
|
880
|
+
HOST_REACHING_CAPABILITIES,
|
|
881
|
+
createCapabilityBridge,
|
|
882
|
+
workerTransport,
|
|
883
|
+
restrictHookVerdict,
|
|
878
884
|
} from './plugin/index.js'
|
|
879
885
|
export type {
|
|
880
886
|
CommonLayoutOptions,
|
|
@@ -1142,6 +1148,7 @@ export {
|
|
|
1142
1148
|
// The only transport in the tree that can RUN an `MCPServer`. It reached
|
|
1143
1149
|
// `connector/mcp/index.ts` and stopped there, so the server was public
|
|
1144
1150
|
// with no public way to serve it.
|
|
1151
|
+
SandboxStdioTransport,
|
|
1145
1152
|
ServerStdioTransport,
|
|
1146
1153
|
StdioTransport,
|
|
1147
1154
|
StreamableHttpTransport,
|
|
@@ -1167,6 +1174,8 @@ export type {
|
|
|
1167
1174
|
McpSkillsClient,
|
|
1168
1175
|
McpSkillsRefresh,
|
|
1169
1176
|
McpSkillsRefreshStatus,
|
|
1177
|
+
SandboxStdioReplyVerdict,
|
|
1178
|
+
SandboxStdioTransportOptions,
|
|
1170
1179
|
McpEnvelope,
|
|
1171
1180
|
McpEnvelopeInput,
|
|
1172
1181
|
McpEraProbe,
|
|
@@ -1580,6 +1589,7 @@ export {
|
|
|
1580
1589
|
COMPACTION_HEADER,
|
|
1581
1590
|
COMPACTION_RECOVERY_NOTE,
|
|
1582
1591
|
COMPACTION_RESUME_NOTE,
|
|
1592
|
+
COMPACTION_RESUME_NOTE_MAY_ASK,
|
|
1583
1593
|
isCompactionMessage,
|
|
1584
1594
|
} from './compaction/summary.js'
|
|
1585
1595
|
export {
|
|
@@ -1896,10 +1906,14 @@ export {
|
|
|
1896
1906
|
export {
|
|
1897
1907
|
GuardedFetchProvider,
|
|
1898
1908
|
WebFetchRefusedError,
|
|
1909
|
+
checkedAddresses,
|
|
1899
1910
|
isPrivateAddress,
|
|
1911
|
+
pinnedFetch,
|
|
1912
|
+
pinnedLookup,
|
|
1900
1913
|
privateAddressProblem,
|
|
1901
1914
|
proxyConfigured,
|
|
1902
1915
|
} from './connector/web/index.js'
|
|
1916
|
+
export type { AddressCheckOptions, PinnedRequest } from './connector/web/index.js'
|
|
1903
1917
|
|
|
1904
1918
|
// Where an attachment's bytes live when the message does not carry them.
|
|
1905
1919
|
// Inline base64 lands in the transcript, in every checkpoint, and on the
|
package/src/public-types.ts
CHANGED
|
@@ -260,6 +260,19 @@ export type {
|
|
|
260
260
|
ShellHooksConfig,
|
|
261
261
|
} from './plugin/shell-hook.js'
|
|
262
262
|
export type { ShellHookToolNames } from './plugin/shell-hook-tool-names.js'
|
|
263
|
+
export type {
|
|
264
|
+
ShellHookExecRequest,
|
|
265
|
+
ShellHookExecResult,
|
|
266
|
+
ShellHookExecutor,
|
|
267
|
+
} from './plugin/shell-hook-execute.js'
|
|
268
|
+
export type {
|
|
269
|
+
CapabilityBridge,
|
|
270
|
+
CapabilityBridgeOptions,
|
|
271
|
+
HookModuleCapability,
|
|
272
|
+
HookModuleClock,
|
|
273
|
+
HookModuleTransport,
|
|
274
|
+
HookModuleTransportFactory,
|
|
275
|
+
} from './plugin/hook-module/index.js'
|
|
263
276
|
export type { HookEnvEvent, SessionHookEnvOptions } from './plugin/session-hook-env.js'
|
|
264
277
|
export type {
|
|
265
278
|
FileChange,
|
|
@@ -4,7 +4,7 @@ import { isIP } from 'node:net'
|
|
|
4
4
|
|
|
5
5
|
import type { WebSocket as WebSocketClient } from 'ws'
|
|
6
6
|
|
|
7
|
-
import { isPrivateAddress } from '../../connector/web/guarded-fetch.js'
|
|
7
|
+
import { isPrivateAddress, pinnedLookup } from '../../connector/web/guarded-fetch.js'
|
|
8
8
|
import { isolationOf } from '../../sandbox/isolation.js'
|
|
9
9
|
import type { Sandbox } from '../../types/sandbox/index.js'
|
|
10
10
|
import type { MonitorWebSocketTarget } from '../../types/tool/index.js'
|
|
@@ -170,51 +170,7 @@ export async function vetWebSocketTarget(
|
|
|
170
170
|
return addresses.map((address) => ({ address, family: isIP(address) === 6 ? 6 : 4 }))
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
|
|
174
|
-
* A `lookup` for the socket that answers with the addresses that were checked
|
|
175
|
-
* and nothing else.
|
|
176
|
-
*
|
|
177
|
-
* This is what closes the gap `web_fetch` documents: there the address is
|
|
178
|
-
* checked, then the platform `fetch` resolves the name AGAIN, so a name that
|
|
179
|
-
* answers publicly the first time and privately the second (DNS rebinding)
|
|
180
|
-
* gets through. Here the connection never asks DNS: it is handed the checked
|
|
181
|
-
* addresses, so there is no second answer to differ. The URL still names the
|
|
182
|
-
* host, so TLS keeps its SNI and its certificate check on the hostname and not
|
|
183
|
-
* on an address.
|
|
184
|
-
*/
|
|
185
|
-
export function pinnedLookup(
|
|
186
|
-
addresses: readonly { readonly address: string; readonly family: 4 | 6 }[],
|
|
187
|
-
) {
|
|
188
|
-
return (
|
|
189
|
-
_hostname: string,
|
|
190
|
-
options: { all?: boolean; family?: number | string } | undefined,
|
|
191
|
-
callback: (
|
|
192
|
-
error: NodeJS.ErrnoException | null,
|
|
193
|
-
address: string | { address: string; family: number }[],
|
|
194
|
-
family?: number,
|
|
195
|
-
) => void,
|
|
196
|
-
): void => {
|
|
197
|
-
// A caller that wants one family gets that family's addresses; asking for
|
|
198
|
-
// one we hold none of is an error rather than a fall back to DNS.
|
|
199
|
-
const wanted = options?.family === 4 || options?.family === 6 ? options.family : undefined
|
|
200
|
-
const usable = wanted === undefined ? addresses : addresses.filter((a) => a.family === wanted)
|
|
201
|
-
const first = usable[0]
|
|
202
|
-
if (first === undefined) {
|
|
203
|
-
const error: NodeJS.ErrnoException = new Error('no vetted address of that family')
|
|
204
|
-
error.code = 'ENOTFOUND'
|
|
205
|
-
callback(error, '', 0)
|
|
206
|
-
return
|
|
207
|
-
}
|
|
208
|
-
if (options?.all === true) {
|
|
209
|
-
callback(
|
|
210
|
-
null,
|
|
211
|
-
usable.map((a) => ({ address: a.address, family: a.family })),
|
|
212
|
-
)
|
|
213
|
-
return
|
|
214
|
-
}
|
|
215
|
-
callback(null, first.address, first.family)
|
|
216
|
-
}
|
|
217
|
-
}
|
|
173
|
+
export { pinnedLookup }
|
|
218
174
|
|
|
219
175
|
/** `api.example.com` is that host; `.example.com` is the domain and its subdomains. */
|
|
220
176
|
export function hostMatchesPolicy(hostname: string, allowedHosts: readonly string[]): boolean {
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
compactRegion,
|
|
7
7
|
} from '../../compaction/manual.js'
|
|
8
8
|
import { readFoldedHistory } from '../../manager/session/turn-recorder.js'
|
|
9
|
+
import { DiskSessionLog } from '../../store/session-log/index.js'
|
|
9
10
|
import { NamzuError } from '../../types/errors/index.js'
|
|
10
11
|
import type { MessageId, SessionId } from '../../types/ids/index.js'
|
|
11
12
|
import type { Message } from '../../types/message/index.js'
|
|
@@ -55,6 +56,8 @@ export async function compactSession(
|
|
|
55
56
|
const ids = new Map<Message, MessageId>()
|
|
56
57
|
for (const entry of history) if (entry.messageId) ids.set(entry.message, entry.messageId)
|
|
57
58
|
const result = await compactNow({
|
|
59
|
+
// The session's own file, so the summary says where exact text is stored.
|
|
60
|
+
...(log instanceof DiskSessionLog ? { sessionFile: log.file } : {}),
|
|
58
61
|
...input,
|
|
59
62
|
messages: history.map((entry) => entry.message),
|
|
60
63
|
...(hooks ? { hooks: { ...hooks, sessionId, trigger } } : {}),
|
|
@@ -141,6 +144,8 @@ export async function compactSessionRange(
|
|
|
141
144
|
const ids = new Map<Message, MessageId>()
|
|
142
145
|
for (const entry of history) if (entry.messageId) ids.set(entry.message, entry.messageId)
|
|
143
146
|
const result = await compactRegion({
|
|
147
|
+
// The session's own file, so the summary says where exact text is stored.
|
|
148
|
+
...(log instanceof DiskSessionLog ? { sessionFile: log.file } : {}),
|
|
144
149
|
...input,
|
|
145
150
|
messages: history.map((entry) => entry.message),
|
|
146
151
|
start,
|
|
@@ -13,6 +13,7 @@ import { type SessionEvent, isEphemeralEvent } from '../../types/session/events.
|
|
|
13
13
|
import type { SessionRecord } from '../../types/session/records.js'
|
|
14
14
|
import type { TaskEvent, TaskStore } from '../../types/task/index.js'
|
|
15
15
|
import { awaitWithAbort } from '../../utils/await-with-abort.js'
|
|
16
|
+
import { toErrorMessage } from '../../utils/error.js'
|
|
16
17
|
import { SCOPE_ATTRIBUTE } from '../../utils/log/types.js'
|
|
17
18
|
import { type Logger, resolveLogger } from '../../utils/logger.js'
|
|
18
19
|
|
|
@@ -82,7 +83,7 @@ export class EventTranslator {
|
|
|
82
83
|
recorder.onLogWriteHealth((change) => {
|
|
83
84
|
// Live only: the log is what cannot be written. The listener runs inside
|
|
84
85
|
// a log write, so it must not wait on one.
|
|
85
|
-
void this.
|
|
86
|
+
void this.emitFromStore(
|
|
86
87
|
change.state === 'degraded'
|
|
87
88
|
? {
|
|
88
89
|
type: 'session_log_degraded',
|
|
@@ -262,18 +263,35 @@ export class EventTranslator {
|
|
|
262
263
|
}
|
|
263
264
|
}
|
|
264
265
|
|
|
266
|
+
/**
|
|
267
|
+
* Emit an event a store's listener raised. The stores call their listeners
|
|
268
|
+
* and do not wait on them, so a rejection here would reach no one and stop
|
|
269
|
+
* the process as an unhandled rejection. A failed log write has already been
|
|
270
|
+
* delivered live (see `emitEvent`); the failure itself is reported on the log.
|
|
271
|
+
*/
|
|
272
|
+
private async emitFromStore(draft: SessionEventDraft): Promise<void> {
|
|
273
|
+
try {
|
|
274
|
+
await this.emitEvent(draft)
|
|
275
|
+
} catch (error) {
|
|
276
|
+
this.log.warn('Could not record a session event raised by a store', {
|
|
277
|
+
'namzu.event.type': draft.type,
|
|
278
|
+
'exception.message': toErrorMessage(error),
|
|
279
|
+
})
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
265
283
|
wireActivityStore(activityStore: ActivityStore): void {
|
|
266
284
|
activityStore.on(async (event: ActivityEvent) => {
|
|
267
285
|
const activity = event.activity
|
|
268
286
|
if (event.type === 'activity.created') {
|
|
269
|
-
await this.
|
|
287
|
+
await this.emitFromStore({
|
|
270
288
|
type: 'activity_created',
|
|
271
289
|
activityId: activity.id,
|
|
272
290
|
activityType: activity.type,
|
|
273
291
|
description: activity.description,
|
|
274
292
|
})
|
|
275
293
|
} else {
|
|
276
|
-
await this.
|
|
294
|
+
await this.emitFromStore({
|
|
277
295
|
type: 'activity_updated',
|
|
278
296
|
activityId: activity.id,
|
|
279
297
|
status: activity.status,
|
|
@@ -296,7 +314,7 @@ export class EventTranslator {
|
|
|
296
314
|
if (task.sessionId !== sessionId) return
|
|
297
315
|
switch (event.type) {
|
|
298
316
|
case 'task.created':
|
|
299
|
-
await this.
|
|
317
|
+
await this.emitFromStore({
|
|
300
318
|
type: 'task_created',
|
|
301
319
|
taskId: task.id,
|
|
302
320
|
subject: task.subject,
|
|
@@ -311,7 +329,7 @@ export class EventTranslator {
|
|
|
311
329
|
case 'task.updated':
|
|
312
330
|
case 'task.claimed':
|
|
313
331
|
case 'task.deleted':
|
|
314
|
-
await this.
|
|
332
|
+
await this.emitFromStore({
|
|
315
333
|
type: 'task_updated',
|
|
316
334
|
taskId: task.id,
|
|
317
335
|
subject: task.subject,
|
|
@@ -336,7 +354,7 @@ export class EventTranslator {
|
|
|
336
354
|
const plan = event.plan
|
|
337
355
|
switch (event.type) {
|
|
338
356
|
case 'plan.ready':
|
|
339
|
-
await this.
|
|
357
|
+
await this.emitFromStore({
|
|
340
358
|
type: 'plan_ready',
|
|
341
359
|
planId: plan.id,
|
|
342
360
|
title: plan.title,
|
|
@@ -345,10 +363,10 @@ export class EventTranslator {
|
|
|
345
363
|
})
|
|
346
364
|
break
|
|
347
365
|
case 'plan.approved':
|
|
348
|
-
await this.
|
|
366
|
+
await this.emitFromStore({ type: 'plan_approved', planId: plan.id })
|
|
349
367
|
break
|
|
350
368
|
case 'plan.rejected':
|
|
351
|
-
await this.
|
|
369
|
+
await this.emitFromStore({
|
|
352
370
|
type: 'plan_rejected',
|
|
353
371
|
planId: plan.id,
|
|
354
372
|
reason: plan.rejectionReason,
|
|
@@ -356,7 +374,7 @@ export class EventTranslator {
|
|
|
356
374
|
break
|
|
357
375
|
case 'plan.step_updated':
|
|
358
376
|
if (event.step) {
|
|
359
|
-
await this.
|
|
377
|
+
await this.emitFromStore({
|
|
360
378
|
type: 'plan_step_updated',
|
|
361
379
|
planId: plan.id,
|
|
362
380
|
stepId: event.step.id,
|
|
@@ -365,10 +383,10 @@ export class EventTranslator {
|
|
|
365
383
|
}
|
|
366
384
|
break
|
|
367
385
|
case 'plan.completed':
|
|
368
|
-
await this.
|
|
386
|
+
await this.emitFromStore({ type: 'plan_completed', planId: plan.id })
|
|
369
387
|
break
|
|
370
388
|
case 'plan.failed':
|
|
371
|
-
await this.
|
|
389
|
+
await this.emitFromStore({
|
|
372
390
|
type: 'plan_failed',
|
|
373
391
|
planId: plan.id,
|
|
374
392
|
...(plan.failureReason ? { reason: plan.failureReason } : {}),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util'
|
|
1
2
|
import { GENAI, NAMZU } from '../../../constants/telemetry/index.js'
|
|
2
3
|
import { boundHookContext } from '../../../plugin/hook-context.js'
|
|
3
4
|
import { callableToolNames, formatToolNames } from '../../../registry/tool/callable.js'
|
|
@@ -83,30 +84,74 @@ export async function runPreToolHook(
|
|
|
83
84
|
signal.throwIfAborted()
|
|
84
85
|
const manager = host.config.pluginManager
|
|
85
86
|
if (!manager) return { kind: 'continue', input, modified: false }
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
87
|
+
const runHooks = async (toolInput: unknown): Promise<readonly PluginHookResult[]> => {
|
|
88
|
+
const results = await awaitWithAbort(
|
|
89
|
+
manager.executeHooks(
|
|
90
|
+
'pre_tool_use',
|
|
91
|
+
{
|
|
92
|
+
sessionId: host.config.sessionId,
|
|
93
|
+
turnId: host.config.turnId,
|
|
94
|
+
toolName,
|
|
95
|
+
...(toolCallId !== undefined ? { toolCallId } : {}),
|
|
96
|
+
toolInput,
|
|
97
|
+
signal,
|
|
98
|
+
},
|
|
99
|
+
host.emitEvent,
|
|
100
|
+
),
|
|
101
|
+
signal,
|
|
102
|
+
)
|
|
103
|
+
signal.throwIfAborted()
|
|
104
|
+
return results
|
|
105
|
+
}
|
|
106
|
+
let outcome = interpretPreToolResults(toolName, input, await runHooks(input), host.requestHalt)
|
|
103
107
|
if (outcome.kind !== 'continue') return outcome
|
|
108
|
+
if (outcome.modified) {
|
|
109
|
+
// The hooks answered about the call the model made. The call that will
|
|
110
|
+
// run is the rewritten one, so every hook answers again about that one:
|
|
111
|
+
// a refusal or a question from any of them stands, and an `allow` counts
|
|
112
|
+
// only when it was given to the input that runs. A second rewrite is not
|
|
113
|
+
// followed (a hook that rewrites every input would never settle), but it
|
|
114
|
+
// is not taken as a yes either.
|
|
115
|
+
const rewritten = outcome.input
|
|
116
|
+
const first = outcome
|
|
117
|
+
const again = interpretPreToolResults(
|
|
118
|
+
toolName,
|
|
119
|
+
rewritten,
|
|
120
|
+
(await runHooks(rewritten)).map((result) => settleRewrite(result, rewritten)),
|
|
121
|
+
host.requestHalt,
|
|
122
|
+
)
|
|
123
|
+
if (again.kind !== 'continue') return again
|
|
124
|
+
const contexts = [
|
|
125
|
+
...new Set([...(first.context?.split('\n') ?? []), ...(again.context?.split('\n') ?? [])]),
|
|
126
|
+
]
|
|
127
|
+
outcome = {
|
|
128
|
+
kind: 'continue',
|
|
129
|
+
input: rewritten,
|
|
130
|
+
modified: true,
|
|
131
|
+
...(again.permission ? { permission: again.permission } : {}),
|
|
132
|
+
...(contexts.length > 0 ? { context: contexts.join('\n') } : {}),
|
|
133
|
+
}
|
|
134
|
+
}
|
|
104
135
|
// A task being made or completed is announced once the call itself is allowed.
|
|
105
136
|
const refusal = await runTaskHook(host, manager, toolName, outcome.input, signal)
|
|
106
137
|
if (refusal === undefined) return outcome
|
|
107
138
|
return { kind: 'skip', input: outcome.input, output: refusal }
|
|
108
139
|
}
|
|
109
140
|
|
|
141
|
+
/**
|
|
142
|
+
* A hook's answer to the rewritten input: a `modify` to the same input is the
|
|
143
|
+
* hook agreeing, and a `modify` to anything else is dropped to a plain
|
|
144
|
+
* `continue` (its verdict was about an input that will not run).
|
|
145
|
+
*/
|
|
146
|
+
function settleRewrite(result: PluginHookResult, rewritten: unknown): PluginHookResult {
|
|
147
|
+
if (result.action !== 'modify') return result
|
|
148
|
+
const { input: _input, permission, ...rest } = result
|
|
149
|
+
if (isDeepStrictEqual(result.input, rewritten)) {
|
|
150
|
+
return { ...rest, action: 'continue', ...(permission ? { permission } : {}) }
|
|
151
|
+
}
|
|
152
|
+
return { ...rest, action: 'continue' }
|
|
153
|
+
}
|
|
154
|
+
|
|
110
155
|
/**
|
|
111
156
|
* `task_created` before `task_create` runs and `task_completed` before a
|
|
112
157
|
* `task_update` that completes a task. The text that refuses the call, or
|
|
@@ -29,6 +29,7 @@ import { withTokenBudget } from '../../provider/token-budget.js'
|
|
|
29
29
|
import type { SessionPaths } from '../../session/paths.js'
|
|
30
30
|
import type { SessionTokenBudget, SessionTokenBudgetStore } from '../../store/budget/index.js'
|
|
31
31
|
import type { SessionCheckpointStore } from '../../store/checkpoint/index.js'
|
|
32
|
+
import { DiskSessionLog } from '../../store/session-log/index.js'
|
|
32
33
|
import type { SessionLease, SessionLog } from '../../store/session-log/index.js'
|
|
33
34
|
import {
|
|
34
35
|
GENAI,
|
|
@@ -923,6 +924,13 @@ export interface QueryParams {
|
|
|
923
924
|
*/
|
|
924
925
|
compactionSummaryRoute?: CompactionSummaryRouter
|
|
925
926
|
|
|
927
|
+
/**
|
|
928
|
+
* Close a compaction summary with the wording that lets the model ask when
|
|
929
|
+
* something is unclear, instead of telling it to continue directly. Absent
|
|
930
|
+
* or false, it continues directly.
|
|
931
|
+
*/
|
|
932
|
+
compactionAskWhenUnclear?: boolean
|
|
933
|
+
|
|
926
934
|
/**
|
|
927
935
|
* Where this conversation's durable state lives.
|
|
928
936
|
*
|
|
@@ -2104,12 +2112,14 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
|
|
|
2104
2112
|
...(params.projectInstructionContext
|
|
2105
2113
|
? { projectInstructionContext: params.projectInstructionContext }
|
|
2106
2114
|
: {}),
|
|
2115
|
+
...(ctx.storage.log instanceof DiskSessionLog ? { sessionFile: ctx.storage.log.file } : {}),
|
|
2107
2116
|
...(params.postCompactionContext
|
|
2108
2117
|
? { postCompactionContext: params.postCompactionContext }
|
|
2109
2118
|
: {}),
|
|
2110
2119
|
...(params.compactionSummaryRoute
|
|
2111
2120
|
? { compactionSummaryRoute: params.compactionSummaryRoute }
|
|
2112
2121
|
: {}),
|
|
2122
|
+
...(params.compactionAskWhenUnclear ? { compactionAskWhenUnclear: true } : {}),
|
|
2113
2123
|
...(providerContextWindow !== undefined ? { providerContextWindow } : {}),
|
|
2114
2124
|
...(providerAutoCompactLimit !== undefined ? { providerAutoCompactLimit } : {}),
|
|
2115
2125
|
resolveModelAutoCompactLimit: async (model) => {
|
|
@@ -26,7 +26,12 @@ import {
|
|
|
26
26
|
} from '../../../../compaction/plan.js'
|
|
27
27
|
import type { ContextReducer, ContextReduction } from '../../../../compaction/reducer.js'
|
|
28
28
|
import { createSlidingWindowReducer } from '../../../../compaction/reducer.js'
|
|
29
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
carriedWorkingCommands,
|
|
31
|
+
collectToolsUsed,
|
|
32
|
+
keptInstructionFiles,
|
|
33
|
+
renderRestoredContext,
|
|
34
|
+
} from '../../../../compaction/restore.js'
|
|
30
35
|
import { findRetainedIndices } from '../../../../compaction/retention.js'
|
|
31
36
|
import { serializeState } from '../../../../compaction/serializer.js'
|
|
32
37
|
import {
|
|
@@ -1302,18 +1307,30 @@ async function runCompactionCheckInner(
|
|
|
1302
1307
|
// shown by an earlier pass, is not put back a second time.
|
|
1303
1308
|
const wholeSkills = handledSkillNames([...preservedSystem, ...retainedOlder, ...recentMessages])
|
|
1304
1309
|
const putBack: { rendered?: RenderedSkills } = {}
|
|
1310
|
+
const mounted = new Set(ctx.tools?.listNames?.() ?? [])
|
|
1305
1311
|
const restored = renderRestoredContext(manager.getState(), {
|
|
1306
1312
|
contextWindowTokens: budget,
|
|
1307
1313
|
wholeSkills,
|
|
1308
1314
|
onSkills: (rendered) => {
|
|
1309
1315
|
putBack.rendered = rendered
|
|
1310
1316
|
},
|
|
1317
|
+
// What the model was working with, named so it keeps using it: the tools it
|
|
1318
|
+
// called (this pass's span and what earlier summaries listed) and the
|
|
1319
|
+
// project instructions that stay whole after the summary.
|
|
1320
|
+
toolsUsed: collectToolsUsed(messages),
|
|
1321
|
+
instructionFiles: keptInstructionFiles([
|
|
1322
|
+
...preservedSystem,
|
|
1323
|
+
...retainedOlder,
|
|
1324
|
+
...recentMessages,
|
|
1325
|
+
]),
|
|
1326
|
+
// The roster of agents is in the description of the tool that hands work to
|
|
1327
|
+
// them, which every request carries; say so instead of copying it.
|
|
1328
|
+
...(mounted.has('create_task') ? { agentsTool: 'create_task' } : {}),
|
|
1311
1329
|
...(hostNote ? { hostNote } : {}),
|
|
1312
1330
|
})
|
|
1313
1331
|
if (restored) compactedContent = `${compactedContent}\n\n${restored}`
|
|
1314
1332
|
|
|
1315
1333
|
// The pointer is only worth a line when both tools it names are mounted.
|
|
1316
|
-
const mounted = new Set(ctx.tools?.listNames?.() ?? [])
|
|
1317
1334
|
const compactionMessage = buildCompactionMessage(
|
|
1318
1335
|
compactedContent,
|
|
1319
1336
|
mounted.has('search_conversation') && mounted.has('read_conversation')
|
|
@@ -1322,6 +1339,13 @@ async function runCompactionCheckInner(
|
|
|
1322
1339
|
// The tools the model had loaded stay loaded: the messages that loaded
|
|
1323
1340
|
// them are what this pass cuts.
|
|
1324
1341
|
collectRevealedTools(messages),
|
|
1342
|
+
{
|
|
1343
|
+
// The summary was written without the messages kept after it.
|
|
1344
|
+
keptTail: retainedOlder.length + recentMessages.length > 0,
|
|
1345
|
+
toolsUsed: collectToolsUsed(messages),
|
|
1346
|
+
...(ctx.sessionFile ? { sessionFile: ctx.sessionFile } : {}),
|
|
1347
|
+
...(ctx.compactionAskWhenUnclear ? { askWhenUnclear: true } : {}),
|
|
1348
|
+
},
|
|
1325
1349
|
)
|
|
1326
1350
|
|
|
1327
1351
|
const newMessages = [...preservedSystem, compactionMessage, ...retainedOlder, ...recentMessages]
|
|
@@ -274,6 +274,12 @@ export interface IterationContext {
|
|
|
274
274
|
/** Live project policy; separate from human inbound continuation. */
|
|
275
275
|
readonly projectInstructionContext?: ProjectInstructionContext
|
|
276
276
|
|
|
277
|
+
/** The file the session's full record is stored in, named in a compaction summary so exact text can be found again. Absent for an in-memory session. */
|
|
278
|
+
readonly sessionFile?: string
|
|
279
|
+
|
|
280
|
+
/** Close a compaction summary with the wording that lets the model ask when something is unclear. */
|
|
281
|
+
readonly compactionAskWhenUnclear?: boolean
|
|
282
|
+
|
|
277
283
|
/** Host text appended to the restored context after a compaction. */
|
|
278
284
|
readonly postCompactionContext?: () => string | undefined | Promise<string | undefined>
|
|
279
285
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
1
2
|
import { wrapUntrusted } from '../tools/untrusted-envelope.js'
|
|
2
3
|
import type { TaskHandle, TaskScheduler } from '../types/agent/scheduler.js'
|
|
3
4
|
import { isTerminalAgentTaskState } from '../types/agent/task.js'
|
|
@@ -722,6 +723,18 @@ function neutralizeNotificationDelimiter(content: string): string {
|
|
|
722
723
|
return content.replace(NOTIFICATION_DELIMITER, 'task_notification')
|
|
723
724
|
}
|
|
724
725
|
|
|
726
|
+
/**
|
|
727
|
+
* Where a worker that had a checkout of its own left its work. The checkout is kept when the
|
|
728
|
+
* worker changed or committed anything and removed when it did not, so the answer is read from
|
|
729
|
+
* the disk: a path that is gone is not offered as something to look at.
|
|
730
|
+
*/
|
|
731
|
+
function workspaceLines(handle: TaskHandle): string[] {
|
|
732
|
+
const meta = handle.workspace?.meta
|
|
733
|
+
if (meta?.backend !== 'git-worktree') return []
|
|
734
|
+
if (!existsSync(meta.worktreePath)) return ['workspace: removed (the worker changed nothing)']
|
|
735
|
+
return [`workspace: ${meta.worktreePath}`, `branch: ${meta.branch}`]
|
|
736
|
+
}
|
|
737
|
+
|
|
725
738
|
/**
|
|
726
739
|
* The message a supervisor reads when a worker it stopped waiting for
|
|
727
740
|
* finishes.
|
|
@@ -790,6 +803,7 @@ export function formatCompletionNotification(handles: readonly TaskHandle[]): st
|
|
|
790
803
|
...(handle.result?.stopReason ? [`stop_reason: ${handle.result.stopReason}`] : []),
|
|
791
804
|
...(durationMs !== undefined ? [`duration_ms: ${durationMs}`] : []),
|
|
792
805
|
...(handle.completedAt ? [`finished_at: ${new Date(handle.completedAt).toISOString()}`] : []),
|
|
806
|
+
...workspaceLines(handle),
|
|
793
807
|
'',
|
|
794
808
|
body,
|
|
795
809
|
// Outside the envelope, deliberately: this sentence is an
|
|
@@ -177,6 +177,13 @@ export interface SessionLogLocation {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
export interface SessionIndex {
|
|
180
|
+
/**
|
|
181
|
+
* True while the index was opened on demand and no read has caught it up with
|
|
182
|
+
* the logs yet: the next list, search or lookup reads every log first, so a
|
|
183
|
+
* caller that makes a person wait can say so. Absent on a backend that does
|
|
184
|
+
* not defer.
|
|
185
|
+
*/
|
|
186
|
+
readonly syncPending?: boolean
|
|
180
187
|
readonly backend: 'sqlite' | 'scan'
|
|
181
188
|
/** Derive (or continue deriving) one session from its records. */
|
|
182
189
|
indexSession(input: SessionLogInput): Promise<IndexedSession | undefined>
|
|
@@ -216,6 +223,12 @@ export interface OpenSessionIndexOptions {
|
|
|
216
223
|
* catch up with the logs in the background; every read waits for it.
|
|
217
224
|
*/
|
|
218
225
|
readonly syncInBackground?: boolean
|
|
226
|
+
/**
|
|
227
|
+
* SQLite only: open without reading any log, and catch up with the logs the
|
|
228
|
+
* first time a read asks. A write never starts the catch-up. The scan
|
|
229
|
+
* backend reads on first use already.
|
|
230
|
+
*/
|
|
231
|
+
readonly syncOnDemand?: boolean
|
|
219
232
|
}
|
|
220
233
|
|
|
221
234
|
/**
|
|
@@ -234,6 +247,7 @@ export async function openSessionIndex(
|
|
|
234
247
|
home,
|
|
235
248
|
path: options.path ?? join(home, 'index.sqlite'),
|
|
236
249
|
...(options.syncInBackground === true ? { syncInBackground: true } : {}),
|
|
250
|
+
...(options.syncOnDemand === true ? { syncOnDemand: true } : {}),
|
|
237
251
|
})
|
|
238
252
|
}
|
|
239
253
|
|
|
@@ -745,8 +745,26 @@ export abstract class SessionIndexBase implements SessionIndex {
|
|
|
745
745
|
return Promise.resolve()
|
|
746
746
|
}
|
|
747
747
|
|
|
748
|
+
/**
|
|
749
|
+
* What a read about one session waits for. A backend that syncs on first read
|
|
750
|
+
* overrides it to bring only that session's rows current, so a lookup the turn
|
|
751
|
+
* itself makes does not read every log.
|
|
752
|
+
*/
|
|
753
|
+
protected settledFor(_sessionId: SessionId | undefined): Promise<void> {
|
|
754
|
+
return this.settled()
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* What a write waits for: a catch-up already running, never one that has not
|
|
759
|
+
* started. A backend that syncs on first read overrides it, so a write at the
|
|
760
|
+
* start of a conversation does not pay for reading every log.
|
|
761
|
+
*/
|
|
762
|
+
protected settledForWrite(): Promise<void> {
|
|
763
|
+
return this.settled()
|
|
764
|
+
}
|
|
765
|
+
|
|
748
766
|
async getSession(sessionId: SessionId): Promise<IndexedSession | undefined> {
|
|
749
|
-
await this.
|
|
767
|
+
await this.settledFor(sessionId)
|
|
750
768
|
return this.sessionNow(sessionId)
|
|
751
769
|
}
|
|
752
770
|
|
|
@@ -765,7 +783,7 @@ export abstract class SessionIndexBase implements SessionIndex {
|
|
|
765
783
|
* clears the row, so a write that ran beside it could be undone.
|
|
766
784
|
*/
|
|
767
785
|
async indexSession(input: SessionLogInput): Promise<IndexedSession | undefined> {
|
|
768
|
-
await this.
|
|
786
|
+
await this.settledForWrite()
|
|
769
787
|
return this.indexSessionNow(input)
|
|
770
788
|
}
|
|
771
789
|
|
|
@@ -882,7 +900,7 @@ export abstract class SessionIndexBase implements SessionIndex {
|
|
|
882
900
|
}
|
|
883
901
|
|
|
884
902
|
async refresh(location: SessionLogLocation): Promise<SessionStaleness> {
|
|
885
|
-
await this.
|
|
903
|
+
await this.settledForWrite()
|
|
886
904
|
return this.refreshNow(location)
|
|
887
905
|
}
|
|
888
906
|
|
|
@@ -912,7 +930,7 @@ export abstract class SessionIndexBase implements SessionIndex {
|
|
|
912
930
|
}
|
|
913
931
|
|
|
914
932
|
async sync(home: string): Promise<void> {
|
|
915
|
-
await this.
|
|
933
|
+
await this.settledForWrite()
|
|
916
934
|
return this.syncNow(home)
|
|
917
935
|
}
|
|
918
936
|
|