yzcode-cli 1.0.1 → 1.0.3
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/assistant/sessionHistory.ts +87 -0
- package/bootstrap/state.ts +1769 -0
- package/bridge/bridgeApi.ts +539 -0
- package/bridge/bridgeConfig.ts +48 -0
- package/bridge/bridgeDebug.ts +135 -0
- package/bridge/bridgeEnabled.ts +202 -0
- package/bridge/bridgeMain.ts +2999 -0
- package/bridge/bridgeMessaging.ts +461 -0
- package/bridge/bridgePermissionCallbacks.ts +43 -0
- package/bridge/bridgePointer.ts +210 -0
- package/bridge/bridgeStatusUtil.ts +163 -0
- package/bridge/bridgeUI.ts +530 -0
- package/bridge/capacityWake.ts +56 -0
- package/bridge/codeSessionApi.ts +168 -0
- package/bridge/createSession.ts +384 -0
- package/bridge/debugUtils.ts +141 -0
- package/bridge/envLessBridgeConfig.ts +165 -0
- package/bridge/flushGate.ts +71 -0
- package/bridge/inboundAttachments.ts +175 -0
- package/bridge/inboundMessages.ts +80 -0
- package/bridge/initReplBridge.ts +569 -0
- package/bridge/jwtUtils.ts +256 -0
- package/bridge/pollConfig.ts +110 -0
- package/bridge/pollConfigDefaults.ts +82 -0
- package/bridge/remoteBridgeCore.ts +1008 -0
- package/bridge/replBridge.ts +2406 -0
- package/bridge/replBridgeHandle.ts +36 -0
- package/bridge/replBridgeTransport.ts +370 -0
- package/bridge/sessionIdCompat.ts +57 -0
- package/bridge/sessionRunner.ts +550 -0
- package/bridge/trustedDevice.ts +210 -0
- package/bridge/types.ts +262 -0
- package/bridge/workSecret.ts +127 -0
- package/buddy/CompanionSprite.tsx +371 -0
- package/buddy/companion.ts +133 -0
- package/buddy/prompt.ts +36 -0
- package/buddy/sprites.ts +514 -0
- package/buddy/types.ts +148 -0
- package/buddy/useBuddyNotification.tsx +98 -0
- package/coordinator/coordinatorMode.ts +369 -0
- package/memdir/findRelevantMemories.ts +141 -0
- package/memdir/memdir.ts +507 -0
- package/memdir/memoryAge.ts +53 -0
- package/memdir/memoryScan.ts +94 -0
- package/memdir/memoryTypes.ts +271 -0
- package/memdir/paths.ts +278 -0
- package/memdir/teamMemPaths.ts +292 -0
- package/memdir/teamMemPrompts.ts +100 -0
- package/migrations/migrateAutoUpdatesToSettings.ts +61 -0
- package/migrations/migrateBypassPermissionsAcceptedToSettings.ts +40 -0
- package/migrations/migrateEnableAllProjectMcpServersToSettings.ts +118 -0
- package/migrations/migrateFennecToOpus.ts +45 -0
- package/migrations/migrateLegacyOpusToCurrent.ts +57 -0
- package/migrations/migrateOpusToOpus1m.ts +43 -0
- package/migrations/migrateReplBridgeEnabledToRemoteControlAtStartup.ts +22 -0
- package/migrations/migrateSonnet1mToSonnet45.ts +48 -0
- package/migrations/migrateSonnet45ToSonnet46.ts +67 -0
- package/migrations/resetAutoModeOptInForDefaultOffer.ts +51 -0
- package/migrations/resetProToOpusDefault.ts +51 -0
- package/native-ts/color-diff/index.ts +999 -0
- package/native-ts/file-index/index.ts +370 -0
- package/native-ts/yoga-layout/enums.ts +134 -0
- package/native-ts/yoga-layout/index.ts +2578 -0
- package/outputStyles/loadOutputStylesDir.ts +98 -0
- package/package.json +22 -5
- package/plugins/builtinPlugins.ts +159 -0
- package/plugins/bundled/index.ts +23 -0
- package/schemas/hooks.ts +222 -0
- package/screens/Doctor.tsx +575 -0
- package/screens/REPL.tsx +5006 -0
- package/screens/ResumeConversation.tsx +399 -0
- package/server/createDirectConnectSession.ts +88 -0
- package/server/directConnectManager.ts +213 -0
- package/server/types.ts +57 -0
- package/skills/bundled/batch.ts +124 -0
- package/skills/bundled/claudeApi.ts +196 -0
- package/skills/bundled/claudeApiContent.ts +75 -0
- package/skills/bundled/claudeInChrome.ts +34 -0
- package/skills/bundled/debug.ts +103 -0
- package/skills/bundled/index.ts +79 -0
- package/skills/bundled/keybindings.ts +339 -0
- package/skills/bundled/loop.ts +92 -0
- package/skills/bundled/loremIpsum.ts +282 -0
- package/skills/bundled/remember.ts +82 -0
- package/skills/bundled/scheduleRemoteAgents.ts +447 -0
- package/skills/bundled/simplify.ts +69 -0
- package/skills/bundled/skillify.ts +197 -0
- package/skills/bundled/stuck.ts +79 -0
- package/skills/bundled/updateConfig.ts +475 -0
- package/skills/bundled/verify/SKILL.md +3 -0
- package/skills/bundled/verify/examples/cli.md +3 -0
- package/skills/bundled/verify/examples/server.md +3 -0
- package/skills/bundled/verify.ts +30 -0
- package/skills/bundled/verifyContent.ts +13 -0
- package/skills/bundledSkills.ts +220 -0
- package/skills/loadSkillsDir.ts +1086 -0
- package/skills/mcpSkillBuilders.ts +44 -0
- package/tasks/DreamTask/DreamTask.ts +157 -0
- package/tasks/InProcessTeammateTask/InProcessTeammateTask.tsx +126 -0
- package/tasks/InProcessTeammateTask/types.ts +121 -0
- package/tasks/LocalAgentTask/LocalAgentTask.tsx +683 -0
- package/tasks/LocalMainSessionTask.ts +479 -0
- package/tasks/LocalShellTask/LocalShellTask.tsx +523 -0
- package/tasks/LocalShellTask/guards.ts +41 -0
- package/tasks/LocalShellTask/killShellTasks.ts +76 -0
- package/tasks/RemoteAgentTask/RemoteAgentTask.tsx +856 -0
- package/tasks/pillLabel.ts +82 -0
- package/tasks/stopTask.ts +100 -0
- package/tasks/types.ts +46 -0
- package/upstreamproxy/relay.ts +455 -0
- package/upstreamproxy/upstreamproxy.ts +285 -0
- package/vim/motions.ts +82 -0
- package/vim/operators.ts +556 -0
- package/vim/textObjects.ts +186 -0
- package/vim/transitions.ts +490 -0
- package/vim/types.ts +199 -0
- package/voice/voiceModeEnabled.ts +54 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { lstat, realpath } from 'fs/promises'
|
|
2
|
+
import { dirname, join, resolve, sep } from 'path'
|
|
3
|
+
import { getFeatureValue_CACHED_MAY_BE_STALE } from '../services/analytics/growthbook.js'
|
|
4
|
+
import { getErrnoCode } from '../utils/errors.js'
|
|
5
|
+
import { getAutoMemPath, isAutoMemoryEnabled } from './paths.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown when a path validation detects a traversal or injection attempt.
|
|
9
|
+
*/
|
|
10
|
+
export class PathTraversalError extends Error {
|
|
11
|
+
constructor(message: string) {
|
|
12
|
+
super(message)
|
|
13
|
+
this.name = 'PathTraversalError'
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Sanitize a file path key by rejecting dangerous patterns.
|
|
19
|
+
* Checks for null bytes, URL-encoded traversals, and other injection vectors.
|
|
20
|
+
* Returns the sanitized string or throws PathTraversalError.
|
|
21
|
+
*/
|
|
22
|
+
function sanitizePathKey(key: string): string {
|
|
23
|
+
// Null bytes can truncate paths in C-based syscalls
|
|
24
|
+
if (key.includes('\0')) {
|
|
25
|
+
throw new PathTraversalError(`Null byte in path key: "${key}"`)
|
|
26
|
+
}
|
|
27
|
+
// URL-encoded traversals (e.g. %2e%2e%2f = ../)
|
|
28
|
+
let decoded: string
|
|
29
|
+
try {
|
|
30
|
+
decoded = decodeURIComponent(key)
|
|
31
|
+
} catch {
|
|
32
|
+
// Malformed percent-encoding (e.g. %ZZ, lone %) — not valid URL-encoding,
|
|
33
|
+
// so no URL-encoded traversal is possible
|
|
34
|
+
decoded = key
|
|
35
|
+
}
|
|
36
|
+
if (decoded !== key && (decoded.includes('..') || decoded.includes('/'))) {
|
|
37
|
+
throw new PathTraversalError(`URL-encoded traversal in path key: "${key}"`)
|
|
38
|
+
}
|
|
39
|
+
// Unicode normalization attacks: fullwidth ../ (U+FF0E U+FF0F) normalize
|
|
40
|
+
// to ASCII ../ under NFKC. While path.resolve/fs.writeFile treat these as
|
|
41
|
+
// literal bytes (not separators), downstream layers or filesystems may
|
|
42
|
+
// normalize — reject for defense-in-depth (PSR M22187 vector 4).
|
|
43
|
+
const normalized = key.normalize('NFKC')
|
|
44
|
+
if (
|
|
45
|
+
normalized !== key &&
|
|
46
|
+
(normalized.includes('..') ||
|
|
47
|
+
normalized.includes('/') ||
|
|
48
|
+
normalized.includes('\\') ||
|
|
49
|
+
normalized.includes('\0'))
|
|
50
|
+
) {
|
|
51
|
+
throw new PathTraversalError(
|
|
52
|
+
`Unicode-normalized traversal in path key: "${key}"`,
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
// Reject backslashes (Windows path separator used as traversal vector)
|
|
56
|
+
if (key.includes('\\')) {
|
|
57
|
+
throw new PathTraversalError(`Backslash in path key: "${key}"`)
|
|
58
|
+
}
|
|
59
|
+
// Reject absolute paths
|
|
60
|
+
if (key.startsWith('/')) {
|
|
61
|
+
throw new PathTraversalError(`Absolute path key: "${key}"`)
|
|
62
|
+
}
|
|
63
|
+
return key
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Whether team memory features are enabled.
|
|
68
|
+
* Team memory is a subdirectory of auto memory, so it requires auto memory
|
|
69
|
+
* to be enabled. This keeps all team-memory consumers (prompt, content
|
|
70
|
+
* injection, sync watcher, file detection) consistent when auto memory is
|
|
71
|
+
* disabled via env var or settings.
|
|
72
|
+
*/
|
|
73
|
+
export function isTeamMemoryEnabled(): boolean {
|
|
74
|
+
if (!isAutoMemoryEnabled()) {
|
|
75
|
+
return false
|
|
76
|
+
}
|
|
77
|
+
return getFeatureValue_CACHED_MAY_BE_STALE('tengu_herring_clock', false)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Returns the team memory path: <memoryBase>/projects/<sanitized-project-root>/memory/team/
|
|
82
|
+
* Lives as a subdirectory of the auto-memory directory, scoped per-project.
|
|
83
|
+
*/
|
|
84
|
+
export function getTeamMemPath(): string {
|
|
85
|
+
return (join(getAutoMemPath(), 'team') + sep).normalize('NFC')
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Returns the team memory entrypoint: <memoryBase>/projects/<sanitized-project-root>/memory/team/MEMORY.md
|
|
90
|
+
* Lives as a subdirectory of the auto-memory directory, scoped per-project.
|
|
91
|
+
*/
|
|
92
|
+
export function getTeamMemEntrypoint(): string {
|
|
93
|
+
return join(getAutoMemPath(), 'team', 'MEMORY.md')
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Resolve symlinks for the deepest existing ancestor of a path.
|
|
98
|
+
* The target file may not exist yet (we may be about to create it), so we
|
|
99
|
+
* walk up the directory tree until realpath() succeeds, then rejoin the
|
|
100
|
+
* non-existing tail onto the resolved ancestor.
|
|
101
|
+
*
|
|
102
|
+
* SECURITY (PSR M22186): path.resolve() does NOT resolve symlinks. An attacker
|
|
103
|
+
* who can place a symlink inside teamDir pointing outside (e.g. to
|
|
104
|
+
* ~/.ssh/authorized_keys) would pass a resolve()-based containment check.
|
|
105
|
+
* Using realpath() on the deepest existing ancestor ensures we compare the
|
|
106
|
+
* actual filesystem location, not the symbolic path.
|
|
107
|
+
*
|
|
108
|
+
*/
|
|
109
|
+
async function realpathDeepestExisting(absolutePath: string): Promise<string> {
|
|
110
|
+
const tail: string[] = []
|
|
111
|
+
let current = absolutePath
|
|
112
|
+
// Walk up until realpath succeeds. ENOENT means this segment doesn't exist
|
|
113
|
+
// yet; pop it onto the tail and try the parent. ENOTDIR means a non-directory
|
|
114
|
+
// component sits in the middle of the path; pop and retry so we can realpath
|
|
115
|
+
// the ancestor to detect symlink escapes.
|
|
116
|
+
// Loop terminates when we reach the filesystem root (dirname('/') === '/').
|
|
117
|
+
for (
|
|
118
|
+
let parent = dirname(current);
|
|
119
|
+
current !== parent;
|
|
120
|
+
parent = dirname(current)
|
|
121
|
+
) {
|
|
122
|
+
try {
|
|
123
|
+
const realCurrent = await realpath(current)
|
|
124
|
+
// Rejoin the non-existing tail in reverse order (deepest popped first)
|
|
125
|
+
return tail.length === 0
|
|
126
|
+
? realCurrent
|
|
127
|
+
: join(realCurrent, ...tail.reverse())
|
|
128
|
+
} catch (e: unknown) {
|
|
129
|
+
const code = getErrnoCode(e)
|
|
130
|
+
if (code === 'ENOENT') {
|
|
131
|
+
// Could be truly non-existent (safe to walk up) OR a dangling symlink
|
|
132
|
+
// whose target doesn't exist. Dangling symlinks are an attack vector:
|
|
133
|
+
// writeFile would follow the link and create the target outside teamDir.
|
|
134
|
+
// lstat distinguishes: it succeeds for dangling symlinks (the link entry
|
|
135
|
+
// itself exists), fails with ENOENT for truly non-existent paths.
|
|
136
|
+
try {
|
|
137
|
+
const st = await lstat(current)
|
|
138
|
+
if (st.isSymbolicLink()) {
|
|
139
|
+
throw new PathTraversalError(
|
|
140
|
+
`Dangling symlink detected (target does not exist): "${current}"`,
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
// lstat succeeded but isn't a symlink — ENOENT from realpath was
|
|
144
|
+
// caused by a dangling symlink in an ancestor. Walk up to find it.
|
|
145
|
+
} catch (lstatErr: unknown) {
|
|
146
|
+
if (lstatErr instanceof PathTraversalError) {
|
|
147
|
+
throw lstatErr
|
|
148
|
+
}
|
|
149
|
+
// lstat also failed (truly non-existent or inaccessible) — safe to walk up.
|
|
150
|
+
}
|
|
151
|
+
} else if (code === 'ELOOP') {
|
|
152
|
+
// Symlink loop — corrupted or malicious filesystem state.
|
|
153
|
+
throw new PathTraversalError(
|
|
154
|
+
`Symlink loop detected in path: "${current}"`,
|
|
155
|
+
)
|
|
156
|
+
} else if (code !== 'ENOTDIR' && code !== 'ENAMETOOLONG') {
|
|
157
|
+
// EACCES, EIO, etc. — cannot verify containment. Fail closed by wrapping
|
|
158
|
+
// as PathTraversalError so the caller can skip this entry gracefully
|
|
159
|
+
// instead of aborting the entire batch.
|
|
160
|
+
throw new PathTraversalError(
|
|
161
|
+
`Cannot verify path containment (${code}): "${current}"`,
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
tail.push(current.slice(parent.length + sep.length))
|
|
165
|
+
current = parent
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Reached filesystem root without finding an existing ancestor (rare —
|
|
169
|
+
// root normally exists). Fall back to the input; containment check will reject.
|
|
170
|
+
return absolutePath
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Check whether a real (symlink-resolved) path is within the real team
|
|
175
|
+
* memory directory. Both sides are realpath'd so the comparison is between
|
|
176
|
+
* canonical filesystem locations.
|
|
177
|
+
*
|
|
178
|
+
* If teamDir does not exist, returns true (skips the check). This is safe:
|
|
179
|
+
* a symlink escape requires a pre-existing symlink inside teamDir, which
|
|
180
|
+
* requires teamDir to exist. If there's no directory, there's no symlink,
|
|
181
|
+
* and the first-pass string-level containment check is sufficient.
|
|
182
|
+
*/
|
|
183
|
+
async function isRealPathWithinTeamDir(
|
|
184
|
+
realCandidate: string,
|
|
185
|
+
): Promise<boolean> {
|
|
186
|
+
let realTeamDir: string
|
|
187
|
+
try {
|
|
188
|
+
// getTeamMemPath() includes a trailing separator; strip it because
|
|
189
|
+
// realpath() rejects trailing separators on some platforms.
|
|
190
|
+
realTeamDir = await realpath(getTeamMemPath().replace(/[/\\]+$/, ''))
|
|
191
|
+
} catch (e: unknown) {
|
|
192
|
+
const code = getErrnoCode(e)
|
|
193
|
+
if (code === 'ENOENT' || code === 'ENOTDIR') {
|
|
194
|
+
// Team dir doesn't exist — symlink escape impossible, skip check.
|
|
195
|
+
return true
|
|
196
|
+
}
|
|
197
|
+
// Unexpected error (EACCES, EIO) — fail closed.
|
|
198
|
+
return false
|
|
199
|
+
}
|
|
200
|
+
if (realCandidate === realTeamDir) {
|
|
201
|
+
return true
|
|
202
|
+
}
|
|
203
|
+
// Prefix-attack protection: require separator after the prefix so that
|
|
204
|
+
// "/foo/team-evil" doesn't match "/foo/team".
|
|
205
|
+
return realCandidate.startsWith(realTeamDir + sep)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Check if a resolved absolute path is within the team memory directory.
|
|
210
|
+
* Uses path.resolve() to convert relative paths and eliminate traversal segments.
|
|
211
|
+
* Does NOT resolve symlinks — for write validation use validateTeamMemWritePath()
|
|
212
|
+
* or validateTeamMemKey() which include symlink resolution.
|
|
213
|
+
*/
|
|
214
|
+
export function isTeamMemPath(filePath: string): boolean {
|
|
215
|
+
// SECURITY: resolve() converts to absolute and eliminates .. segments,
|
|
216
|
+
// preventing path traversal attacks (e.g. "team/../../etc/passwd")
|
|
217
|
+
const resolvedPath = resolve(filePath)
|
|
218
|
+
const teamDir = getTeamMemPath()
|
|
219
|
+
return resolvedPath.startsWith(teamDir)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Validate that an absolute file path is safe for writing to the team memory directory.
|
|
224
|
+
* Returns the resolved absolute path if valid.
|
|
225
|
+
* Throws PathTraversalError if the path contains injection vectors, escapes the
|
|
226
|
+
* directory via .. segments, or escapes via a symlink (PSR M22186).
|
|
227
|
+
*/
|
|
228
|
+
export async function validateTeamMemWritePath(
|
|
229
|
+
filePath: string,
|
|
230
|
+
): Promise<string> {
|
|
231
|
+
if (filePath.includes('\0')) {
|
|
232
|
+
throw new PathTraversalError(`Null byte in path: "${filePath}"`)
|
|
233
|
+
}
|
|
234
|
+
// First pass: normalize .. segments and check string-level containment.
|
|
235
|
+
// This is a fast rejection for obvious traversal attempts before we touch
|
|
236
|
+
// the filesystem.
|
|
237
|
+
const resolvedPath = resolve(filePath)
|
|
238
|
+
const teamDir = getTeamMemPath()
|
|
239
|
+
// Prefix attack protection: teamDir already ends with sep (from getTeamMemPath),
|
|
240
|
+
// so "team-evil/" won't match "team/"
|
|
241
|
+
if (!resolvedPath.startsWith(teamDir)) {
|
|
242
|
+
throw new PathTraversalError(
|
|
243
|
+
`Path escapes team memory directory: "${filePath}"`,
|
|
244
|
+
)
|
|
245
|
+
}
|
|
246
|
+
// Second pass: resolve symlinks on the deepest existing ancestor and verify
|
|
247
|
+
// the real path is still within the real team dir. This catches symlink-based
|
|
248
|
+
// escapes that path.resolve() alone cannot detect.
|
|
249
|
+
const realPath = await realpathDeepestExisting(resolvedPath)
|
|
250
|
+
if (!(await isRealPathWithinTeamDir(realPath))) {
|
|
251
|
+
throw new PathTraversalError(
|
|
252
|
+
`Path escapes team memory directory via symlink: "${filePath}"`,
|
|
253
|
+
)
|
|
254
|
+
}
|
|
255
|
+
return resolvedPath
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Validate a relative path key from the server against the team memory directory.
|
|
260
|
+
* Sanitizes the key, joins with the team dir, resolves symlinks on the deepest
|
|
261
|
+
* existing ancestor, and verifies containment against the real team dir.
|
|
262
|
+
* Returns the resolved absolute path.
|
|
263
|
+
* Throws PathTraversalError if the key is malicious (PSR M22186).
|
|
264
|
+
*/
|
|
265
|
+
export async function validateTeamMemKey(relativeKey: string): Promise<string> {
|
|
266
|
+
sanitizePathKey(relativeKey)
|
|
267
|
+
const teamDir = getTeamMemPath()
|
|
268
|
+
const fullPath = join(teamDir, relativeKey)
|
|
269
|
+
// First pass: normalize .. segments and check string-level containment.
|
|
270
|
+
const resolvedPath = resolve(fullPath)
|
|
271
|
+
if (!resolvedPath.startsWith(teamDir)) {
|
|
272
|
+
throw new PathTraversalError(
|
|
273
|
+
`Key escapes team memory directory: "${relativeKey}"`,
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
// Second pass: resolve symlinks and verify real containment.
|
|
277
|
+
const realPath = await realpathDeepestExisting(resolvedPath)
|
|
278
|
+
if (!(await isRealPathWithinTeamDir(realPath))) {
|
|
279
|
+
throw new PathTraversalError(
|
|
280
|
+
`Key escapes team memory directory via symlink: "${relativeKey}"`,
|
|
281
|
+
)
|
|
282
|
+
}
|
|
283
|
+
return resolvedPath
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Check if a file path is within the team memory directory
|
|
288
|
+
* and team memory is enabled.
|
|
289
|
+
*/
|
|
290
|
+
export function isTeamMemFile(filePath: string): boolean {
|
|
291
|
+
return isTeamMemoryEnabled() && isTeamMemPath(filePath)
|
|
292
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildSearchingPastContextSection,
|
|
3
|
+
DIRS_EXIST_GUIDANCE,
|
|
4
|
+
ENTRYPOINT_NAME,
|
|
5
|
+
MAX_ENTRYPOINT_LINES,
|
|
6
|
+
} from './memdir.js'
|
|
7
|
+
import {
|
|
8
|
+
MEMORY_DRIFT_CAVEAT,
|
|
9
|
+
MEMORY_FRONTMATTER_EXAMPLE,
|
|
10
|
+
TRUSTING_RECALL_SECTION,
|
|
11
|
+
TYPES_SECTION_COMBINED,
|
|
12
|
+
WHAT_NOT_TO_SAVE_SECTION,
|
|
13
|
+
} from './memoryTypes.js'
|
|
14
|
+
import { getAutoMemPath } from './paths.js'
|
|
15
|
+
import { getTeamMemPath } from './teamMemPaths.js'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Build the combined prompt when both auto memory and team memory are enabled.
|
|
19
|
+
* Closed four-type taxonomy (user / feedback / project / reference) with
|
|
20
|
+
* per-type <scope> guidance embedded in XML-style <type> blocks.
|
|
21
|
+
*/
|
|
22
|
+
export function buildCombinedMemoryPrompt(
|
|
23
|
+
extraGuidelines?: string[],
|
|
24
|
+
skipIndex = false,
|
|
25
|
+
): string {
|
|
26
|
+
const autoDir = getAutoMemPath()
|
|
27
|
+
const teamDir = getTeamMemPath()
|
|
28
|
+
|
|
29
|
+
const howToSave = skipIndex
|
|
30
|
+
? [
|
|
31
|
+
'## How to save memories',
|
|
32
|
+
'',
|
|
33
|
+
"Write each memory to its own file in the chosen directory (private or team, per the type's scope guidance) using this frontmatter format:",
|
|
34
|
+
'',
|
|
35
|
+
...MEMORY_FRONTMATTER_EXAMPLE,
|
|
36
|
+
'',
|
|
37
|
+
'- Keep the name, description, and type fields in memory files up-to-date with the content',
|
|
38
|
+
'- Organize memory semantically by topic, not chronologically',
|
|
39
|
+
'- Update or remove memories that turn out to be wrong or outdated',
|
|
40
|
+
'- Do not write duplicate memories. First check if there is an existing memory you can update before writing a new one.',
|
|
41
|
+
]
|
|
42
|
+
: [
|
|
43
|
+
'## How to save memories',
|
|
44
|
+
'',
|
|
45
|
+
'Saving a memory is a two-step process:',
|
|
46
|
+
'',
|
|
47
|
+
"**Step 1** — write the memory to its own file in the chosen directory (private or team, per the type's scope guidance) using this frontmatter format:",
|
|
48
|
+
'',
|
|
49
|
+
...MEMORY_FRONTMATTER_EXAMPLE,
|
|
50
|
+
'',
|
|
51
|
+
`**Step 2** — add a pointer to that file in the same directory's \`${ENTRYPOINT_NAME}\`. Each directory (private and team) has its own \`${ENTRYPOINT_NAME}\` index — each entry should be one line, under ~150 characters: \`- [Title](file.md) — one-line hook\`. They have no frontmatter. Never write memory content directly into a \`${ENTRYPOINT_NAME}\`.`,
|
|
52
|
+
'',
|
|
53
|
+
`- Both \`${ENTRYPOINT_NAME}\` indexes are loaded into your conversation context — lines after ${MAX_ENTRYPOINT_LINES} will be truncated, so keep them concise`,
|
|
54
|
+
'- Keep the name, description, and type fields in memory files up-to-date with the content',
|
|
55
|
+
'- Organize memory semantically by topic, not chronologically',
|
|
56
|
+
'- Update or remove memories that turn out to be wrong or outdated',
|
|
57
|
+
'- Do not write duplicate memories. First check if there is an existing memory you can update before writing a new one.',
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
const lines = [
|
|
61
|
+
'# Memory',
|
|
62
|
+
'',
|
|
63
|
+
`You have a persistent, file-based memory system with two directories: a private directory at \`${autoDir}\` and a shared team directory at \`${teamDir}\`. ${DIRS_EXIST_GUIDANCE}`,
|
|
64
|
+
'',
|
|
65
|
+
"You should build up this memory system over time so that future conversations can have a complete picture of who the user is, how they'd like to collaborate with you, what behaviors to avoid or repeat, and the context behind the work the user gives you.",
|
|
66
|
+
'',
|
|
67
|
+
'If the user explicitly asks you to remember something, save it immediately as whichever type fits best. If they ask you to forget something, find and remove the relevant entry.',
|
|
68
|
+
'',
|
|
69
|
+
'## Memory scope',
|
|
70
|
+
'',
|
|
71
|
+
'There are two scope levels:',
|
|
72
|
+
'',
|
|
73
|
+
`- private: memories that are private between you and the current user. They persist across conversations with only this specific user and are stored at the root \`${autoDir}\`.`,
|
|
74
|
+
`- team: memories that are shared with and contributed by all of the users who work within this project directory. Team memories are synced at the beginning of every session and they are stored at \`${teamDir}\`.`,
|
|
75
|
+
'',
|
|
76
|
+
...TYPES_SECTION_COMBINED,
|
|
77
|
+
...WHAT_NOT_TO_SAVE_SECTION,
|
|
78
|
+
'- You MUST avoid saving sensitive data within shared team memories. For example, never save API keys or user credentials.',
|
|
79
|
+
'',
|
|
80
|
+
...howToSave,
|
|
81
|
+
'',
|
|
82
|
+
'## When to access memories',
|
|
83
|
+
'- When memories (personal or team) seem relevant, or the user references prior work with them or others in their organization.',
|
|
84
|
+
'- You MUST access memory when the user explicitly asks you to check, recall, or remember.',
|
|
85
|
+
'- If the user says to *ignore* or *not use* memory: proceed as if MEMORY.md were empty. Do not apply remembered facts, cite, compare against, or mention memory content.',
|
|
86
|
+
MEMORY_DRIFT_CAVEAT,
|
|
87
|
+
'',
|
|
88
|
+
...TRUSTING_RECALL_SECTION,
|
|
89
|
+
'',
|
|
90
|
+
'## Memory and other forms of persistence',
|
|
91
|
+
'Memory is one of several persistence mechanisms available to you as you assist the user in a given conversation. The distinction is often that memory can be recalled in future conversations and should not be used for persisting information that is only useful within the scope of the current conversation.',
|
|
92
|
+
'- When to use or update a plan instead of memory: If you are about to start a non-trivial implementation task and would like to reach alignment with the user on your approach you should use a Plan rather than saving this information to memory. Similarly, if you already have a plan within the conversation and you have changed your approach persist that change by updating the plan rather than saving a memory.',
|
|
93
|
+
'- When to use or update tasks instead of memory: When you need to break your work in current conversation into discrete steps or keep track of your progress use tasks instead of saving to memory. Tasks are great for persisting information about the work that needs to be done in the current conversation, but memory should be reserved for information that will be useful in future conversations.',
|
|
94
|
+
...(extraGuidelines ?? []),
|
|
95
|
+
'',
|
|
96
|
+
...buildSearchingPastContextSection(autoDir),
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
return lines.join('\n')
|
|
100
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { logEvent } from 'src/services/analytics/index.js'
|
|
2
|
+
import { getGlobalConfig, saveGlobalConfig } from '../utils/config.js'
|
|
3
|
+
import { logError } from '../utils/log.js'
|
|
4
|
+
import {
|
|
5
|
+
getSettingsForSource,
|
|
6
|
+
updateSettingsForSource,
|
|
7
|
+
} from '../utils/settings/settings.js'
|
|
8
|
+
/**
|
|
9
|
+
* Migration: Move user-set autoUpdates preference to settings.json env var
|
|
10
|
+
* Only migrates if user explicitly disabled auto-updates (not for protection)
|
|
11
|
+
* This preserves user intent while allowing native installations to auto-update
|
|
12
|
+
*/
|
|
13
|
+
export function migrateAutoUpdatesToSettings(): void {
|
|
14
|
+
const globalConfig = getGlobalConfig()
|
|
15
|
+
|
|
16
|
+
// Only migrate if autoUpdates was explicitly set to false by user preference
|
|
17
|
+
// (not automatically for native protection)
|
|
18
|
+
if (
|
|
19
|
+
globalConfig.autoUpdates !== false ||
|
|
20
|
+
globalConfig.autoUpdatesProtectedForNative === true
|
|
21
|
+
) {
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const userSettings = getSettingsForSource('userSettings') || {}
|
|
27
|
+
|
|
28
|
+
// Always set DISABLE_AUTOUPDATER to preserve user intent
|
|
29
|
+
// We need to overwrite even if it exists, to ensure the migration is complete
|
|
30
|
+
updateSettingsForSource('userSettings', {
|
|
31
|
+
...userSettings,
|
|
32
|
+
env: {
|
|
33
|
+
...userSettings.env,
|
|
34
|
+
DISABLE_AUTOUPDATER: '1',
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
logEvent('tengu_migrate_autoupdates_to_settings', {
|
|
39
|
+
was_user_preference: true,
|
|
40
|
+
already_had_env_var: !!userSettings.env?.DISABLE_AUTOUPDATER,
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
// explicitly set, so this takes effect immediately
|
|
44
|
+
process.env.DISABLE_AUTOUPDATER = '1'
|
|
45
|
+
|
|
46
|
+
// Remove autoUpdates from global config after successful migration
|
|
47
|
+
saveGlobalConfig(current => {
|
|
48
|
+
const {
|
|
49
|
+
autoUpdates: _,
|
|
50
|
+
autoUpdatesProtectedForNative: __,
|
|
51
|
+
...updatedConfig
|
|
52
|
+
} = current
|
|
53
|
+
return updatedConfig
|
|
54
|
+
})
|
|
55
|
+
} catch (error) {
|
|
56
|
+
logError(new Error(`Failed to migrate auto-updates: ${error}`))
|
|
57
|
+
logEvent('tengu_migrate_autoupdates_error', {
|
|
58
|
+
has_error: true,
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { logEvent } from 'src/services/analytics/index.js'
|
|
2
|
+
import { getGlobalConfig, saveGlobalConfig } from '../utils/config.js'
|
|
3
|
+
import { logError } from '../utils/log.js'
|
|
4
|
+
import {
|
|
5
|
+
hasSkipDangerousModePermissionPrompt,
|
|
6
|
+
updateSettingsForSource,
|
|
7
|
+
} from '../utils/settings/settings.js'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Migration: Move bypassPermissionsModeAccepted from global config to settings.json
|
|
11
|
+
* as skipDangerousModePermissionPrompt. This is a better home since settings.json
|
|
12
|
+
* is the user-configurable settings file.
|
|
13
|
+
*/
|
|
14
|
+
export function migrateBypassPermissionsAcceptedToSettings(): void {
|
|
15
|
+
const globalConfig = getGlobalConfig()
|
|
16
|
+
|
|
17
|
+
if (!globalConfig.bypassPermissionsModeAccepted) {
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
if (!hasSkipDangerousModePermissionPrompt()) {
|
|
23
|
+
updateSettingsForSource('userSettings', {
|
|
24
|
+
skipDangerousModePermissionPrompt: true,
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
logEvent('tengu_migrate_bypass_permissions_accepted', {})
|
|
29
|
+
|
|
30
|
+
saveGlobalConfig(current => {
|
|
31
|
+
if (!('bypassPermissionsModeAccepted' in current)) return current
|
|
32
|
+
const { bypassPermissionsModeAccepted: _, ...updatedConfig } = current
|
|
33
|
+
return updatedConfig
|
|
34
|
+
})
|
|
35
|
+
} catch (error) {
|
|
36
|
+
logError(
|
|
37
|
+
new Error(`Failed to migrate bypass permissions accepted: ${error}`),
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { logEvent } from 'src/services/analytics/index.js'
|
|
2
|
+
import {
|
|
3
|
+
getCurrentProjectConfig,
|
|
4
|
+
saveCurrentProjectConfig,
|
|
5
|
+
} from '../utils/config.js'
|
|
6
|
+
import { logError } from '../utils/log.js'
|
|
7
|
+
import {
|
|
8
|
+
getSettingsForSource,
|
|
9
|
+
updateSettingsForSource,
|
|
10
|
+
} from '../utils/settings/settings.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Migration: Move MCP server approval fields from project config to local settings
|
|
14
|
+
* This migrates both enableAllProjectMcpServers and enabledMcpjsonServers to the
|
|
15
|
+
* settings system for better management and consistency.
|
|
16
|
+
*/
|
|
17
|
+
export function migrateEnableAllProjectMcpServersToSettings(): void {
|
|
18
|
+
const projectConfig = getCurrentProjectConfig()
|
|
19
|
+
|
|
20
|
+
// Check if any field exists in project config
|
|
21
|
+
const hasEnableAll = projectConfig.enableAllProjectMcpServers !== undefined
|
|
22
|
+
const hasEnabledServers =
|
|
23
|
+
projectConfig.enabledMcpjsonServers &&
|
|
24
|
+
projectConfig.enabledMcpjsonServers.length > 0
|
|
25
|
+
const hasDisabledServers =
|
|
26
|
+
projectConfig.disabledMcpjsonServers &&
|
|
27
|
+
projectConfig.disabledMcpjsonServers.length > 0
|
|
28
|
+
|
|
29
|
+
if (!hasEnableAll && !hasEnabledServers && !hasDisabledServers) {
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const existingSettings = getSettingsForSource('localSettings') || {}
|
|
35
|
+
const updates: Partial<{
|
|
36
|
+
enableAllProjectMcpServers: boolean
|
|
37
|
+
enabledMcpjsonServers: string[]
|
|
38
|
+
disabledMcpjsonServers: string[]
|
|
39
|
+
}> = {}
|
|
40
|
+
const fieldsToRemove: Array<
|
|
41
|
+
| 'enableAllProjectMcpServers'
|
|
42
|
+
| 'enabledMcpjsonServers'
|
|
43
|
+
| 'disabledMcpjsonServers'
|
|
44
|
+
> = []
|
|
45
|
+
|
|
46
|
+
// Migrate enableAllProjectMcpServers if it exists and hasn't been migrated
|
|
47
|
+
if (
|
|
48
|
+
hasEnableAll &&
|
|
49
|
+
existingSettings.enableAllProjectMcpServers === undefined
|
|
50
|
+
) {
|
|
51
|
+
updates.enableAllProjectMcpServers =
|
|
52
|
+
projectConfig.enableAllProjectMcpServers
|
|
53
|
+
fieldsToRemove.push('enableAllProjectMcpServers')
|
|
54
|
+
} else if (hasEnableAll) {
|
|
55
|
+
// Already migrated, just mark for removal
|
|
56
|
+
fieldsToRemove.push('enableAllProjectMcpServers')
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Migrate enabledMcpjsonServers if it exists
|
|
60
|
+
if (hasEnabledServers && projectConfig.enabledMcpjsonServers) {
|
|
61
|
+
const existingEnabledServers =
|
|
62
|
+
existingSettings.enabledMcpjsonServers || []
|
|
63
|
+
// Merge the servers (avoiding duplicates)
|
|
64
|
+
updates.enabledMcpjsonServers = [
|
|
65
|
+
...new Set([
|
|
66
|
+
...existingEnabledServers,
|
|
67
|
+
...projectConfig.enabledMcpjsonServers,
|
|
68
|
+
]),
|
|
69
|
+
]
|
|
70
|
+
fieldsToRemove.push('enabledMcpjsonServers')
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Migrate disabledMcpjsonServers if it exists
|
|
74
|
+
if (hasDisabledServers && projectConfig.disabledMcpjsonServers) {
|
|
75
|
+
const existingDisabledServers =
|
|
76
|
+
existingSettings.disabledMcpjsonServers || []
|
|
77
|
+
// Merge the servers (avoiding duplicates)
|
|
78
|
+
updates.disabledMcpjsonServers = [
|
|
79
|
+
...new Set([
|
|
80
|
+
...existingDisabledServers,
|
|
81
|
+
...projectConfig.disabledMcpjsonServers,
|
|
82
|
+
]),
|
|
83
|
+
]
|
|
84
|
+
fieldsToRemove.push('disabledMcpjsonServers')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Update settings if there are any updates
|
|
88
|
+
if (Object.keys(updates).length > 0) {
|
|
89
|
+
updateSettingsForSource('localSettings', updates)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Remove migrated fields from project config
|
|
93
|
+
if (
|
|
94
|
+
fieldsToRemove.includes('enableAllProjectMcpServers') ||
|
|
95
|
+
fieldsToRemove.includes('enabledMcpjsonServers') ||
|
|
96
|
+
fieldsToRemove.includes('disabledMcpjsonServers')
|
|
97
|
+
) {
|
|
98
|
+
saveCurrentProjectConfig(current => {
|
|
99
|
+
const {
|
|
100
|
+
enableAllProjectMcpServers: _enableAll,
|
|
101
|
+
enabledMcpjsonServers: _enabledServers,
|
|
102
|
+
disabledMcpjsonServers: _disabledServers,
|
|
103
|
+
...configWithoutFields
|
|
104
|
+
} = current
|
|
105
|
+
return configWithoutFields
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Log the migration event
|
|
110
|
+
logEvent('tengu_migrate_mcp_approval_fields_success', {
|
|
111
|
+
migratedCount: fieldsToRemove.length,
|
|
112
|
+
})
|
|
113
|
+
} catch (e: unknown) {
|
|
114
|
+
// Log migration failure but don't throw to avoid breaking startup
|
|
115
|
+
logError(e)
|
|
116
|
+
logEvent('tengu_migrate_mcp_approval_fields_error', {})
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getSettingsForSource,
|
|
3
|
+
updateSettingsForSource,
|
|
4
|
+
} from '../utils/settings/settings.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Migrate users on removed fennec model aliases to their new Opus 4.6 aliases.
|
|
8
|
+
* - fennec-latest → opus
|
|
9
|
+
* - fennec-latest[1m] → opus[1m]
|
|
10
|
+
* - fennec-fast-latest → opus[1m] + fast mode
|
|
11
|
+
* - opus-4-5-fast → opus + fast mode
|
|
12
|
+
*
|
|
13
|
+
* Only touches userSettings. Reading and writing the same source keeps this
|
|
14
|
+
* idempotent without a completion flag. Fennec aliases in project/local/policy
|
|
15
|
+
* settings are left alone — we can't rewrite those, and reading merged
|
|
16
|
+
* settings here would cause infinite re-runs + silent global promotion.
|
|
17
|
+
*/
|
|
18
|
+
export function migrateFennecToOpus(): void {
|
|
19
|
+
if (process.env.USER_TYPE !== 'ant') {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const settings = getSettingsForSource('userSettings')
|
|
24
|
+
|
|
25
|
+
const model = settings?.model
|
|
26
|
+
if (typeof model === 'string') {
|
|
27
|
+
if (model.startsWith('fennec-latest[1m]')) {
|
|
28
|
+
updateSettingsForSource('userSettings', {
|
|
29
|
+
model: 'opus[1m]',
|
|
30
|
+
})
|
|
31
|
+
} else if (model.startsWith('fennec-latest')) {
|
|
32
|
+
updateSettingsForSource('userSettings', {
|
|
33
|
+
model: 'opus',
|
|
34
|
+
})
|
|
35
|
+
} else if (
|
|
36
|
+
model.startsWith('fennec-fast-latest') ||
|
|
37
|
+
model.startsWith('opus-4-5-fast')
|
|
38
|
+
) {
|
|
39
|
+
updateSettingsForSource('userSettings', {
|
|
40
|
+
model: 'opus[1m]',
|
|
41
|
+
fastMode: true,
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|