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.
Files changed (117) hide show
  1. package/assistant/sessionHistory.ts +87 -0
  2. package/bootstrap/state.ts +1769 -0
  3. package/bridge/bridgeApi.ts +539 -0
  4. package/bridge/bridgeConfig.ts +48 -0
  5. package/bridge/bridgeDebug.ts +135 -0
  6. package/bridge/bridgeEnabled.ts +202 -0
  7. package/bridge/bridgeMain.ts +2999 -0
  8. package/bridge/bridgeMessaging.ts +461 -0
  9. package/bridge/bridgePermissionCallbacks.ts +43 -0
  10. package/bridge/bridgePointer.ts +210 -0
  11. package/bridge/bridgeStatusUtil.ts +163 -0
  12. package/bridge/bridgeUI.ts +530 -0
  13. package/bridge/capacityWake.ts +56 -0
  14. package/bridge/codeSessionApi.ts +168 -0
  15. package/bridge/createSession.ts +384 -0
  16. package/bridge/debugUtils.ts +141 -0
  17. package/bridge/envLessBridgeConfig.ts +165 -0
  18. package/bridge/flushGate.ts +71 -0
  19. package/bridge/inboundAttachments.ts +175 -0
  20. package/bridge/inboundMessages.ts +80 -0
  21. package/bridge/initReplBridge.ts +569 -0
  22. package/bridge/jwtUtils.ts +256 -0
  23. package/bridge/pollConfig.ts +110 -0
  24. package/bridge/pollConfigDefaults.ts +82 -0
  25. package/bridge/remoteBridgeCore.ts +1008 -0
  26. package/bridge/replBridge.ts +2406 -0
  27. package/bridge/replBridgeHandle.ts +36 -0
  28. package/bridge/replBridgeTransport.ts +370 -0
  29. package/bridge/sessionIdCompat.ts +57 -0
  30. package/bridge/sessionRunner.ts +550 -0
  31. package/bridge/trustedDevice.ts +210 -0
  32. package/bridge/types.ts +262 -0
  33. package/bridge/workSecret.ts +127 -0
  34. package/buddy/CompanionSprite.tsx +371 -0
  35. package/buddy/companion.ts +133 -0
  36. package/buddy/prompt.ts +36 -0
  37. package/buddy/sprites.ts +514 -0
  38. package/buddy/types.ts +148 -0
  39. package/buddy/useBuddyNotification.tsx +98 -0
  40. package/coordinator/coordinatorMode.ts +369 -0
  41. package/memdir/findRelevantMemories.ts +141 -0
  42. package/memdir/memdir.ts +507 -0
  43. package/memdir/memoryAge.ts +53 -0
  44. package/memdir/memoryScan.ts +94 -0
  45. package/memdir/memoryTypes.ts +271 -0
  46. package/memdir/paths.ts +278 -0
  47. package/memdir/teamMemPaths.ts +292 -0
  48. package/memdir/teamMemPrompts.ts +100 -0
  49. package/migrations/migrateAutoUpdatesToSettings.ts +61 -0
  50. package/migrations/migrateBypassPermissionsAcceptedToSettings.ts +40 -0
  51. package/migrations/migrateEnableAllProjectMcpServersToSettings.ts +118 -0
  52. package/migrations/migrateFennecToOpus.ts +45 -0
  53. package/migrations/migrateLegacyOpusToCurrent.ts +57 -0
  54. package/migrations/migrateOpusToOpus1m.ts +43 -0
  55. package/migrations/migrateReplBridgeEnabledToRemoteControlAtStartup.ts +22 -0
  56. package/migrations/migrateSonnet1mToSonnet45.ts +48 -0
  57. package/migrations/migrateSonnet45ToSonnet46.ts +67 -0
  58. package/migrations/resetAutoModeOptInForDefaultOffer.ts +51 -0
  59. package/migrations/resetProToOpusDefault.ts +51 -0
  60. package/native-ts/color-diff/index.ts +999 -0
  61. package/native-ts/file-index/index.ts +370 -0
  62. package/native-ts/yoga-layout/enums.ts +134 -0
  63. package/native-ts/yoga-layout/index.ts +2578 -0
  64. package/outputStyles/loadOutputStylesDir.ts +98 -0
  65. package/package.json +22 -5
  66. package/plugins/builtinPlugins.ts +159 -0
  67. package/plugins/bundled/index.ts +23 -0
  68. package/schemas/hooks.ts +222 -0
  69. package/screens/Doctor.tsx +575 -0
  70. package/screens/REPL.tsx +5006 -0
  71. package/screens/ResumeConversation.tsx +399 -0
  72. package/server/createDirectConnectSession.ts +88 -0
  73. package/server/directConnectManager.ts +213 -0
  74. package/server/types.ts +57 -0
  75. package/skills/bundled/batch.ts +124 -0
  76. package/skills/bundled/claudeApi.ts +196 -0
  77. package/skills/bundled/claudeApiContent.ts +75 -0
  78. package/skills/bundled/claudeInChrome.ts +34 -0
  79. package/skills/bundled/debug.ts +103 -0
  80. package/skills/bundled/index.ts +79 -0
  81. package/skills/bundled/keybindings.ts +339 -0
  82. package/skills/bundled/loop.ts +92 -0
  83. package/skills/bundled/loremIpsum.ts +282 -0
  84. package/skills/bundled/remember.ts +82 -0
  85. package/skills/bundled/scheduleRemoteAgents.ts +447 -0
  86. package/skills/bundled/simplify.ts +69 -0
  87. package/skills/bundled/skillify.ts +197 -0
  88. package/skills/bundled/stuck.ts +79 -0
  89. package/skills/bundled/updateConfig.ts +475 -0
  90. package/skills/bundled/verify/SKILL.md +3 -0
  91. package/skills/bundled/verify/examples/cli.md +3 -0
  92. package/skills/bundled/verify/examples/server.md +3 -0
  93. package/skills/bundled/verify.ts +30 -0
  94. package/skills/bundled/verifyContent.ts +13 -0
  95. package/skills/bundledSkills.ts +220 -0
  96. package/skills/loadSkillsDir.ts +1086 -0
  97. package/skills/mcpSkillBuilders.ts +44 -0
  98. package/tasks/DreamTask/DreamTask.ts +157 -0
  99. package/tasks/InProcessTeammateTask/InProcessTeammateTask.tsx +126 -0
  100. package/tasks/InProcessTeammateTask/types.ts +121 -0
  101. package/tasks/LocalAgentTask/LocalAgentTask.tsx +683 -0
  102. package/tasks/LocalMainSessionTask.ts +479 -0
  103. package/tasks/LocalShellTask/LocalShellTask.tsx +523 -0
  104. package/tasks/LocalShellTask/guards.ts +41 -0
  105. package/tasks/LocalShellTask/killShellTasks.ts +76 -0
  106. package/tasks/RemoteAgentTask/RemoteAgentTask.tsx +856 -0
  107. package/tasks/pillLabel.ts +82 -0
  108. package/tasks/stopTask.ts +100 -0
  109. package/tasks/types.ts +46 -0
  110. package/upstreamproxy/relay.ts +455 -0
  111. package/upstreamproxy/upstreamproxy.ts +285 -0
  112. package/vim/motions.ts +82 -0
  113. package/vim/operators.ts +556 -0
  114. package/vim/textObjects.ts +186 -0
  115. package/vim/transitions.ts +490 -0
  116. package/vim/types.ts +199 -0
  117. package/voice/voiceModeEnabled.ts +54 -0
