typeclaw 0.45.0 → 0.46.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/README.md +1 -1
- package/package.json +3 -2
- package/src/agent/git-nudge.ts +2 -1
- package/src/agent/index.ts +67 -25
- package/src/agent/live-subagents.ts +18 -0
- package/src/agent/loop-guard.ts +208 -10
- package/src/agent/multimodal/index.ts +1 -1
- package/src/agent/multimodal/look-at.ts +78 -44
- package/src/agent/multimodal/looker.ts +151 -39
- package/src/agent/network/response-body.ts +26 -0
- package/src/agent/network/safe-http.ts +198 -0
- package/src/agent/plugin-tools.ts +438 -162
- package/src/agent/provider-error.ts +62 -4
- package/src/agent/restart/index.ts +61 -40
- package/src/agent/restart-handoff/index.ts +73 -4
- package/src/agent/retry-same-ref.ts +66 -0
- package/src/agent/reviewer-bash-policy.ts +42 -1
- package/src/agent/session-origin.ts +2 -0
- package/src/agent/subagent-drain.ts +117 -7
- package/src/agent/subagents.ts +77 -18
- package/src/agent/throttle-circuit.ts +25 -5
- package/src/agent/tool-error-remediation.ts +72 -0
- package/src/agent/tool-file-safety.ts +1050 -0
- package/src/agent/tools/channel-fetch-attachment.ts +10 -3
- package/src/agent/tools/channel-reply.ts +15 -1
- package/src/agent/tools/channel-send.ts +17 -1
- package/src/agent/tools/ddg.ts +16 -2
- package/src/agent/tools/post-github-review.ts +199 -0
- package/src/agent/tools/spawn-subagent.ts +21 -18
- package/src/agent/tools/webfetch/fetch.ts +143 -183
- package/src/agent/tools/webfetch/tool.ts +2 -3
- package/src/agent/tools/websearch.ts +23 -2
- package/src/agent/tools-without-local-file-operands.ts +27 -0
- package/src/agent/turn-runner.ts +109 -15
- package/src/bundled-plugins/backup/index.ts +2 -1
- package/src/bundled-plugins/backup/runner.ts +2 -1
- package/src/bundled-plugins/doc-render/render.ts +93 -12
- package/src/bundled-plugins/doc-render/skills/typeclaw-render-pdf/SKILL.md +13 -13
- package/src/bundled-plugins/github-cli-auth/effective-approval.ts +16 -6
- package/src/bundled-plugins/github-cli-auth/gh-command.ts +555 -15
- package/src/bundled-plugins/github-cli-auth/index.ts +131 -135
- package/src/bundled-plugins/github-cli-auth/review-checkout.ts +138 -0
- package/src/bundled-plugins/guard/policies/uncommitted-changes.ts +2 -1
- package/src/bundled-plugins/memory/README.md +23 -11
- package/src/bundled-plugins/memory/append-tool.ts +15 -8
- package/src/bundled-plugins/memory/citations.ts +22 -9
- package/src/bundled-plugins/memory/dreaming.ts +13 -8
- package/src/bundled-plugins/memory/find-entry-tool.ts +4 -0
- package/src/bundled-plugins/memory/index.ts +0 -4
- package/src/bundled-plugins/memory/load-memory.ts +8 -3
- package/src/bundled-plugins/memory/provenance-index.ts +717 -0
- package/src/bundled-plugins/memory/provenance-sanitize.ts +40 -0
- package/src/bundled-plugins/memory/references/store-reference-tool.ts +4 -0
- package/src/bundled-plugins/memory/search-tool.ts +163 -60
- package/src/bundled-plugins/memory/stream-events.ts +2 -0
- package/src/bundled-plugins/memory/vector/hybrid.ts +126 -13
- package/src/bundled-plugins/researcher/write-report.ts +6 -3
- package/src/bundled-plugins/reviewer/index.ts +2 -2
- package/src/bundled-plugins/reviewer/reviewer.ts +10 -3
- package/src/bundled-plugins/reviewer/skills/code-review.ts +24 -9
- package/src/bundled-plugins/scout/scout.ts +8 -0
- package/src/bundled-plugins/security/index.ts +4 -4
- package/src/bundled-plugins/security/policies/outbound-secret-scan.ts +1 -0
- package/src/bundled-plugins/security/policies/private-surface-read.ts +220 -29
- package/src/bundled-plugins/security/policies/secret-exfil-read.ts +1 -0
- package/src/bundled-plugins/security/policies/ssrf.ts +29 -9
- package/src/channels/adapters/discord-bot-channel-resolver.ts +26 -14
- package/src/channels/adapters/discord-bot-thread-room.ts +44 -12
- package/src/channels/adapters/discord-bot.ts +91 -10
- package/src/channels/adapters/discord-channel-resolver.ts +91 -23
- package/src/channels/adapters/discord-id.ts +4 -0
- package/src/channels/adapters/discord-resolver-cache.ts +41 -0
- package/src/channels/adapters/discord.ts +57 -7
- package/src/channels/adapters/github/auth-app.ts +41 -12
- package/src/channels/adapters/github/index.ts +23 -11
- package/src/channels/adapters/github/review-submitter.ts +302 -0
- package/src/channels/adapters/kakaotalk-channel-resolver.ts +12 -1
- package/src/channels/adapters/kakaotalk-fetch-attachment.ts +8 -4
- package/src/channels/adapters/kakaotalk-typing.ts +127 -0
- package/src/channels/adapters/kakaotalk.ts +19 -0
- package/src/channels/adapters/slack-attachment-download.ts +71 -0
- package/src/channels/adapters/slack-bot.ts +19 -8
- package/src/channels/adapters/slack-classify.ts +21 -2
- package/src/channels/adapters/slack.ts +59 -7
- package/src/channels/adapters/telegram-bot.ts +18 -5
- package/src/channels/adapters/webex-bot.ts +8 -3
- package/src/channels/adapters/webex.ts +8 -3
- package/src/channels/fetch-attachment.ts +43 -0
- package/src/{bundled-plugins/github-cli-auth/approve-idempotency.ts → channels/github-review-verdict-coordinator.ts} +25 -1
- package/src/channels/github-token-bridge.ts +10 -3
- package/src/channels/manager.ts +9 -0
- package/src/channels/router.ts +568 -12
- package/src/channels/types.ts +28 -1
- package/src/cli/channel.ts +1 -1
- package/src/cli/init.ts +1 -1
- package/src/cli/model.ts +57 -7
- package/src/compose/stop.ts +17 -5
- package/src/config/config.ts +6 -6
- package/src/config/models-mutation.ts +13 -1
- package/src/config/providers.ts +176 -0
- package/src/container/start.ts +49 -10
- package/src/doctor/checks.ts +3 -1
- package/src/doctor/commit.ts +2 -1
- package/src/doctor/file-ownership.ts +52 -0
- package/src/dreams/git.ts +2 -1
- package/src/git/hookless.ts +5 -0
- package/src/git/reconcile-ignored.ts +18 -5
- package/src/git/secret-history.ts +371 -0
- package/src/git/system-commit.ts +12 -6
- package/src/init/dockerfile.ts +86 -5
- package/src/init/index.ts +17 -5
- package/src/init/models-dev.ts +4 -0
- package/src/init/validate-api-key.ts +2 -0
- package/src/mcp/tools.ts +16 -3
- package/src/permissions/builtins.ts +3 -1
- package/src/plugin/context.ts +2 -0
- package/src/plugin/index.ts +1 -0
- package/src/plugin/manager.ts +4 -0
- package/src/plugin/types.ts +21 -0
- package/src/run/index.ts +40 -0
- package/src/run/llm-fetch-observer.ts +188 -13
- package/src/sandbox/build.ts +37 -15
- package/src/sandbox/canonical-secrets.ts +18 -0
- package/src/sandbox/env-exposure.ts +80 -0
- package/src/sandbox/errors.ts +13 -6
- package/src/sandbox/hidden-paths.ts +102 -44
- package/src/sandbox/index.ts +22 -4
- package/src/sandbox/package-install.ts +3 -27
- package/src/sandbox/policy.ts +11 -25
- package/src/sandbox/privileged-runtime.ts +255 -0
- package/src/sandbox/session-tmp.ts +8 -2
- package/src/sandbox/writable-zones.ts +204 -140
- package/src/secrets/index.ts +8 -0
- package/src/secrets/refresh-provider-oauth.ts +128 -0
- package/src/server/command-runner.ts +48 -4
- package/src/server/index.ts +4 -0
- package/src/skills/typeclaw-channel-github/SKILL.md +49 -56
- package/src/skills/typeclaw-claude-code/SKILL.md +24 -60
- package/src/skills/typeclaw-claude-code/references/auth-flow.md +17 -158
- package/src/skills/typeclaw-codex-cli/SKILL.md +19 -49
- package/src/skills/typeclaw-codex-cli/references/auth-flow.md +17 -154
- package/src/skills/typeclaw-config/SKILL.md +5 -5
- package/src/skills/typeclaw-config/references/recommended-mounts.md +24 -24
- package/src/skills/typeclaw-github-contributing/SKILL.md +23 -26
- package/src/skills/typeclaw-memory/SKILL.md +9 -3
- package/src/skills/typeclaw-permissions/SKILL.md +19 -15
- package/typeclaw.schema.json +20 -0
|
@@ -9,6 +9,7 @@ import { formatLocalDate } from '@/shared'
|
|
|
9
9
|
|
|
10
10
|
import { fragmentContentHash } from './fragment-parser'
|
|
11
11
|
import { streamFilePath } from './paths'
|
|
12
|
+
import { sanitizeProvenanceName } from './provenance-sanitize'
|
|
12
13
|
import { detectSecrets } from './secret-detector'
|
|
13
14
|
import { newEventId, timestampFromId } from './stream-events'
|
|
14
15
|
import type { FragmentEvent, FragmentProvenance, WatermarkEvent } from './stream-events'
|
|
@@ -52,18 +53,16 @@ export function provenanceFromOrigin(origin: SessionOrigin | undefined): Fragmen
|
|
|
52
53
|
// so a credential-shaped name is dropped rather than thrown — keep the raw id,
|
|
53
54
|
// never let the leaky display string reach git. Raw ids are platform-issued
|
|
54
55
|
// identifiers, not free text, so they are not scanned.
|
|
55
|
-
const workspaceName =
|
|
56
|
-
const chatName =
|
|
56
|
+
const workspaceName = sanitizeProvenanceName(origin.workspaceName)
|
|
57
|
+
const chatName = sanitizeProvenanceName(origin.chatName)
|
|
58
|
+
const parentChatName = sanitizeProvenanceName(origin.parentChatName)
|
|
57
59
|
if (workspaceName !== undefined) where.workspaceName = workspaceName
|
|
58
60
|
if (chatName !== undefined) where.chatName = chatName
|
|
61
|
+
if (origin.parentChat !== undefined) where.parentChat = origin.parentChat
|
|
62
|
+
if (parentChatName !== undefined) where.parentChatName = parentChatName
|
|
59
63
|
return where
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
function redactIfSecret(name: string | undefined): string | undefined {
|
|
63
|
-
if (name === undefined) return undefined
|
|
64
|
-
return detectSecrets(name).length === 0 ? name : undefined
|
|
65
|
-
}
|
|
66
|
-
|
|
67
66
|
export function createAppendTool(options: CreateAppendToolOptions = {}) {
|
|
68
67
|
const { onFragmentsAppended, originProvider, referenceSlugResolver } = options
|
|
69
68
|
return defineTool({
|
|
@@ -78,6 +77,13 @@ export function createAppendTool(options: CreateAppendToolOptions = {}) {
|
|
|
78
77
|
references: z.array(z.string()).optional(),
|
|
79
78
|
who: z.string().min(1).optional(),
|
|
80
79
|
}),
|
|
80
|
+
// None of these is a local path — topic/body are prose, the rest are session/
|
|
81
|
+
// entry/reference ids. The runtime chooses the stream filename; the tool never
|
|
82
|
+
// opens a caller path. Declared so a body carrying "/" or a slug/id that
|
|
83
|
+
// collides with an agent-root dir name is not misread as a file operand.
|
|
84
|
+
fileOperands: {
|
|
85
|
+
nonFile: ['topic', 'body', 'source', 'entry', 'latestEntryId', 'references', 'who'],
|
|
86
|
+
},
|
|
81
87
|
async execute({ topic, body, source, entry, latestEntryId, references, who }, ctx) {
|
|
82
88
|
const streamPath = dailyStreamPath(ctx.agentDir)
|
|
83
89
|
const where = provenanceFromOrigin(originProvider?.())
|
|
@@ -116,7 +122,8 @@ export function createAppendTool(options: CreateAppendToolOptions = {}) {
|
|
|
116
122
|
if (validReferences.length > 0) {
|
|
117
123
|
fragment.references = validReferences
|
|
118
124
|
}
|
|
119
|
-
|
|
125
|
+
const safeWho = sanitizeProvenanceName(who)
|
|
126
|
+
if (safeWho !== undefined) fragment.who = safeWho
|
|
120
127
|
if (where !== undefined) fragment.where = where
|
|
121
128
|
const watermark: WatermarkEvent = {
|
|
122
129
|
type: 'watermark',
|
|
@@ -87,9 +87,11 @@ const SECTION_HEADING = /^[\s-]*(fragments|superseded)\s*:\s*$/i
|
|
|
87
87
|
|
|
88
88
|
export type SectionedCitations = { active: Set<string>; superseded: Set<string> }
|
|
89
89
|
|
|
90
|
-
export
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
export type SectionedCitationRefs = { active: Citation[]; superseded: Citation[] }
|
|
91
|
+
|
|
92
|
+
export function splitCitationRefsBySection(body: string): SectionedCitationRefs {
|
|
93
|
+
const active = new Map<string, Citation>()
|
|
94
|
+
const superseded = new Map<string, Citation>()
|
|
93
95
|
let current: 'active' | 'superseded' = 'active'
|
|
94
96
|
|
|
95
97
|
for (const line of body.split('\n')) {
|
|
@@ -98,13 +100,24 @@ export function splitCitationsBySection(body: string): SectionedCitations {
|
|
|
98
100
|
current = heading[1]!.toLowerCase() === 'superseded' ? 'superseded' : 'active'
|
|
99
101
|
continue
|
|
100
102
|
}
|
|
101
|
-
const
|
|
102
|
-
if (
|
|
103
|
-
|
|
103
|
+
const match = CITATION_LINE.exec(line)
|
|
104
|
+
if (match === null) continue
|
|
105
|
+
const citation = { date: match[2]!, fragmentId: match[3]! }
|
|
106
|
+
const canonical = formatCitation(citation.date, citation.fragmentId)
|
|
107
|
+
;(current === 'superseded' ? superseded : active).set(canonical, citation)
|
|
104
108
|
}
|
|
105
109
|
|
|
106
|
-
|
|
107
|
-
for (const
|
|
110
|
+
const activeIds = new Set([...active.values()].map((citation) => citation.fragmentId))
|
|
111
|
+
for (const [canonical, citation] of superseded) {
|
|
112
|
+
if (activeIds.has(citation.fragmentId)) superseded.delete(canonical)
|
|
113
|
+
}
|
|
114
|
+
return { active: [...active.values()], superseded: [...superseded.values()] }
|
|
115
|
+
}
|
|
108
116
|
|
|
109
|
-
|
|
117
|
+
export function splitCitationsBySection(body: string): SectionedCitations {
|
|
118
|
+
const refs = splitCitationRefsBySection(body)
|
|
119
|
+
return {
|
|
120
|
+
active: new Set(refs.active.map((citation) => citation.fragmentId)),
|
|
121
|
+
superseded: new Set(refs.superseded.map((citation) => citation.fragmentId)),
|
|
122
|
+
}
|
|
110
123
|
}
|
|
@@ -5,6 +5,7 @@ import { basename, join } from 'node:path'
|
|
|
5
5
|
|
|
6
6
|
import { z } from 'zod'
|
|
7
7
|
|
|
8
|
+
import { hooklessGitArgs } from '@/git/hookless'
|
|
8
9
|
import { withGitLock } from '@/git/mutex'
|
|
9
10
|
import { type AgentGit, resolveAgentGit } from '@/git/resolve-agent-git'
|
|
10
11
|
import { defineTool, lsTool, readTool, type Subagent, writeTool } from '@/plugin'
|
|
@@ -773,7 +774,7 @@ async function commitMemorySnapshotUnlocked(cwd: string): Promise<void> {
|
|
|
773
774
|
}
|
|
774
775
|
|
|
775
776
|
const add = bun.spawn({
|
|
776
|
-
cmd: ['git', ...repo.gitArgs, 'add', '-f', '--', ...presentPaths],
|
|
777
|
+
cmd: ['git', ...hooklessGitArgs([...repo.gitArgs, 'add', '-f', '--', ...presentPaths])],
|
|
777
778
|
cwd,
|
|
778
779
|
stdout: 'pipe',
|
|
779
780
|
stderr: 'pipe',
|
|
@@ -788,7 +789,10 @@ async function commitMemorySnapshotUnlocked(cwd: string): Promise<void> {
|
|
|
788
789
|
// fails outright when `bar/` matches no tracked file, even if `foo` is
|
|
789
790
|
// staged.
|
|
790
791
|
const stagedNames = bun.spawn({
|
|
791
|
-
cmd: [
|
|
792
|
+
cmd: [
|
|
793
|
+
'git',
|
|
794
|
+
...hooklessGitArgs([...repo.gitArgs, 'diff', '--cached', '--name-only', '-z', '--', ...SNAPSHOT_PATHS]),
|
|
795
|
+
],
|
|
792
796
|
cwd,
|
|
793
797
|
stdout: 'pipe',
|
|
794
798
|
stderr: 'pipe',
|
|
@@ -807,7 +811,7 @@ async function commitMemorySnapshotUnlocked(cwd: string): Promise<void> {
|
|
|
807
811
|
const message = await buildCommitMessage(bun, cwd, staged, undefined, repo.gitArgs)
|
|
808
812
|
|
|
809
813
|
const commit = bun.spawn({
|
|
810
|
-
cmd: ['git', ...repo.gitArgs, 'commit', '-m', message, '--only', '--', ...staged],
|
|
814
|
+
cmd: ['git', ...hooklessGitArgs([...repo.gitArgs, 'commit', '-m', message, '--only', '--', ...staged])],
|
|
811
815
|
cwd,
|
|
812
816
|
stdout: 'pipe',
|
|
813
817
|
stderr: 'pipe',
|
|
@@ -864,7 +868,7 @@ async function buildDreamSummary(
|
|
|
864
868
|
// numstat: `<added>\t<deleted>\t<path>` per line. Use NUL-terminated so paths
|
|
865
869
|
// with whitespace round-trip; -z switches the record separator to NUL.
|
|
866
870
|
const numstat = bun.spawn({
|
|
867
|
-
cmd: ['git', ...gitArgs, 'diff', '--cached', '--numstat', '-z', '--', ...staged],
|
|
871
|
+
cmd: ['git', ...hooklessGitArgs([...gitArgs, 'diff', '--cached', '--numstat', '-z', '--', ...staged])],
|
|
868
872
|
cwd,
|
|
869
873
|
stdout: 'pipe',
|
|
870
874
|
stderr: 'pipe',
|
|
@@ -921,7 +925,7 @@ async function listNewlyAddedSkills(
|
|
|
921
925
|
gitArgs: readonly string[] = [],
|
|
922
926
|
): Promise<string[]> {
|
|
923
927
|
const proc = bun.spawn({
|
|
924
|
-
cmd: ['git', ...gitArgs, 'diff', '--cached', '--name-status', '-z', '--', ...staged],
|
|
928
|
+
cmd: ['git', ...hooklessGitArgs([...gitArgs, 'diff', '--cached', '--name-status', '-z', '--', ...staged])],
|
|
925
929
|
cwd,
|
|
926
930
|
stdout: 'pipe',
|
|
927
931
|
stderr: 'pipe',
|
|
@@ -949,7 +953,7 @@ async function listTrackedSnapshotFiles(
|
|
|
949
953
|
repo: AgentGit,
|
|
950
954
|
): Promise<string[]> {
|
|
951
955
|
const ls = bun.spawn({
|
|
952
|
-
cmd: ['git', ...repo.gitArgs, 'ls-files', '-z', '--', ...SNAPSHOT_PATHS],
|
|
956
|
+
cmd: ['git', ...hooklessGitArgs([...repo.gitArgs, 'ls-files', '-z', '--', ...SNAPSHOT_PATHS])],
|
|
953
957
|
cwd,
|
|
954
958
|
stdout: 'pipe',
|
|
955
959
|
stderr: 'pipe',
|
|
@@ -963,7 +967,7 @@ async function clearSkipWorktree(bun: { spawn: typeof Bun.spawn }, cwd: string,
|
|
|
963
967
|
const files = await listTrackedSnapshotFiles(bun, cwd, repo)
|
|
964
968
|
if (files.length === 0) return
|
|
965
969
|
const proc = bun.spawn({
|
|
966
|
-
cmd: ['git', ...repo.gitArgs, 'update-index', '--no-skip-worktree', '--', ...files],
|
|
970
|
+
cmd: ['git', ...hooklessGitArgs([...repo.gitArgs, 'update-index', '--no-skip-worktree', '--', ...files])],
|
|
967
971
|
cwd,
|
|
968
972
|
stdout: 'pipe',
|
|
969
973
|
stderr: 'pipe',
|
|
@@ -975,7 +979,7 @@ async function applySkipWorktree(bun: { spawn: typeof Bun.spawn }, cwd: string,
|
|
|
975
979
|
const files = await listTrackedSnapshotFiles(bun, cwd, repo)
|
|
976
980
|
if (files.length === 0) return
|
|
977
981
|
const proc = bun.spawn({
|
|
978
|
-
cmd: ['git', ...repo.gitArgs, 'update-index', '--skip-worktree', '--', ...files],
|
|
982
|
+
cmd: ['git', ...hooklessGitArgs([...repo.gitArgs, 'update-index', '--skip-worktree', '--', ...files])],
|
|
979
983
|
cwd,
|
|
980
984
|
stdout: 'pipe',
|
|
981
985
|
stderr: 'pipe',
|
|
@@ -1324,6 +1328,7 @@ function escapeTableCell(value: string): string {
|
|
|
1324
1328
|
const dreamingDeleteTopicShardTool = defineTool({
|
|
1325
1329
|
description: deleteTopicShardTool.description,
|
|
1326
1330
|
parameters: deleteTopicShardTool.inputSchema,
|
|
1331
|
+
fileOperands: { destructive: ['path'] },
|
|
1327
1332
|
async execute(args, ctx) {
|
|
1328
1333
|
const result = await deleteTopicShardTool.run(args, { agentDir: ctx.agentDir })
|
|
1329
1334
|
return { content: [{ type: 'text', text: JSON.stringify(result) }] }
|
|
@@ -19,6 +19,10 @@ export const findEntryTool = defineTool({
|
|
|
19
19
|
.min(1)
|
|
20
20
|
.describe('The entry id to locate (matches the JSONL row whose own `id` field equals this value).'),
|
|
21
21
|
}),
|
|
22
|
+
// `path` is a real local file this tool reads; declaring it pins an immutable
|
|
23
|
+
// snapshot before readFile (and restores the original path in the result)
|
|
24
|
+
// instead of the scanner rejecting the bare `sessions/...jsonl` path.
|
|
25
|
+
fileOperands: { input: ['path'] },
|
|
22
26
|
async execute({ path, entryId }) {
|
|
23
27
|
if (entryId.length === 0) {
|
|
24
28
|
throw new Error('find_entry requires a non-empty entryId; an empty needle would match every line.')
|
|
@@ -717,7 +717,3 @@ async function raceSpawn(work: Promise<void>, ms: number): Promise<void> {
|
|
|
717
717
|
if (timer !== null) clearTimeout(timer)
|
|
718
718
|
}
|
|
719
719
|
}
|
|
720
|
-
|
|
721
|
-
function isEnoent(err: unknown): boolean {
|
|
722
|
-
return typeof err === 'object' && err !== null && 'code' in err && err.code === 'ENOENT'
|
|
723
|
-
}
|
|
@@ -7,6 +7,7 @@ import { firstBeliefSentence, isTitleLikeHeading } from './belief-sentence'
|
|
|
7
7
|
import { buildInjectionPlan, type InjectionPlan } from './injection-plan'
|
|
8
8
|
import { loadAllShards, type TopicShard } from './load-shards'
|
|
9
9
|
import { topicsDir } from './paths'
|
|
10
|
+
import { sanitizeProvenanceName } from './provenance-sanitize'
|
|
10
11
|
import { slugIsHeadingEcho } from './slug'
|
|
11
12
|
import type { FragmentProvenance } from './stream-events'
|
|
12
13
|
import type { DedupedRetrievedItem } from './turn-dedup'
|
|
@@ -68,9 +69,13 @@ export type RetrievedMemoryItem = {
|
|
|
68
69
|
// parts that exist are shown; an undreamed fragment with none renders nothing.
|
|
69
70
|
export function renderProvenanceLine(item: Pick<RetrievedMemoryItem, 'who' | 'when' | 'where'>): string | null {
|
|
70
71
|
const parts: string[] = []
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
const who = sanitizeProvenanceName(item.who)
|
|
73
|
+
if (who !== undefined) parts.push(`speaker=<untrusted-name>${who}</untrusted-name>`)
|
|
74
|
+
const roomName = sanitizeProvenanceName(item.where?.chatName)
|
|
75
|
+
const room = roomName ?? item.where?.chat
|
|
76
|
+
if (room !== undefined) {
|
|
77
|
+
parts.push(roomName === undefined ? `in ${room}` : `in #<untrusted-name>${roomName}</untrusted-name>`)
|
|
78
|
+
}
|
|
74
79
|
if (item.when !== undefined) parts.push(`on ${item.when.slice(0, 10)}`)
|
|
75
80
|
return parts.length === 0 ? null : `_${parts.join(' ')}_`
|
|
76
81
|
}
|