typeclaw 0.50.0 → 0.52.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/dist/types/agent/bash-sandbox-env.d.ts +17 -0
- package/dist/types/agent/bash-sandbox-proc.d.ts +8 -0
- package/dist/types/agent/bash-sandbox.d.ts +98 -0
- package/dist/types/agent/compaction.d.ts +4 -4
- package/dist/types/agent/idle-compaction.d.ts +1 -0
- package/dist/types/agent/index.d.ts +10 -17
- package/dist/types/agent/multimodal/look-at.d.ts +1 -1
- package/dist/types/agent/output-allowance.d.ts +4 -0
- package/dist/types/agent/plugin-tools.d.ts +8 -75
- package/dist/types/agent/prompt-cache-key.d.ts +1 -0
- package/dist/types/agent/session-tail.d.ts +12 -0
- package/dist/types/agent/subagents.d.ts +5 -0
- package/dist/types/agent/system-prompt-composition.d.ts +18 -0
- package/dist/types/agent/system-prompt.d.ts +2 -0
- package/dist/types/agent/tools/channel-disengage.d.ts +1 -1
- package/dist/types/agent/tools/channel-edit.d.ts +1 -1
- package/dist/types/agent/tools/channel-fetch-attachment.d.ts +1 -1
- package/dist/types/agent/tools/channel-handoff.d.ts +1 -1
- package/dist/types/agent/tools/channel-history.d.ts +1 -1
- package/dist/types/agent/tools/channel-react.d.ts +1 -1
- package/dist/types/agent/tools/channel-read.d.ts +10 -2
- package/dist/types/agent/tools/channel-reply.d.ts +1 -1
- package/dist/types/agent/tools/channel-send.d.ts +1 -1
- package/dist/types/agent/tools/channel-session-search.d.ts +1 -1
- package/dist/types/agent/tools/ddg.d.ts +9 -0
- package/dist/types/agent/tools/grant-role.d.ts +1 -1
- package/dist/types/agent/tools/post-github-review.d.ts +1 -1
- package/dist/types/agent/tools/restart.d.ts +1 -1
- package/dist/types/agent/tools/skip-response.d.ts +1 -1
- package/dist/types/agent/tools/spawn-subagent.d.ts +2 -1
- package/dist/types/agent/tools/stream-snapshot.d.ts +2 -2
- package/dist/types/agent/tools/subagent-cancel.d.ts +1 -1
- package/dist/types/agent/tools/subagent-output.d.ts +1 -1
- package/dist/types/agent/tools/todo/index.d.ts +1 -1
- package/dist/types/agent/tools/webfetch/adaptive-html.d.ts +3 -3
- package/dist/types/agent/tools/webfetch/strategies/readability-process.d.ts +48 -0
- package/dist/types/agent/tools/webfetch/tool.d.ts +2 -2
- package/dist/types/agent/tools/websearch.d.ts +1 -1
- package/dist/types/channels/adapters/github/auth-app.d.ts +25 -0
- package/dist/types/channels/adapters/github/auth-pat.d.ts +17 -0
- package/dist/types/channels/adapters/github/auth.d.ts +24 -0
- package/dist/types/channels/github-review-check.d.ts +1 -1
- package/dist/types/channels/github-token-bridge.d.ts +4 -0
- package/dist/types/channels/lost-background-context.d.ts +2 -0
- package/dist/types/channels/persistence.d.ts +1 -0
- package/dist/types/channels/router.d.ts +16 -50
- package/dist/types/channels/types.d.ts +1 -0
- package/dist/types/coding-agent/tool.d.ts +1 -1
- package/dist/types/config/config.d.ts +22 -0
- package/dist/types/config/providers.d.ts +50 -1
- package/dist/types/container/start.d.ts +1 -0
- package/dist/types/eval/cell.d.ts +26 -0
- package/dist/types/eval/config.d.ts +19 -0
- package/dist/types/eval/dispatch.d.ts +7 -0
- package/dist/types/eval/kernel.d.ts +28 -0
- package/dist/types/eval/process.d.ts +23 -0
- package/dist/types/eval/protocol.d.ts +34 -0
- package/dist/types/eval/sandbox.d.ts +12 -0
- package/dist/types/eval/tool.d.ts +17 -0
- package/dist/types/eval/wire.d.ts +33 -0
- package/dist/types/git/resolve-identity.d.ts +2 -0
- package/dist/types/init/dockerfile.d.ts +1 -0
- package/dist/types/init/gitignore.d.ts +1 -1
- package/dist/types/permissions/builtins.d.ts +1 -0
- package/dist/types/plugin/types.d.ts +3 -0
- package/dist/types/sandbox/canonical-secrets.d.ts +2 -2
- package/dist/types/sandbox/coding-agent.d.ts +1 -1
- package/dist/types/sandbox/dependency-bins.d.ts +1 -0
- package/dist/types/sandbox/dev-source.d.ts +2 -2
- package/dist/types/sandbox/env-exposure.d.ts +2 -0
- package/dist/types/sandbox/hidden-paths.d.ts +1 -0
- package/dist/types/sandbox/index.d.ts +1 -1
- package/dist/types/sandbox/policy.d.ts +3 -0
- package/dist/types/typevault/cli-path.d.ts +2 -0
- package/dist/types/typevault/envelope-store.d.ts +11 -0
- package/dist/types/typevault/lifecycle.d.ts +13 -0
- package/dist/types/typevault/vault.d.ts +27 -0
- package/package.json +8 -7
- package/scripts/test.ts +252 -0
- package/src/agent/bash-sandbox-env.ts +136 -0
- package/src/agent/bash-sandbox-proc.ts +70 -0
- package/src/agent/bash-sandbox.ts +239 -0
- package/src/agent/compaction.ts +22 -10
- package/src/agent/idle-compaction.ts +7 -3
- package/src/agent/index.ts +185 -187
- package/src/agent/multimodal/look-at.ts +1 -1
- package/src/agent/output-allowance.ts +7 -0
- package/src/agent/plugin-tools.ts +64 -380
- package/src/agent/prompt-cache-key.ts +26 -3
- package/src/agent/session-origin.ts +41 -19
- package/src/agent/session-tail.ts +28 -0
- package/src/agent/subagent-completion-reminder.ts +2 -2
- package/src/agent/subagents.ts +21 -2
- package/src/agent/system-prompt-composition.ts +159 -0
- package/src/agent/system-prompt.ts +43 -5
- package/src/agent/todo/scope.ts +1 -1
- package/src/agent/tool-error-remediation.ts +18 -3
- package/src/agent/tools/channel-disengage.ts +1 -1
- package/src/agent/tools/channel-edit.ts +1 -1
- package/src/agent/tools/channel-fetch-attachment.ts +1 -1
- package/src/agent/tools/channel-handoff.ts +3 -2
- package/src/agent/tools/channel-history.ts +2 -1
- package/src/agent/tools/channel-react.ts +1 -1
- package/src/agent/tools/channel-read.ts +36 -3
- package/src/agent/tools/channel-reply.ts +1 -1
- package/src/agent/tools/channel-send.ts +4 -3
- package/src/agent/tools/channel-session-search.ts +13 -4
- package/src/agent/tools/ddg.ts +71 -11
- package/src/agent/tools/grant-role.ts +1 -1
- package/src/agent/tools/post-github-review.ts +1 -1
- package/src/agent/tools/restart.ts +1 -1
- package/src/agent/tools/skip-response.ts +1 -1
- package/src/agent/tools/spawn-subagent.ts +15 -1
- package/src/agent/tools/stream-snapshot.ts +1 -1
- package/src/agent/tools/subagent-cancel.ts +1 -1
- package/src/agent/tools/subagent-output.ts +1 -1
- package/src/agent/tools/todo/index.ts +1 -1
- package/src/agent/tools/webfetch/adaptive-html.ts +6 -4
- package/src/agent/tools/webfetch/strategies/readability-child.ts +25 -0
- package/src/agent/tools/webfetch/strategies/readability-process.ts +185 -0
- package/src/agent/tools/webfetch/tool.ts +6 -5
- package/src/agent/tools/websearch.ts +1 -1
- package/src/agent/tools-without-local-file-operands.ts +4 -0
- package/src/browser/dockerfile.ts +1 -1
- package/src/browser/fill-secret.ts +364 -0
- package/src/browser/registry.ts +6 -6
- package/src/bundled-plugins/agent-messenger-cli-auth/command.ts +211 -0
- package/src/bundled-plugins/agent-messenger-cli-auth/index.ts +186 -0
- package/src/bundled-plugins/backup/index.ts +17 -2
- package/src/bundled-plugins/backup/runner.ts +37 -2
- package/src/bundled-plugins/browser-agent/browser-agent.ts +51 -14
- package/src/bundled-plugins/browser-agent/index.ts +12 -5
- package/src/bundled-plugins/explorer/explorer.ts +1 -1
- package/src/bundled-plugins/github-cli-auth/gh-review-detect.ts +40 -16
- package/src/bundled-plugins/github-cli-auth/graphql-auth-nudge.ts +12 -7
- package/src/bundled-plugins/github-cli-auth/index.ts +10 -1
- package/src/bundled-plugins/managed-browser/index.ts +130 -2
- package/src/bundled-plugins/managed-browser/skills/browserskill/browserskill/SKILL.md +13 -5
- package/src/bundled-plugins/managed-browser/skills/omowright/omowright/SKILL.md +56 -5
- package/src/bundled-plugins/memory/README.md +23 -2
- package/src/bundled-plugins/memory/append-fragment.ts +133 -0
- package/src/bundled-plugins/memory/append-tool.ts +80 -149
- package/src/bundled-plugins/memory/dreaming.ts +6 -1
- package/src/bundled-plugins/memory/index.ts +33 -6
- package/src/bundled-plugins/memory/load-memory.ts +2 -4
- package/src/bundled-plugins/memory/memory-logger.ts +200 -6
- package/src/bundled-plugins/memory/references/store-reference-tool.ts +56 -32
- package/src/bundled-plugins/memory/remember-tool.ts +81 -0
- package/src/bundled-plugins/memory/search-tool-hybrid.ts +91 -0
- package/src/bundled-plugins/memory/search-tool.ts +58 -12
- package/src/bundled-plugins/memory/stream-events.ts +2 -0
- package/src/bundled-plugins/memory/transcript-cursor.ts +30 -0
- package/src/bundled-plugins/memory/transcript-preload.ts +208 -0
- package/src/bundled-plugins/memory/transcript-view.ts +36 -0
- package/src/bundled-plugins/memory/vector/hybrid.ts +25 -14
- package/src/bundled-plugins/memory/watermark.ts +19 -10
- package/src/bundled-plugins/reviewer/reviewer.ts +20 -0
- package/src/bundled-plugins/security/policies/outbound-secret-scan.ts +3 -6
- package/src/bundled-plugins/security/policies/outbound-text.ts +20 -0
- package/src/bundled-plugins/security/policies/private-surface-read.ts +166 -201
- package/src/bundled-plugins/security/policies/system-prompt-leak.ts +2 -7
- package/src/bundled-plugins/typevault/grants.ts +119 -0
- package/src/bundled-plugins/typevault/index.ts +152 -0
- package/src/bundled-plugins/typevault/request.ts +87 -0
- package/src/bundled-plugins/typevault/runtime.ts +45 -0
- package/src/bundled-plugins/typevault/skills/typevault/SKILL.md +65 -0
- package/src/channels/adapter-halt.ts +17 -0
- package/src/channels/adapters/discord-bot-reference.ts +5 -4
- package/src/channels/adapters/discord-bot.ts +1 -0
- package/src/channels/adapters/discord-classify.ts +8 -3
- package/src/channels/adapters/discord.ts +29 -0
- package/src/channels/adapters/github/history.ts +23 -2
- package/src/channels/adapters/github/inbound.ts +60 -1
- package/src/channels/adapters/github/index.ts +27 -5
- package/src/channels/adapters/github/reconcile-open-prs.ts +7 -1
- package/src/channels/adapters/kakaotalk-author-resolver.ts +7 -5
- package/src/channels/adapters/kakaotalk-channel-resolver.ts +45 -15
- package/src/channels/adapters/kakaotalk-classify.ts +7 -9
- package/src/channels/adapters/kakaotalk-list.ts +62 -0
- package/src/channels/adapters/kakaotalk-member-cache.ts +67 -0
- package/src/channels/adapters/kakaotalk-membership.ts +27 -10
- package/src/channels/adapters/kakaotalk-mention.ts +61 -0
- package/src/channels/adapters/kakaotalk.ts +159 -125
- package/src/channels/adapters/teams-classify.ts +18 -8
- package/src/channels/github-review-check.ts +5 -1
- package/src/channels/github-review-verdict-coordinator.ts +68 -2
- package/src/channels/github-token-bridge.ts +13 -0
- package/src/channels/lost-background-context.ts +46 -0
- package/src/channels/manager.ts +52 -3
- package/src/channels/persistence.ts +5 -0
- package/src/channels/router.ts +208 -128
- package/src/channels/schema.ts +1 -1
- package/src/channels/subagent-completion-bridge.ts +3 -2
- package/src/channels/types.ts +3 -0
- package/src/cli/hostd.ts +3 -0
- package/src/coding-agent/tool.ts +1 -1
- package/src/config/config.ts +35 -1
- package/src/config/providers.ts +75 -4
- package/src/container/start.ts +52 -3
- package/src/doctor/channel-checks.ts +33 -0
- package/src/doctor/checks.ts +37 -18
- package/src/doctor/index.ts +48 -12
- package/src/doctor/operational-incidents.ts +16 -1
- package/src/doctor/plugin-bridge.ts +14 -1
- package/src/doctor/stage.ts +14 -0
- package/src/doctor/types.ts +6 -0
- package/src/eval/cell.ts +93 -0
- package/src/eval/config.ts +32 -0
- package/src/eval/dispatch.ts +67 -0
- package/src/eval/entry.ts +261 -0
- package/src/eval/kernel.ts +154 -0
- package/src/eval/process.ts +113 -0
- package/src/eval/protocol.ts +26 -0
- package/src/eval/redeclare.ts +174 -0
- package/src/eval/sandbox.ts +117 -0
- package/src/eval/tool.ts +99 -0
- package/src/eval/wire.ts +93 -0
- package/src/git/resolve-identity.ts +67 -2
- package/src/git/system-commit.ts +7 -0
- package/src/init/dockerfile.ts +5 -1
- package/src/init/gitignore.ts +3 -3
- package/src/init/index.ts +1 -0
- package/src/init/models-dev.ts +2 -0
- package/src/init/validate-api-key.ts +5 -0
- package/src/migrations/secrets-v1-to-v2.ts +2 -0
- package/src/operations/classify-tool-outcome.ts +1 -1
- package/src/permissions/builtins.ts +8 -0
- package/src/plugin/core-tool-names.ts +6 -1
- package/src/plugin/types.ts +6 -0
- package/src/run/bundled-plugins.ts +12 -0
- package/src/run/channel-session-factory.ts +3 -0
- package/src/run/index.ts +13 -2
- package/src/sandbox/build.ts +1 -0
- package/src/sandbox/canonical-secrets.ts +6 -0
- package/src/sandbox/dependency-bins.ts +13 -1
- package/src/sandbox/dev-source.ts +21 -12
- package/src/sandbox/env-exposure.ts +20 -0
- package/src/sandbox/hidden-paths.ts +1 -1
- package/src/sandbox/index.ts +1 -0
- package/src/sandbox/policy.ts +5 -0
- package/src/secrets/hydrate.ts +4 -1
- package/src/secrets/storage.ts +10 -1
- package/src/server/command-runner.ts +4 -0
- package/src/server/index.ts +54 -12
- package/src/skills/typeclaw-config/SKILL.md +36 -2
- package/src/skills/typeclaw-memory/SKILL.md +3 -1
- package/src/skills/typeclaw-permissions/SKILL.md +8 -8
- package/src/skills/typeclaw-troubleshooting/SKILL.md +18 -1
- package/src/tunnels/active.ts +14 -0
- package/src/typevault/bash-cli.ts +18 -0
- package/src/typevault/cli-path.ts +11 -0
- package/src/typevault/envelope-helper.ts +17 -0
- package/src/typevault/envelope-store.ts +98 -0
- package/src/typevault/lifecycle.ts +132 -0
- package/src/typevault/prompt-tunnel.ts +33 -0
- package/src/typevault/redaction.ts +37 -0
- package/src/typevault/vault.ts +283 -0
- package/typeclaw.schema.json +92 -10
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
1
2
|
import { writeFile } from 'node:fs/promises'
|
|
2
3
|
|
|
3
4
|
import { z } from 'zod'
|
|
@@ -13,9 +14,13 @@ import {
|
|
|
13
14
|
} from './provenance-index'
|
|
14
15
|
import { sanitizeProvenanceName } from './provenance-sanitize'
|
|
15
16
|
import { renderReference } from './references/frontmatter'
|
|
16
|
-
import { loadAllReferences, loadReference, type Reference } from './references/load-references'
|
|
17
|
+
import { bumpReferenceAccess, loadAllReferences, loadReference, type Reference } from './references/load-references'
|
|
18
|
+
import { vectorDbPath } from './search-command'
|
|
19
|
+
import { hydrateHybridMatches } from './search-tool-hybrid'
|
|
17
20
|
import type { FragmentEvent, FragmentProvenance, LegacyProseEvent, StreamEvent } from './stream-events'
|
|
18
21
|
import { filterUndreamedEvents, readAllStreamDays, type UndreamedStreamDay } from './stream-io'
|
|
22
|
+
import { hybridSearch, type EmbedFn, type HybridSearchResult } from './vector/hybrid'
|
|
23
|
+
import { VectorStore } from './vector/store'
|
|
19
24
|
|
|
20
25
|
const DEFAULT_MAX_RESULTS = 10
|
|
21
26
|
const EXCERPT_CONTEXT_LINES = 3
|
|
@@ -59,12 +64,13 @@ export type MemorySearchResult = { matches: MemorySearchMatch[]; truncatedAt?: n
|
|
|
59
64
|
|
|
60
65
|
export type Matcher = (haystack: string) => boolean
|
|
61
66
|
|
|
62
|
-
export function createMemorySearchTool() {
|
|
67
|
+
export function createMemorySearchTool(embedFn?: EmbedFn) {
|
|
63
68
|
return defineTool({
|
|
64
69
|
description:
|
|
65
|
-
'Search long-term memory and recent undreamed fragments
|
|
70
|
+
'Search long-term memory and recent undreamed fragments by meaning and keywords (default mode: hybrid). Use mode: lexical for case-insensitive phrase-first search with token-OR fallback. Use asRegex: true for exact regex semantics without token fallback, or topic for one exact topic/reference slug; both bypass semantic search. If the semantic index is unavailable, the result reports lexical fallback. full: true returns complete bodies. Runtime-owned provenance from active topic citations is searchable but never embedded. `workspace`, `chat`, and `thread` scope both topics and recent fragments to matching captured origin IDs or names; legacy `where` remains an alias for `chat`. Scoped topic eligibility, lexical matching, and returned provenance use the same eligible active cited children. Unresolved citations remain explicit in unscoped results and never gain invented metadata.',
|
|
66
71
|
parameters: z.object({
|
|
67
72
|
query: z.string().optional(),
|
|
73
|
+
mode: z.enum(['hybrid', 'lexical']).default('hybrid'),
|
|
68
74
|
topic: z.string().optional(),
|
|
69
75
|
asRegex: z.boolean().default(false),
|
|
70
76
|
full: z.boolean().default(false),
|
|
@@ -82,9 +88,12 @@ export function createMemorySearchTool() {
|
|
|
82
88
|
// with an agent-root dir, or a `since` date like "2026-01-01", is not
|
|
83
89
|
// misread as a file operand.
|
|
84
90
|
fileOperands: {
|
|
85
|
-
nonFile: ['query', 'topic', 'since', 'before', 'where', 'workspace', 'chat', 'thread'],
|
|
91
|
+
nonFile: ['query', 'mode', 'topic', 'since', 'before', 'where', 'workspace', 'chat', 'thread'],
|
|
86
92
|
},
|
|
87
|
-
async execute(
|
|
93
|
+
async execute(
|
|
94
|
+
{ query, mode, topic, asRegex, full, maxResults, since, before, where, workspace, chat, thread },
|
|
95
|
+
ctx,
|
|
96
|
+
) {
|
|
88
97
|
if ((query === undefined) === (topic === undefined)) {
|
|
89
98
|
return resultToToolResult({ error: 'provide exactly one of `query` or `topic`' })
|
|
90
99
|
}
|
|
@@ -105,6 +114,37 @@ export function createMemorySearchTool() {
|
|
|
105
114
|
if (typeof matcherOrError === 'string') {
|
|
106
115
|
return resultToToolResult({ error: matcherOrError })
|
|
107
116
|
}
|
|
117
|
+
const dateFilter = parseReferenceDateFilter(since, before)
|
|
118
|
+
if ('error' in dateFilter) return resultToToolResult(dateFilter)
|
|
119
|
+
let fallbackReason: string | undefined
|
|
120
|
+
if (query !== undefined && mode === 'hybrid' && !asRegex) {
|
|
121
|
+
const dbPath = vectorDbPath(ctx.agentDir)
|
|
122
|
+
if (!existsSync(dbPath)) {
|
|
123
|
+
fallbackReason = 'memory/.vectors/index.db is absent'
|
|
124
|
+
} else {
|
|
125
|
+
try {
|
|
126
|
+
const store = VectorStore.open(dbPath)
|
|
127
|
+
let hits: HybridSearchResult[]
|
|
128
|
+
try {
|
|
129
|
+
hits = await hybridSearch(query, store, ctx.agentDir, maxResults, embedFn, { scope })
|
|
130
|
+
} finally {
|
|
131
|
+
store.close()
|
|
132
|
+
}
|
|
133
|
+
const matches = (await hydrateHybridMatches(ctx.agentDir, hits, full)).filter(
|
|
134
|
+
(match) => match.source !== 'reference' || referenceDateAllowed(match.created, dateFilter),
|
|
135
|
+
)
|
|
136
|
+
await bumpReferenceAccess(
|
|
137
|
+
ctx.agentDir,
|
|
138
|
+
matches.flatMap((match) => (match.source === 'reference' ? [match.slug] : [])),
|
|
139
|
+
{ logger: ctx.logger },
|
|
140
|
+
)
|
|
141
|
+
return resultToToolResult({ matches })
|
|
142
|
+
} catch (err) {
|
|
143
|
+
fallbackReason = err instanceof Error ? err.message : String(err)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
ctx.logger.warn(`[memory-search] semantic index unavailable: ${fallbackReason}`)
|
|
147
|
+
}
|
|
108
148
|
const [shards, allStreamDays, allReferences] = await Promise.all([
|
|
109
149
|
loadAllShards(ctx.agentDir, { logger: ctx.logger }),
|
|
110
150
|
readAllStreamDays(ctx.agentDir),
|
|
@@ -126,8 +166,6 @@ export function createMemorySearchTool() {
|
|
|
126
166
|
}
|
|
127
167
|
return events.length === 0 ? [] : [{ date: day.date, path: day.path, name: day.name, events }]
|
|
128
168
|
})
|
|
129
|
-
const dateFilter = parseReferenceDateFilter(since, before)
|
|
130
|
-
if ('error' in dateFilter) return resultToToolResult(dateFilter)
|
|
131
169
|
|
|
132
170
|
const roomFilteredDays = streamDays
|
|
133
171
|
const scopedShards = shards.filter((shard) => provenanceIndex.topicEligible(shard.slug, scope))
|
|
@@ -154,7 +192,7 @@ export function createMemorySearchTool() {
|
|
|
154
192
|
}
|
|
155
193
|
|
|
156
194
|
if (scopedShards.length === 0 && roomFilteredDays.length === 0 && references.length === 0) {
|
|
157
|
-
return resultToToolResult({ matches: [], truncatedAt: 0 })
|
|
195
|
+
return resultToToolResult({ matches: [], truncatedAt: 0 }, fallbackReason)
|
|
158
196
|
}
|
|
159
197
|
|
|
160
198
|
const searchOptions = { full, maxResults, references, topicDocuments, topicProvenance, streamDocuments }
|
|
@@ -164,7 +202,7 @@ export function createMemorySearchTool() {
|
|
|
164
202
|
if (fallback !== null) result = fallback
|
|
165
203
|
}
|
|
166
204
|
if ('matches' in result) await bumpReturnedReferences(allReferences, result.matches)
|
|
167
|
-
return resultToToolResult(result)
|
|
205
|
+
return resultToToolResult(result, fallbackReason)
|
|
168
206
|
},
|
|
169
207
|
})
|
|
170
208
|
}
|
|
@@ -661,7 +699,11 @@ function parseDateParam(name: string, value: string): Date | string {
|
|
|
661
699
|
|
|
662
700
|
function referenceCandidateAllowed(reference: Reference, filter: ReferenceDateFilter): boolean {
|
|
663
701
|
if (reference.frontmatter.demoted) return false
|
|
664
|
-
|
|
702
|
+
return referenceDateAllowed(reference.frontmatter.created, filter)
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
function referenceDateAllowed(createdAt: string, filter: ReferenceDateFilter): boolean {
|
|
706
|
+
const created = new Date(createdAt)
|
|
665
707
|
if (filter.since !== undefined && created < filter.since) return false
|
|
666
708
|
if (filter.before !== undefined && created >= filter.before) return false
|
|
667
709
|
return true
|
|
@@ -702,9 +744,13 @@ const EMPTY_RESULT_GUIDANCE =
|
|
|
702
744
|
// The empty-set note rides in the LLM-facing `text` ONLY. `details` stays the
|
|
703
745
|
// pure struct: `keywordLane` reads `searchAll` directly (never this layer) and
|
|
704
746
|
// the structured tests assert on `details`, so both must see no `note`.
|
|
705
|
-
function resultToToolResult(result: MemorySearchResult) {
|
|
747
|
+
function resultToToolResult(result: MemorySearchResult, fallbackReason?: string) {
|
|
706
748
|
const isEmpty = 'matches' in result && result.matches.length === 0
|
|
707
|
-
const text =
|
|
749
|
+
const text = JSON.stringify({
|
|
750
|
+
...result,
|
|
751
|
+
...(isEmpty ? { note: EMPTY_RESULT_GUIDANCE } : {}),
|
|
752
|
+
...(fallbackReason === undefined ? {} : { notice: 'Semantic index unavailable; lexical results are shown.' }),
|
|
753
|
+
})
|
|
708
754
|
return {
|
|
709
755
|
content: [{ type: 'text' as const, text }],
|
|
710
756
|
details: result,
|
|
@@ -56,6 +56,8 @@ export const fragmentEventSchema = z
|
|
|
56
56
|
entry: z.string(),
|
|
57
57
|
topic: z.string(),
|
|
58
58
|
body: z.string(),
|
|
59
|
+
// Deliberate main-agent capture; absent on legacy/logger fragments.
|
|
60
|
+
kind: z.literal('explicit').optional(),
|
|
59
61
|
references: z.array(z.string()).optional(),
|
|
60
62
|
// WHO the evidence is attributable to (display name/handle of the speaker).
|
|
61
63
|
// LLM-supplied by the memory-logger, set ONLY when one transcript speaker
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod'
|
|
4
|
+
|
|
5
|
+
const PREFIX = 'memory-page:'
|
|
6
|
+
const cursorSchema = z.object({
|
|
7
|
+
version: z.literal(1),
|
|
8
|
+
file: z.string(),
|
|
9
|
+
entry: z.string().min(1),
|
|
10
|
+
digest: z.string(),
|
|
11
|
+
offset: z.number().int().nonnegative(),
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
export function transcriptDigest(value: string): string {
|
|
15
|
+
return createHash('sha256').update(value).digest('hex')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function encodeTranscriptCursor(path: string, entry: string, text: string, offset: number): string {
|
|
19
|
+
const cursor = { version: 1, file: transcriptDigest(path), entry, digest: transcriptDigest(text), offset }
|
|
20
|
+
return `${PREFIX}${Buffer.from(JSON.stringify(cursor)).toString('base64url')}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function decodeTranscriptCursor(value: string | null): z.infer<typeof cursorSchema> | null {
|
|
24
|
+
if (!value?.startsWith(PREFIX)) return null
|
|
25
|
+
return cursorSchema.parse(JSON.parse(Buffer.from(value.slice(PREFIX.length), 'base64url').toString('utf8')))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function transcriptEntryId(value: string): string {
|
|
29
|
+
return decodeTranscriptCursor(value)?.entry ?? value
|
|
30
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
|
|
3
|
+
import { decodeTranscriptCursor, encodeTranscriptCursor, transcriptDigest } from './transcript-cursor'
|
|
4
|
+
import { projectTranscriptLine } from './transcript-view'
|
|
5
|
+
|
|
6
|
+
// Pack complete projected records where possible. Large records are paged
|
|
7
|
+
// reversibly; the checkpoint includes the next character offset and digest,
|
|
8
|
+
// so an interrupted or changed entry is replayed rather than skipped.
|
|
9
|
+
export const PRELOAD_MAX_BYTES = 256 * 1024
|
|
10
|
+
const MIN_USEFUL_PRELOAD_BYTES = 8 * 1024
|
|
11
|
+
// Byte-level BPE tokenizers emit at most one token per UTF-8 byte, so byte
|
|
12
|
+
// length is a tokenizer-independent upper bound on token count. The overhead
|
|
13
|
+
// covers tool schemas and the preload header; each model's output allowance is
|
|
14
|
+
// reserved separately.
|
|
15
|
+
export const PRELOAD_OVERHEAD_TOKENS = 8192
|
|
16
|
+
// The header lines and <transcript> tags rendered around the slice. They sit in
|
|
17
|
+
// the same user message as the slice, so the slice budget must leave room for
|
|
18
|
+
// them; otherwise a line-granular slice that lands just under its budget
|
|
19
|
+
// overflows the tightest window by the frame's size.
|
|
20
|
+
export const PRELOAD_FRAME_BYTES = 512
|
|
21
|
+
|
|
22
|
+
export type PreloadModelLimits = { contextWindow: number; outputTokens: number }
|
|
23
|
+
|
|
24
|
+
// The preload is one unprocessed user message, so it must fit the smallest
|
|
25
|
+
// model the subagent can fall back to: compaction cannot shrink it and
|
|
26
|
+
// context-overflow errors do not fail over. Returns null when no useful slice
|
|
27
|
+
// fits, so the caller keeps the incremental read loop.
|
|
28
|
+
export function preloadBudgetBytes(models: readonly PreloadModelLimits[], promptBytes: number): number | null {
|
|
29
|
+
if (models.length === 0) return null
|
|
30
|
+
const tightest = Math.min(...models.map((m) => m.contextWindow - m.outputTokens))
|
|
31
|
+
const budget = Math.min(PRELOAD_MAX_BYTES, tightest - promptBytes - PRELOAD_OVERHEAD_TOKENS)
|
|
32
|
+
return budget >= MIN_USEFUL_PRELOAD_BYTES ? budget : null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type TranscriptPreload = {
|
|
36
|
+
text: string
|
|
37
|
+
startLine: number
|
|
38
|
+
endLine: number
|
|
39
|
+
totalLines: number
|
|
40
|
+
truncatedLines: number
|
|
41
|
+
watermarkFound: boolean
|
|
42
|
+
checkpoint: string | null
|
|
43
|
+
startCheckpoint: string | null
|
|
44
|
+
entryIds: string[]
|
|
45
|
+
// First unread line when the byte cap stopped the preload early; null when
|
|
46
|
+
// the preload reaches the end of the transcript.
|
|
47
|
+
nextOffset: number | null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function buildTranscriptPreload(
|
|
51
|
+
path: string,
|
|
52
|
+
watermark: string | null,
|
|
53
|
+
options: { maxBytes?: number; untilLine?: number } = {},
|
|
54
|
+
): Promise<TranscriptPreload | null> {
|
|
55
|
+
const maxBytes = options.maxBytes ?? PRELOAD_MAX_BYTES
|
|
56
|
+
let raw: string
|
|
57
|
+
try {
|
|
58
|
+
raw = await readFile(path, 'utf8')
|
|
59
|
+
} catch {
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
62
|
+
const lines = raw.length === 0 ? [] : raw.split('\n')
|
|
63
|
+
if (lines.length > 0 && lines[lines.length - 1] === '') lines.pop()
|
|
64
|
+
const totalLines = Math.min(lines.length, options.untilLine ?? lines.length)
|
|
65
|
+
|
|
66
|
+
let startIndex = 0
|
|
67
|
+
let startOffset = 0
|
|
68
|
+
let watermarkFound = false
|
|
69
|
+
const cursor = decodeTranscriptCursor(watermark)
|
|
70
|
+
if (watermark !== null) {
|
|
71
|
+
const entryId = cursor?.entry ?? watermark
|
|
72
|
+
const found = lines.findIndex((line) => recordId(line) === entryId)
|
|
73
|
+
if (found !== -1) {
|
|
74
|
+
startIndex = cursor === null ? found + 1 : found
|
|
75
|
+
watermarkFound = true
|
|
76
|
+
if (cursor !== null) {
|
|
77
|
+
const text = projectTranscriptLine(lines[found] ?? '')
|
|
78
|
+
if (
|
|
79
|
+
cursor.file === transcriptDigest(path) &&
|
|
80
|
+
cursor.digest === transcriptDigest(text) &&
|
|
81
|
+
cursor.offset <= text.length &&
|
|
82
|
+
!isInsideSurrogatePair(text, cursor.offset)
|
|
83
|
+
) {
|
|
84
|
+
startOffset = cursor.offset
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const out: string[] = []
|
|
91
|
+
const entryIds: string[] = []
|
|
92
|
+
let bytes = 0
|
|
93
|
+
let checkpoint = watermark
|
|
94
|
+
const firstId = recordId(lines[startIndex] ?? '')
|
|
95
|
+
const startCheckpoint =
|
|
96
|
+
firstId === null
|
|
97
|
+
? null
|
|
98
|
+
: encodeTranscriptCursor(path, firstId, projectTranscriptLine(lines[startIndex] ?? ''), startOffset)
|
|
99
|
+
let partial = false
|
|
100
|
+
let index = startIndex
|
|
101
|
+
for (; index < totalLines; index++) {
|
|
102
|
+
const source = lines[index] ?? ''
|
|
103
|
+
const id = recordId(source)
|
|
104
|
+
// A live writer's incomplete tail is never acknowledged.
|
|
105
|
+
if (id === null) break
|
|
106
|
+
const text = projectTranscriptLine(source)
|
|
107
|
+
const offset = index === startIndex ? startOffset : 0
|
|
108
|
+
const separatorBytes = out.length === 0 ? 0 : 1
|
|
109
|
+
if (offset === 0 && bytes + separatorBytes + Buffer.byteLength(text, 'utf8') <= maxBytes) {
|
|
110
|
+
out.push(text)
|
|
111
|
+
entryIds.push(id)
|
|
112
|
+
bytes += separatorBytes + Buffer.byteLength(text, 'utf8')
|
|
113
|
+
checkpoint = id
|
|
114
|
+
continue
|
|
115
|
+
}
|
|
116
|
+
if (out.length > 0) break
|
|
117
|
+
|
|
118
|
+
const context = entryContext(text)
|
|
119
|
+
// Read-only overlap lets a fresh session interpret facts split at the
|
|
120
|
+
// boundary. Reserve most of even a small page for new progress.
|
|
121
|
+
let overlapStart = Math.max(0, offset - Math.min(2048, Math.floor(maxBytes / 16)))
|
|
122
|
+
if (isInsideSurrogatePair(text, overlapStart)) overlapStart++
|
|
123
|
+
const precedingText = offset > 0 ? text.slice(overlapStart, offset) : undefined
|
|
124
|
+
let low = offset
|
|
125
|
+
let high = text.length
|
|
126
|
+
while (low < high) {
|
|
127
|
+
const middle = Math.ceil((low + high) / 2)
|
|
128
|
+
const part = JSON.stringify({
|
|
129
|
+
type: 'entry-part',
|
|
130
|
+
id,
|
|
131
|
+
context,
|
|
132
|
+
offset,
|
|
133
|
+
precedingText,
|
|
134
|
+
text: text.slice(offset, middle),
|
|
135
|
+
})
|
|
136
|
+
if (Buffer.byteLength(part, 'utf8') <= maxBytes) low = middle
|
|
137
|
+
else high = middle - 1
|
|
138
|
+
}
|
|
139
|
+
const end = isInsideSurrogatePair(text, low) ? low - 1 : low
|
|
140
|
+
if (end <= offset) throw new Error('Memory transcript page budget cannot hold the next character.')
|
|
141
|
+
out.push(JSON.stringify({ type: 'entry-part', id, context, offset, precedingText, text: text.slice(offset, end) }))
|
|
142
|
+
entryIds.push(id)
|
|
143
|
+
checkpoint = end === text.length ? id : encodeTranscriptCursor(path, id, text, end)
|
|
144
|
+
partial = end < text.length
|
|
145
|
+
if (end === text.length) index++
|
|
146
|
+
break
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
text: out.join('\n'),
|
|
151
|
+
startLine: startIndex + 1,
|
|
152
|
+
endLine: index + (partial ? 1 : 0),
|
|
153
|
+
totalLines,
|
|
154
|
+
truncatedLines: 0,
|
|
155
|
+
watermarkFound,
|
|
156
|
+
checkpoint,
|
|
157
|
+
startCheckpoint,
|
|
158
|
+
entryIds,
|
|
159
|
+
nextOffset: index < totalLines ? index + 1 : null,
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function entryContext(text: string): Record<string, unknown> {
|
|
164
|
+
const entry: unknown = JSON.parse(text)
|
|
165
|
+
if (!isRecord(entry)) return {}
|
|
166
|
+
const context: Record<string, unknown> = {}
|
|
167
|
+
for (const key of ['parentId', 'timestamp']) {
|
|
168
|
+
if (key in entry) context[key] = entry[key]
|
|
169
|
+
}
|
|
170
|
+
if (isRecord(entry.message)) {
|
|
171
|
+
for (const key of [
|
|
172
|
+
'role',
|
|
173
|
+
'timestamp',
|
|
174
|
+
'toolCallId',
|
|
175
|
+
'toolName',
|
|
176
|
+
'isError',
|
|
177
|
+
'stopReason',
|
|
178
|
+
'authorId',
|
|
179
|
+
'authorName',
|
|
180
|
+
'who',
|
|
181
|
+
'where',
|
|
182
|
+
]) {
|
|
183
|
+
if (key in entry.message) context[`message.${key}`] = entry.message[key]
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return context
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
190
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function recordId(line: string): string | null {
|
|
194
|
+
try {
|
|
195
|
+
const entry: unknown = JSON.parse(line)
|
|
196
|
+
if (typeof entry !== 'object' || entry === null || !('id' in entry)) return null
|
|
197
|
+
return typeof entry.id === 'string' ? entry.id : null
|
|
198
|
+
} catch (error) {
|
|
199
|
+
if (error instanceof SyntaxError) return null
|
|
200
|
+
throw error
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function isInsideSurrogatePair(text: string, offset: number): boolean {
|
|
205
|
+
const before = text.charCodeAt(offset - 1)
|
|
206
|
+
const after = text.charCodeAt(offset)
|
|
207
|
+
return before >= 0xd800 && before <= 0xdbff && after >= 0xdc00 && after <= 0xdfff
|
|
208
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// This is an extractor view only. The source transcript and its replay
|
|
2
|
+
// signatures remain authoritative and are never rewritten.
|
|
3
|
+
export function projectTranscriptLine(line: string): string {
|
|
4
|
+
let entry: unknown
|
|
5
|
+
try {
|
|
6
|
+
entry = JSON.parse(line)
|
|
7
|
+
} catch (error) {
|
|
8
|
+
if (error instanceof SyntaxError) return line
|
|
9
|
+
throw error
|
|
10
|
+
}
|
|
11
|
+
if (!isRecord(entry) || !isRecord(entry.message)) return line
|
|
12
|
+
if (entry.message.role !== 'assistant') return line
|
|
13
|
+
|
|
14
|
+
const message = { ...entry.message }
|
|
15
|
+
for (const key of ['usage', 'api', 'provider', 'model', 'responseId']) delete message[key]
|
|
16
|
+
if (Array.isArray(message.content)) {
|
|
17
|
+
message.content = message.content.map((block: unknown) => {
|
|
18
|
+
if (!isRecord(block)) return block
|
|
19
|
+
if (block.type === 'toolCall') {
|
|
20
|
+
const content = { ...block }
|
|
21
|
+
delete content.thoughtSignature
|
|
22
|
+
return content
|
|
23
|
+
}
|
|
24
|
+
if (block.type !== 'text' && block.type !== 'thinking') return block
|
|
25
|
+
const content = { ...block }
|
|
26
|
+
delete content.thinkingSignature
|
|
27
|
+
delete content.textSignature
|
|
28
|
+
return content
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
return JSON.stringify({ ...entry, message })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
35
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
36
|
+
}
|
|
@@ -136,11 +136,9 @@ export async function hybridSearch(
|
|
|
136
136
|
return fuseLanes(vectorRows, keywordMatches, index, parentSlugsByFragmentId).slice(0, topK)
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
// ambient band; sparse streams consume the band but never define it, so a
|
|
143
|
-
// nearest-neighbour cluster of fragments can't move the bar).
|
|
139
|
+
// Only topics define the topic gate and the stream admission band. Reference
|
|
140
|
+
// chunks can form an elevated, flat cluster even on a content-free query;
|
|
141
|
+
// pooling that cluster with topics would let it admit unrelated topic neighbours.
|
|
144
142
|
//
|
|
145
143
|
// - Topic rows: the gate keeps the knee above the band, or empties the topic
|
|
146
144
|
// partition entirely when no topic clears it.
|
|
@@ -148,16 +146,17 @@ export async function hybridSearch(
|
|
|
148
146
|
// the shared margin. A genuine fresh fragment (well above the band) survives
|
|
149
147
|
// the freshness window; an irrelevant in-band neighbour is dropped, so a
|
|
150
148
|
// no-match query can't leak closest-neighbours-regardless through streams.
|
|
149
|
+
// - Reference rows: must clear both the topic band and the reference chunk
|
|
150
|
+
// band by the strict margin. A uniformly elevated reference cluster is not
|
|
151
|
+
// evidence of a match, even when it stands above the topic band. Unlike
|
|
152
|
+
// gateRelevance, this admission check has no small-reference-set exemption.
|
|
151
153
|
//
|
|
152
154
|
// Topic suppression uses the floor-gated verdict (gateRelevance): below the
|
|
153
155
|
// floor topics pass ungated, since a tiny index can't form a reliable band and
|
|
154
|
-
// a false negative is cheaper than suppressing the only memory.
|
|
155
|
-
//
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
// exist at all. A lexically-corroborated fragment still reaches RRF via the
|
|
159
|
-
// separate keyword lane. An empty merged lane composes with RRF exactly like a
|
|
160
|
-
// lane that found nothing, so a genuine keyword hit survives a full no-match.
|
|
156
|
+
// a false negative is cheaper than suppressing the only memory. With fewer
|
|
157
|
+
// than two topics there is no topic admission baseline: streams remain closed,
|
|
158
|
+
// while references use their own floor-gated verdict so a tiny reference-only
|
|
159
|
+
// index is not hidden. Keyword hits remain independent of every vector verdict.
|
|
161
160
|
function gatedVectorLane(
|
|
162
161
|
queryEmbeddings: Float32Array[],
|
|
163
162
|
queryChunks: string[],
|
|
@@ -169,7 +168,8 @@ function gatedVectorLane(
|
|
|
169
168
|
const allScored = maxScoreAcrossChunks(queryEmbeddings, store)
|
|
170
169
|
const scored = allScored.scored.filter(({ row }) => vectorRowIsAuthorized(row, index, parentSlugsByFragmentId))
|
|
171
170
|
const { winnerChunkByRowId } = allScored
|
|
172
|
-
const bandDefiningRows = scored.filter(({ row }) => row.source === 'topic'
|
|
171
|
+
const bandDefiningRows = scored.filter(({ row }) => row.source === 'topic')
|
|
172
|
+
const referenceRows = scored.filter(({ row }) => row.source === 'reference')
|
|
173
173
|
const streamRows = scored.filter(({ row }) => row.source === 'stream')
|
|
174
174
|
|
|
175
175
|
// The cross-script verdict is judged against the HEAD of the scored band — the
|
|
@@ -199,7 +199,18 @@ function gatedVectorLane(
|
|
|
199
199
|
const streamBaseline = streamAdmissionBaseline(bandScores)
|
|
200
200
|
const keptStreams = streamRows.filter(({ score }) => clearsBaseline(score, streamBaseline)).slice(0, topK * 2)
|
|
201
201
|
|
|
202
|
-
|
|
202
|
+
const referenceScores = referenceRows.map(({ score }) => score)
|
|
203
|
+
const referenceBaseline = streamAdmissionBaseline(referenceScores)
|
|
204
|
+
const keptReferences =
|
|
205
|
+
streamBaseline === null
|
|
206
|
+
? referenceRows.slice(0, gateRelevance(referenceScores, topK * 2))
|
|
207
|
+
: referenceRows
|
|
208
|
+
.filter(({ score }) => clearsBaseline(score, Math.max(streamBaseline, referenceBaseline ?? streamBaseline)))
|
|
209
|
+
.slice(0, topK * 2)
|
|
210
|
+
|
|
211
|
+
return [...keptBandDefiningRows, ...keptStreams, ...keptReferences]
|
|
212
|
+
.sort((a, b) => b.score - a.score)
|
|
213
|
+
.map(({ row }) => row)
|
|
203
214
|
}
|
|
204
215
|
|
|
205
216
|
function vectorRowIsAuthorized(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readdir } from 'node:fs/promises'
|
|
2
2
|
import { join } from 'node:path'
|
|
3
3
|
|
|
4
|
+
import type { StreamEvent } from './stream-events'
|
|
4
5
|
import { readEvents } from './stream-io'
|
|
5
6
|
|
|
6
7
|
// Daily stream files are named `YYYY-MM-DD.jsonl` (see `formatLocalDate` in
|
|
@@ -11,13 +12,8 @@ const DAILY_STREAM_NAME = /^\d{4}-\d{2}-\d{2}\.jsonl$/
|
|
|
11
12
|
export async function readWatermarkFromFile(streamFilePath: string, parentSessionId: string): Promise<string | null> {
|
|
12
13
|
const events = await readEvents(streamFilePath)
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if ((event.type === 'fragment' || event.type === 'watermark') && event.source === parentSessionId) {
|
|
17
|
-
lastEntryId = event.entry
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return lastEntryId
|
|
15
|
+
const progress = findProgress(events, parentSessionId)
|
|
16
|
+
return progress.checkpoint ?? progress.legacy
|
|
21
17
|
}
|
|
22
18
|
|
|
23
19
|
// Returns the latest watermark entry id for `parentSessionId` across all
|
|
@@ -47,9 +43,22 @@ export async function readLatestWatermark(memoryDir: string, parentSessionId: st
|
|
|
47
43
|
const dailyStreams = entries
|
|
48
44
|
.filter((name) => DAILY_STREAM_NAME.test(name))
|
|
49
45
|
.sort((a, b) => (a < b ? 1 : a > b ? -1 : 0))
|
|
46
|
+
let legacy: string | null = null
|
|
50
47
|
for (const name of dailyStreams) {
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
48
|
+
const progress = findProgress(await readEvents(join(memoryDir, name)), parentSessionId)
|
|
49
|
+
if (progress.checkpoint !== null) return progress.checkpoint
|
|
50
|
+
legacy ??= progress.legacy
|
|
51
|
+
}
|
|
52
|
+
return legacy
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function findProgress(events: StreamEvent[], source: string): { checkpoint: string | null; legacy: string | null } {
|
|
56
|
+
let checkpoint: string | null = null
|
|
57
|
+
let legacy: string | null = null
|
|
58
|
+
for (const event of events) {
|
|
59
|
+
if (event.type === 'watermark' && event.source === source) checkpoint = event.entry
|
|
60
|
+
// Explicit captures have not evaluated the logger's pending transcript.
|
|
61
|
+
if (event.type === 'fragment' && event.kind !== 'explicit' && event.source === source) legacy = event.entry
|
|
53
62
|
}
|
|
54
|
-
return
|
|
63
|
+
return { checkpoint, legacy }
|
|
55
64
|
}
|
|
@@ -195,6 +195,12 @@ export const reviewerPayloadSchema = z
|
|
|
195
195
|
requestId: z.string().optional(),
|
|
196
196
|
prompt: z.string().optional(),
|
|
197
197
|
description: z.string().optional(),
|
|
198
|
+
skill: z
|
|
199
|
+
.enum(REVIEWER_SKILLS.map((skill) => skill.name))
|
|
200
|
+
.optional()
|
|
201
|
+
.describe(
|
|
202
|
+
'One curated review skill to preload. Omit for ambiguous or unspecified domains; load_skill remains available.',
|
|
203
|
+
),
|
|
198
204
|
reviewIdentity: reviewerReviewIdentitySchema.optional(),
|
|
199
205
|
})
|
|
200
206
|
.passthrough()
|
|
@@ -230,6 +236,20 @@ If none of the listed skills fit the target, load \`general\`. Keep the skill-se
|
|
|
230
236
|
...(options === undefined ? [] : [createReviewerCheckoutTool(options.resolveTokenForRepo)]),
|
|
231
237
|
],
|
|
232
238
|
payloadSchema: reviewerPayloadSchema,
|
|
239
|
+
handler: async ({ payload }, runSession) => {
|
|
240
|
+
const skill = REVIEWER_SKILLS.find((candidate) => candidate.name === payload.skill)
|
|
241
|
+
await runSession(
|
|
242
|
+
skill === undefined
|
|
243
|
+
? undefined
|
|
244
|
+
: {
|
|
245
|
+
systemPrompt:
|
|
246
|
+
`${REVIEWER_SYSTEM_PROMPT}\n\n## Preloaded review skill: ${skill.name}\n\n` +
|
|
247
|
+
'The following curated skill is already loaded. Apply it directly; skip the initial load_skill call. ' +
|
|
248
|
+
'Keep load_skill for an additional domain only when the target requires it.\n\n' +
|
|
249
|
+
skill.content,
|
|
250
|
+
},
|
|
251
|
+
)
|
|
252
|
+
},
|
|
233
253
|
visibility: 'public',
|
|
234
254
|
rosterDescription:
|
|
235
255
|
'deep read-only code/PR/plan review in a fresh context, returns a structured verdict; it does NOT post — you act on its findings',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SecuritySeverity } from '../permissions'
|
|
2
2
|
import type { SecurityBlock } from '../policy'
|
|
3
|
+
import { outboundTexts } from './outbound-text'
|
|
3
4
|
|
|
4
5
|
export const GUARD_OUTBOUND_SECRET = 'outboundSecret'
|
|
5
6
|
// Classified `high` (audience-leak axis): bypass posts credential-shaped
|
|
@@ -60,6 +61,7 @@ const PROCESS_ENV_TARGETS: ReadonlyArray<string> = [
|
|
|
60
61
|
'MOONSHOT_API_KEY',
|
|
61
62
|
'MOONSHOT_CODING_API_KEY',
|
|
62
63
|
'INCEPTION_API_KEY',
|
|
64
|
+
'EXAONE_API_KEY',
|
|
63
65
|
'GOOGLE_API_KEY',
|
|
64
66
|
'GEMINI_API_KEY',
|
|
65
67
|
'AWS_ACCESS_KEY_ID',
|
|
@@ -95,8 +97,6 @@ const ENV_KEY_RECON_MATCHERS: ReadonlyArray<readonly [name: string, pattern: Reg
|
|
|
95
97
|
(name) => [name, new RegExp(`\\b${name}\\b`)] as const,
|
|
96
98
|
)
|
|
97
99
|
|
|
98
|
-
const TEXT_KEYS = ['text', 'message', 'content', 'body']
|
|
99
|
-
|
|
100
100
|
export type OutboundSecretMatch = {
|
|
101
101
|
kind: string
|
|
102
102
|
source: 'signature' | 'process_env' | 'env_key_recon'
|
|
@@ -156,11 +156,8 @@ export function checkOutboundSecretGuard(options: {
|
|
|
156
156
|
env?: NodeJS.ProcessEnv
|
|
157
157
|
}): SecurityBlock | undefined {
|
|
158
158
|
const { tool, args } = options
|
|
159
|
-
if (tool !== 'channel_send' && tool !== 'channel_reply') return undefined
|
|
160
159
|
const env = options.env ?? process.env
|
|
161
|
-
for (const
|
|
162
|
-
const value = args[key]
|
|
163
|
-
if (typeof value !== 'string' || value.length === 0) continue
|
|
160
|
+
for (const value of outboundTexts(tool, args)) {
|
|
164
161
|
const matches = findOutboundSecrets(value, env)
|
|
165
162
|
if (matches.length === 0) continue
|
|
166
163
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { analyzeAgentMessengerCommand } from '@/bundled-plugins/agent-messenger-cli-auth/command'
|
|
2
|
+
|
|
3
|
+
const CHANNEL_TEXT_KEYS = ['text', 'message', 'content', 'body']
|
|
4
|
+
|
|
5
|
+
// The texts a tool call would post to a chat. A bot CLI command that
|
|
6
|
+
// agent-messenger-cli-auth would lend a channel token to posts its argv as the
|
|
7
|
+
// agent, so the audience-leak guards scan those arguments exactly as they scan
|
|
8
|
+
// channel_send text; otherwise that bash path would bypass them.
|
|
9
|
+
export function outboundTexts(tool: string, args: Record<string, unknown>): string[] {
|
|
10
|
+
if (tool === 'channel_send' || tool === 'channel_reply') {
|
|
11
|
+
return CHANNEL_TEXT_KEYS.map((key) => args[key]).filter(
|
|
12
|
+
(value): value is string => typeof value === 'string' && value.length > 0,
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
if (tool === 'bash' && typeof args.command === 'string') {
|
|
16
|
+
const decision = analyzeAgentMessengerCommand(args.command)
|
|
17
|
+
if (decision.kind === 'mint') return decision.args.filter((arg) => arg.length > 0)
|
|
18
|
+
}
|
|
19
|
+
return []
|
|
20
|
+
}
|