@@ -0,0 +1,220 @@
1
+ import type { ContentBlockParam } from '@anthropic-ai/sdk/resources/index.mjs'
2
+ import { constants as fsConstants } from 'fs'
3
+ import { mkdir, open } from 'fs/promises'
4
+ import { dirname, isAbsolute, join, normalize, sep as pathSep } from 'path'
5
+ import type { ToolUseContext } from '../Tool.js'
6
+ import type { Command } from '../types/command.js'
7
+ import { logForDebugging } from '../utils/debug.js'
8
+ import { getBundledSkillsRoot } from '../utils/permissions/filesystem.js'
9
+ import type { HooksSettings } from '../utils/settings/types.js'
10
+
11
+ /**
12
+ * Definition for a bundled skill that ships with the CLI.
13
+ * These are registered programmatically at startup.
14
+ */
15
+ export type BundledSkillDefinition = {
16
+ name: string
17
+ description: string
18
+ aliases?: string[]
19
+ whenToUse?: string
20
+ argumentHint?: string
21
+ allowedTools?: string[]
22
+ model?: string
23
+ disableModelInvocation?: boolean
24
+ userInvocable?: boolean
25
+ isEnabled?: () => boolean
26
+ hooks?: HooksSettings
27
+ context?: 'inline' | 'fork'
28
+ agent?: string
29
+ /**
30
+ * Additional reference files to extract to disk on first invocation.
31
+ * Keys are relative paths (forward slashes, no `..`), values are content.
32
+ * When set, the skill prompt is prefixed with a "Base directory for this
33
+ * skill: <dir>" line so the model can Read/Grep these files on demand —
34
+ * same contract as disk-based skills.
35
+ */
36
+ files?: Record<string, string>
37
+ getPromptForCommand: (
38
+ args: string,
39
+ context: ToolUseContext,
40
+ ) => Promise<ContentBlockParam[]>
41
+ }
42
+
43
+ // Internal registry for bundled skills
44
+ const bundledSkills: Command[] = []
45
+
46
+ /**
47
+ * Register a bundled skill that will be available to the model.
48
+ * Call this at module initialization or in an init function.
49
+ *
50
+ * Bundled skills are compiled into the CLI binary and available to all users.
51
+ * They follow the same pattern as registerPostSamplingHook() for internal features.
52
+ */
53
+ export function registerBundledSkill(definition: BundledSkillDefinition): void {
54
+ const { files } = definition
55
+
56
+ let skillRoot: string | undefined
57
+ let getPromptForCommand = definition.getPromptForCommand
58
+
59
+ if (files && Object.keys(files).length > 0) {
60
+ skillRoot = getBundledSkillExtractDir(definition.name)
61
+ // Closure-local memoization: extract once per process.
62
+ // Memoize the promise (not the result) so concurrent callers await
63
+ // the same extraction instead of racing into separate writes.
64
+ let extractionPromise: Promise<string | null> | undefined
65
+ const inner = definition.getPromptForCommand
66
+ getPromptForCommand = async (args, ctx) => {
67
+ extractionPromise ??= extractBundledSkillFiles(definition.name, files)
68
+ const extractedDir = await extractionPromise
69
+ const blocks = await inner(args, ctx)
70
+ if (extractedDir === null) return blocks
71
+ return prependBaseDir(blocks, extractedDir)
72
+ }
73
+ }
74
+
75
+ const command: Command = {
76
+ type: 'prompt',
77
+ name: definition.name,
78
+ description: definition.description,
79
+ aliases: definition.aliases,
80
+ hasUserSpecifiedDescription: true,
81
+ allowedTools: definition.allowedTools ?? [],
82
+ argumentHint: definition.argumentHint,
83
+ whenToUse: definition.whenToUse,
84
+ model: definition.model,
85
+ disableModelInvocation: definition.disableModelInvocation ?? false,
86
+ userInvocable: definition.userInvocable ?? true,
87
+ contentLength: 0, // Not applicable for bundled skills
88
+ source: 'bundled',
89
+ loadedFrom: 'bundled',
90
+ hooks: definition.hooks,
91
+ skillRoot,
92
+ context: definition.context,
93
+ agent: definition.agent,
94
+ isEnabled: definition.isEnabled,
95
+ isHidden: !(definition.userInvocable ?? true),
96
+ progressMessage: 'running',
97
+ getPromptForCommand,
98
+ }
99
+ bundledSkills.push(command)
100
+ }
101
+
102
+ /**
103
+ * Get all registered bundled skills.
104
+ * Returns a copy to prevent external mutation.
105
+ */
106
+ export function getBundledSkills(): Command[] {
107
+ return [...bundledSkills]
108
+ }
109
+
110
+ /**
111
+ * Clear bundled skills registry (for testing).
112
+ */
113
+ export function clearBundledSkills(): void {
114
+ bundledSkills.length = 0
115
+ }
116
+
117
+ /**
118
+ * Deterministic extraction directory for a bundled skill's reference files.
119
+ */
120
+ export function getBundledSkillExtractDir(skillName: string): string {
121
+ return join(getBundledSkillsRoot(), skillName)
122
+ }
123
+
124
+ /**
125
+ * Extract a bundled skill's reference files to disk so the model can
126
+ * Read/Grep them on demand. Called lazily on first skill invocation.
127
+ *
128
+ * Returns the directory written to, or null if write failed (skill
129
+ * continues to work, just without the base-directory prefix).
130
+ */
131
+ async function extractBundledSkillFiles(
132
+ skillName: string,
133
+ files: Record<string, string>,
134
+ ): Promise<string | null> {
135
+ const dir = getBundledSkillExtractDir(skillName)
136
+ try {
137
+ await writeSkillFiles(dir, files)
138
+ return dir
139
+ } catch (e) {
140
+ logForDebugging(
141
+ `Failed to extract bundled skill '${skillName}' to ${dir}: ${e instanceof Error ? e.message : String(e)}`,
142
+ )
143
+ return null
144
+ }
145
+ }
146
+
147
+ async function writeSkillFiles(
148
+ dir: string,
149
+ files: Record<string, string>,
150
+ ): Promise<void> {
151
+ // Group by parent dir so we mkdir each subtree once, then write.
152
+ const byParent = new Map<string, [string, string][]>()
153
+ for (const [relPath, content] of Object.entries(files)) {
154
+ const target = resolveSkillFilePath(dir, relPath)
155
+ const parent = dirname(target)
156
+ const entry: [string, string] = [target, content]
157
+ const group = byParent.get(parent)
158
+ if (group) group.push(entry)
159
+ else byParent.set(parent, [entry])
160
+ }
161
+ await Promise.all(
162
+ [...byParent].map(async ([parent, entries]) => {
163
+ await mkdir(parent, { recursive: true, mode: 0o700 })
164
+ await Promise.all(entries.map(([p, c]) => safeWriteFile(p, c)))
165
+ }),
166
+ )
167
+ }
168
+
169
+ // The per-process nonce in getBundledSkillsRoot() is the primary defense
170
+ // against pre-created symlinks/dirs. Explicit 0o700/0o600 modes keep the
171
+ // nonce subtree owner-only even on umask=0, so an attacker who learns the
172
+ // nonce via inotify on the predictable parent still can't write into it.
173
+ // O_NOFOLLOW|O_EXCL is belt-and-suspenders (O_NOFOLLOW only protects the
174
+ // final component); we deliberately do NOT unlink+retry on EEXIST — unlink()
175
+ // follows intermediate symlinks too.
176
+ const O_NOFOLLOW = fsConstants.O_NOFOLLOW ?? 0
177
+ // On Windows, use string flags — numeric O_EXCL can produce EINVAL through libuv.
178
+ const SAFE_WRITE_FLAGS =
179
+ process.platform === 'win32'
180
+ ? 'wx'
181
+ : fsConstants.O_WRONLY |
182
+ fsConstants.O_CREAT |
183
+ fsConstants.O_EXCL |
184
+ O_NOFOLLOW
185
+
186
+ async function safeWriteFile(p: string, content: string): Promise<void> {
187
+ const fh = await open(p, SAFE_WRITE_FLAGS, 0o600)
188
+ try {
189
+ await fh.writeFile(content, 'utf8')
190
+ } finally {
191
+ await fh.close()
192
+ }
193
+ }
194
+
195
+ /** Normalize and validate a skill-relative path; throws on traversal. */
196
+ function resolveSkillFilePath(baseDir: string, relPath: string): string {
197
+ const normalized = normalize(relPath)
198
+ if (
199
+ isAbsolute(normalized) ||
200
+ normalized.split(pathSep).includes('..') ||
201
+ normalized.split('/').includes('..')
202
+ ) {
203
+ throw new Error(`bundled skill file path escapes skill dir: ${relPath}`)
204
+ }
205
+ return join(baseDir, normalized)
206
+ }
207
+
208
+ function prependBaseDir(
209
+ blocks: ContentBlockParam[],
210
+ baseDir: string,
211
+ ): ContentBlockParam[] {
212
+ const prefix = `Base directory for this skill: ${baseDir}\n\n`
213
+ if (blocks.length > 0 && blocks[0]!.type === 'text') {
214
+ return [
215
+ { type: 'text', text: prefix + blocks[0]!.text },
216
+ ...blocks.slice(1),
217
+ ]
218
+ }
219
+ return [{ type: 'text', text: prefix }, ...blocks]
220
+ }