gen-cordis-catalog.ts 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160
  1. /**
  2. * Generate the per-subsystem Cordis service/event reference regions from the
  3. * Typert catalog projection. Every harness `ctx.<key>` service and event scope
  4. * maps to exactly one `docs/subsystems/` page through the curated tables below;
  5. * the generator injects each page's Cordis API reference between its GENERATED markers —
  6. * into both language sides of the pair, localizing paired document paths for
  7. * the Chinese side while retaining every other byte — and re-records a pair's
  8. * `.i18n.yaml` only when nothing outside the region changed. The
  9. * projection enforces event modes, JSDoc parameter/return completeness, and
  10. * signature type-link coverage; the inherited (vendor) tier renders to
  11. * `docs/cordis-api/inherited.md`. `--check` verifies every generated artifact.
  12. *
  13. * Generated regions embed `file:line` source pointers, so inserting lines ABOVE a
  14. * recorded symbol makes the committed output stale even though nothing about the
  15. * symbol changed. Regenerate after editing any file this projection records — the
  16. * failure otherwise surfaces as the "reproduces every committed catalog artifact
  17. * byte for byte" test failing, which reads like a snapshot regression rather than
  18. * a missing regeneration.
  19. */
  20. import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
  21. import { dirname, resolve } from 'node:path'
  22. import {
  23. projectCordisCatalog,
  24. renderInheritedPage,
  25. renderPageRegion,
  26. REGION_BEGIN,
  27. REGION_END,
  28. } from '@deepseek-ai/dsh-typert-generator'
  29. import type { CordisCatalogPolicy } from '@deepseek-ai/dsh-typert-generator'
  30. import { renderCordisCoreApiPages } from './cordis-core-api.ts'
  31. import { contextKeyMap, contextMergeFiles, eventNameList } from './cordis-walk.ts'
  32. import {
  33. blobHash,
  34. parsePairMeta,
  35. parseTranslationPairingManifest,
  36. partitionGeneratedRegions,
  37. renderPairMeta,
  38. translationPairSourcePredicate,
  39. } from './translation-pairing.ts'
  40. import { rewriteTranslationLinkLocales } from './translation-links.ts'
  41. const root = resolve(import.meta.dirname, '..')
  42. const SUBSYSTEMS_DIR = 'docs/subsystems'
  43. const OUT_INHERITED = 'docs/cordis-api/inherited.md'
  44. const OUT_RUNTIME_API = 'packages/extensions/tool-cordis/src/api-catalog.ts'
  45. export { REGION_BEGIN, REGION_END }
  46. /**
  47. * The owning subsystems page for every harness `ctx.<key>` service the
  48. * projection discovers. Fail-closed both ways: a discovered key absent here
  49. * and an entry whose key the projection no longer discovers are both hard
  50. * errors, so the partition can never silently drift from the service API.
  51. */
  52. export const SERVICE_PAGE: Record<string, string> = {
  53. agentLoop: 'core.md',
  54. agentDefaultModel: 'core.md',
  55. agentPresets: 'core.md',
  56. agents: 'core.md',
  57. approval: 'approval.md',
  58. attachments: 'attachment.md',
  59. shell: 'shell.md',
  60. shellEnv: 'shell.md',
  61. clientModules: 'client-modules.md',
  62. codeRuntime: 'code-runtime.md',
  63. commands: 'commands.md',
  64. compaction: 'compaction.md',
  65. cordisInspect: 'extensions.md',
  66. authorization: 'credentials.md',
  67. credentials: 'credentials.md',
  68. credentialsController: 'credentials.md',
  69. settingsController: 'settings.md',
  70. directoryPicker: 'workspace.md',
  71. deepseekLlmApiExtensions: 'llm-streaming.md',
  72. dynamicCordisRunner: 'extensions.md',
  73. e2b: 'subprocess.md',
  74. fileUploads: 'attachment.md',
  75. fileReferences: 'session-reference.md',
  76. fs: 'filesystem.md',
  77. goals: 'goal.md',
  78. inspector: 'extensions.md',
  79. webServer: 'web-server.md',
  80. invariants: 'invariants.md',
  81. llm: 'llm-streaming.md',
  82. lsp: 'lsp.md',
  83. messageFeedback: 'feedback.md',
  84. sessionFeedback: 'feedback.md',
  85. permissionPresets: 'permission-presets.md',
  86. planMode: 'plan.md',
  87. terminals: 'terminal.md',
  88. sandbox: 'sandbox.md',
  89. sandboxPolicy: 'sandbox.md',
  90. sessionPersistence: 'persistence.md',
  91. sessionQuery: 'session-query.md',
  92. sessionFileReferences: 'session-reference.md',
  93. sessionReferenceResolver: 'session-reference.md',
  94. sessionProjectionCache: 'session-projection.md',
  95. sessionProjections: 'session-projection.md',
  96. sessionController: 'session.md',
  97. sessionSkillCatalog: 'skills.md',
  98. sessions: 'session.md',
  99. settings: 'settings.md',
  100. sessionTitle: 'session-title.md',
  101. skills: 'skills.md',
  102. spillStore: 'spill.md',
  103. storage: 'storage.md',
  104. storageDomain: 'storage.md',
  105. subagentModelSelection: 'subagent.md',
  106. subagents: 'subagent.md',
  107. subprocess: 'subprocess.md',
  108. systemPrompt: 'system-prompt.md',
  109. jobs: 'jobs.md',
  110. sessionTelemetry: 'session-telemetry.md',
  111. agentTeams: 'agent-team.md',
  112. tokenMeter: 'token-meter.md',
  113. toolResultPruner: 'compaction.md',
  114. tools: 'tools.md',
  115. typert: 'typert.md',
  116. typertGateway: 'typert.md',
  117. userQuestions: 'user-questions.md',
  118. web: 'web.md',
  119. workflowEngine: 'workflow.md',
  120. webhookRuntime: 'webhook.md',
  121. workspaceRegistry: 'workspace.md',
  122. workspaceController: 'workspace.md',
  123. workspaceFiles: 'workspace.md',
  124. directoryPickerController: 'workspace.md',
  125. }
  126. /**
  127. * Context keys declared in `interface Context` merges that the rendering
  128. * projection cannot see, each with the reason and its documentation owner.
  129. * The scan that enforces this list reads EVERY `declare module '@deepseek-ai/cordis'`
  130. * Context merge under `packages/x/x/src/**` — any depth, not only root
  131. * `index.ts` files with a same-named service class — so a new service can
  132. * never silently join this blind spot: it either enters {@link SERVICE_PAGE}
  133. * or names itself here. Client-face keys (the projection analyzes the host
  134. * face only) name the package README that owns their surface.
  135. *
  136. * Two categories remain, and neither is a projection gap a scanning rule could
  137. * close. An OPTIONAL key (`key?: X`) is a value the launcher or boot code
  138. * installs before the tree mounts, which the analyzer skips by rule because no
  139. * plugin provides it and `inject` cannot reach it. A client-face key belongs to
  140. * the browser Context, which this host-face program never sees; the browser
  141. * surface has its own generated catalog (`scripts/gen-client-catalog.ts`, served
  142. * to a model as `cordis_runtime_inspect what:"client"`).
  143. */
  144. export const SERVICE_WALK_EXEMPTIONS: Record<string, string> = {
  145. appReady: 'not a service: launcher-provided successful-startup signal — packages/boot/cmdline/README.md owns the launcher contract',
  146. appExit: 'not a service: launcher-provided bounded process-exit callback — packages/boot/cmdline/README.md owns the launcher contract',
  147. cmdlineArgs: 'not a service: launcher-provided immutable app argument accessor — packages/boot/cmdline/README.md owns the launcher contract',
  148. configuredAgentIdentities: 'not a service: launcher-provided boot-context value (ConfiguredAgentIdentities | undefined) — packages/core/agent-loop/README.md owns this launcher contract',
  149. launcherSessionQueryPath: 'not a service: launcher-provided boot-context value (string | undefined) — packages/session-query/session-query-sqlite/README.md owns this launcher contract',
  150. dshHomePath: 'not a service: boot-provided root accessor function (typeof dshHomePath | undefined) for Loader !!js config expressions — packages/boot/app-boot/README.md owns the boot contract',
  151. launchEnvironment: 'not a service: launcher-provided root accessor value (LaunchEnvironmentSnapshot | undefined) — packages/util/launch-environment/README.md owns this launcher contract',
  152. connection: 'interface-typed (HostConnectionHandle); implementing class HostConnectionService is declared in rpc-host.ts — packages/client/connection/README.md owns the API',
  153. fileUpload: 'client-side browser upload service — packages/client/file-upload/README.md owns the API',
  154. uiRenderer: 'client-side interface-typed browser service — packages/client/ui-renderer/README.md owns the API',
  155. uiSession: 'client-side Session source adapter — packages/client/ui-session/README.md owns the API',
  156. uiConversation: 'client-side Conversation registries and assembler — packages/client/ui-conversation/README.md owns the API',
  157. uiWorkspace: 'client-side Workspace navigation adapter — packages/client/ui-workspace/README.md owns the API',
  158. settingsSchema: 'client-side schema introspection service — packages/client/ui-settings/README.md owns the API',
  159. settingsScope: 'client-side settings-namespace transport service — packages/client/ui-settings/README.md owns the API',
  160. chatFileMentions: 'client-side slot-contract accessor (ChatFileMentions) — packages/client/ui-chat/README.md owns the API',
  161. commandUi: 'client-side interface-typed browser service — packages/client/ui-commands/README.md owns the API',
  162. conversation: 'client-side interface-typed browser service — packages/client/ui-conversation/README.md owns the API',
  163. layout: 'client-side interface-typed browser service — packages/client/ui-layout/README.md owns the API',
  164. locale: 'client-side interface-typed browser service — packages/client/locale/README.md owns the API',
  165. modelDirectories: 'client-side interface-typed browser service — packages/client/ui-model-selection/README.md owns the API',
  166. modules: 'client-side interface-typed browser service — packages/client/modules/README.md owns the API',
  167. remote: 'client-side interface-typed gateway accessor (ClientRemote) — packages/api/gateway/README.md owns the API',
  168. sessionLogDownload: 'client-side browser download controller — packages/session-query/session-log-export/README.md owns the API',
  169. inputTriggers: 'client-side interface-typed browser service — packages/client/ui-input-trigger/README.md owns the API',
  170. timer: 'client-side dynamic-package timer service — packages/extensions/cordis-client-runner/README.md owns the API',
  171. slots: 'client-side interface-typed browser service — packages/client/ui-renderer/README.md owns the API',
  172. theme: 'client-side interface-typed browser service — packages/client/ui-theme/README.md owns the API',
  173. workspaces: 'client-side interface-typed browser service — packages/api/workspace-controller/README.md owns the API',
  174. resources: 'client-side resource model (protocol providers, pins, live sources) — packages/client/resources/README.md owns the API',
  175. sidebarRight: 'client-side right-Sidebar navigation face — packages/client/ui-sidebar-right/README.md owns the API',
  176. sidebarRightTabs: 'client-side right-Sidebar tab-type registry — packages/client/ui-sidebar-right/README.md owns the API',
  177. documentPreviews: 'client-side document renderer registry — docs/subsystems/sidebar-right.md owns the API',
  178. }
  179. /**
  180. * The owning subsystems page for every harness event scope (the segment
  181. * before the first `/`) the projection renders. Fail-closed exactly like
  182. * {@link SERVICE_PAGE}. Client-face events (`slash/*`, `theme/change`, …) are
  183. * invisible to the host-face projection and therefore never reach this map;
  184. * {@link EVENT_WALK_EXEMPTIONS} names each one with its documentation owner.
  185. */
  186. export const EVENT_SCOPE_PAGE: Record<string, string> = {
  187. 'agent': 'core.md',
  188. 'agent-loop': 'core.md',
  189. 'agent-preset': 'core.md',
  190. 'api-session': 'session.md',
  191. 'approval': 'approval.md',
  192. 'commands': 'commands.md',
  193. 'cordis': 'extensions.md',
  194. 'authorization': 'credentials.md',
  195. 'credentials': 'credentials.md',
  196. 'domain': 'storage.md',
  197. 'fs': 'filesystem.md',
  198. 'goal': 'goal.md',
  199. 'llm': 'llm-streaming.md',
  200. 'session': 'session.md',
  201. 'settings': 'settings.md',
  202. 'skills': 'skills.md',
  203. 'subagent': 'subagent.md',
  204. 'system-prompt': 'system-prompt.md',
  205. 'session-telemetry': 'session-telemetry.md',
  206. 'feedback': 'feedback.md',
  207. 'tools': 'tools.md',
  208. 'user-questions': 'user-questions.md',
  209. 'webserver': 'web-server.md',
  210. 'workflow': 'workflow.md',
  211. }
  212. /**
  213. * Event names declared in `interface Events` merges that the rendering
  214. * projection cannot see, each with the reason and its documentation owner.
  215. * The mirror of {@link SERVICE_WALK_EXEMPTIONS} for events: an independent
  216. * scan reads EVERY `declare module '@deepseek-ai/cordis'` Events merge under
  217. * `packages/x/x/src/**`, so a declared event either renders onto a subsystems
  218. * page (via {@link EVENT_SCOPE_PAGE}) or names itself here — never vanishes
  219. * silently. Keys are full event names rather than scopes, so a scope-level
  220. * exemption cannot mask another declaration in that scope.
  221. */
  222. export const EVENT_WALK_EXEMPTIONS: Record<string, string> = {
  223. 'command/executed': 'client-face local command acknowledgment — packages/client/ui-commands/README.md owns the API',
  224. 'connection/reset': 'client-face transport signal — packages/api/session-controller/README.md owns the API',
  225. 'locale/change': 'client-face locale switch signal — packages/client/locale/README.md owns the API',
  226. 'slash/input-begin-command': 'client-face slash-input protocol — packages/client/ui-input-trigger/README.md owns the API',
  227. 'slash/input-consume-token': 'client-face slash-input protocol — packages/client/ui-input-trigger/README.md owns the API',
  228. 'slash/input-insert-reference': 'client-face slash-input protocol — packages/client/ui-input-trigger/README.md owns the API',
  229. 'slash/input-insert-text': 'client-face slash-input protocol — packages/client/ui-input-trigger/README.md owns the API',
  230. 'slots/changed': 'client-face slot invalidation signal — packages/client/ui-renderer/README.md owns the API',
  231. 'theme/change': 'client-face theme switch signal — packages/client/ui-theme/README.md owns the API',
  232. }
  233. /**
  234. * One primary subsystems page per project type used by a generated
  235. * signature. This stays curated because union names intentionally do not
  236. * reuse the type-equivalence manifest's map-symbol entries and some symbols
  237. * appear on more than one page.
  238. */
  239. export const LINK_MAP: Readonly<Record<string, string>> = {
  240. Agent: 'core.md',
  241. AgentCancelCause: 'core.md',
  242. AgentFactory: 'core.md',
  243. AgentHandle: 'core.md',
  244. ModelSelection: 'core.md',
  245. AllowedModelRoute: 'subagent.md',
  246. SubagentModelSelectionSettings: 'subagent.md',
  247. AgentOptions: 'core.md',
  248. AgentStatus: 'core.md',
  249. AssistantStreamFrame: 'core.md',
  250. ContentBlock: 'llm-streaming.md',
  251. CreateAgentOptions: 'core.md',
  252. GenerateOptions: 'llm-streaming.md',
  253. Inbox: 'core.md',
  254. InboxItem: 'core.md',
  255. InboxPlacement: 'core.md',
  256. InspectorJsonValue: 'extensions.md',
  257. MessageId: 'llm-streaming.md',
  258. ResumeAgentOptions: 'core.md',
  259. SettleReason: 'core.md',
  260. AdapterRegistrationHandle: 'llm-streaming.md',
  261. DirectoryRegistrationHandle: 'llm-streaming.md',
  262. DeepSeekLlmApiExtensionMap: 'llm-streaming.md',
  263. DeepSeekLlmApiExtensionProvider: 'llm-streaming.md',
  264. DeepSeekLlmApiExtensionRequest: 'llm-streaming.md',
  265. LlmCallConfig: 'llm-streaming.md',
  266. LlmModelContext: 'llm-streaming.md',
  267. LlmModelReasoningInfo: 'llm-streaming.md',
  268. LlmResolvedModelInfo: 'llm-streaming.md',
  269. LlmFailure: 'llm-streaming.md',
  270. LlmImageRequestPricing: 'llm-streaming.md',
  271. LlmModelInfo: 'llm-streaming.md',
  272. LlmProviderInfo: 'llm-streaming.md',
  273. LlmConfigurableProvider: 'llm-streaming.md',
  274. LlmModelDiscoveryRequest: 'llm-streaming.md',
  275. LlmDiscoveredModel: 'llm-streaming.md',
  276. ResolvedRetryPolicy: 'llm-streaming.md',
  277. Message: 'llm-streaming.md',
  278. MessageSource: 'llm-streaming.md',
  279. MessageFeedbackDeleteRequest: 'feedback.md',
  280. MessageFeedbackDeleteResult: 'feedback.md',
  281. MessageFeedbackDeleteValue: 'feedback.md',
  282. MessageFeedbackFailure: 'feedback.md',
  283. MessageFeedbackItem: 'feedback.md',
  284. MessageFeedbackListRequest: 'feedback.md',
  285. SessionFeedbackRecordRequest: 'feedback.md',
  286. SessionFeedbackRecordResult: 'feedback.md',
  287. MessageFeedbackListResult: 'feedback.md',
  288. MessageFeedbackListValue: 'feedback.md',
  289. MessageFeedbackNoteBlank: 'feedback.md',
  290. MessageFeedbackNoteTooLarge: 'feedback.md',
  291. MessageFeedbackPutRequest: 'feedback.md',
  292. MessageFeedbackPutResult: 'feedback.md',
  293. MessageFeedbackRating: 'feedback.md',
  294. MessageFeedbackRejected: 'feedback.md',
  295. MessageFeedbackSessionNotFound: 'feedback.md',
  296. MessageFeedbackSuccess: 'feedback.md',
  297. MessageFeedbackTargetNotFound: 'feedback.md',
  298. MessageFeedbackVersion: 'feedback.md',
  299. MessageFeedbackVersionConflict: 'feedback.md',
  300. UserMessage: 'session.md',
  301. ApiSessionAgentResult: 'session.md',
  302. PreStepDecision: 'core.md',
  303. PreStepContext: 'core.md',
  304. RequestErrorAction: 'core.md',
  305. RequestFailureContext: 'core.md',
  306. PreparedReferencedMessage: 'session-reference.md',
  307. FileReferenceCandidate: 'session-reference.md',
  308. SessionReferenceCandidate: 'session-reference.md',
  309. SessionReferenceMentionCandidate: 'session-reference.md',
  310. SessionReferenceInput: 'session-reference.md',
  311. SessionAttachmentRequest: 'session.md',
  312. SessionAttachmentValue: 'session.md',
  313. SessionCancelRequest: 'session.md',
  314. SessionCancelValue: 'session.md',
  315. SessionControlFrame: 'session.md',
  316. SessionCreateRequest: 'session.md',
  317. SessionCreateValue: 'session.md',
  318. SessionEvent: 'session.md',
  319. SessionFollowFrame: 'session.md',
  320. SessionFollowRequest: 'session.md',
  321. SessionForkRequest: 'session.md',
  322. SessionForkValue: 'session.md',
  323. SessionId: 'core.md',
  324. SessionLogOffset: 'session.md',
  325. SessionSeq: 'session.md',
  326. SessionSeqCursor: 'session.md',
  327. OptionalSessionSeq: 'session.md',
  328. SessionListRequest: 'session.md',
  329. SessionListValue: 'session.md',
  330. ModelCatalog: 'session.md',
  331. SessionOpenWorkspacePathRequest: 'session.md',
  332. SessionOpenWorkspacePathValue: 'session.md',
  333. SessionModels: 'session.md',
  334. SessionModelsRequest: 'session.md',
  335. SessionPage: 'session.md',
  336. SessionPageRequest: 'session.md',
  337. SessionPromptRequest: 'session.md',
  338. SessionPromptValue: 'session.md',
  339. SessionRenameRequest: 'session.md',
  340. SessionRenameValue: 'session.md',
  341. SessionRespondReceipt: 'session.md',
  342. SessionRespondRequest: 'session.md',
  343. SessionSearchValue: 'session.md',
  344. SessionSelectModelRequest: 'session.md',
  345. SessionSelectModelValue: 'session.md',
  346. SessionSummary: 'session.md',
  347. SessionUpdateQueueRequest: 'session.md',
  348. SessionUpdateQueueValue: 'session.md',
  349. EncodedFileUploadRequest: 'attachment.md',
  350. AgentResolver: 'attachment.md',
  351. PromptFileBinding: 'attachment.md',
  352. FileUploadReceiptId: 'attachment.md',
  353. FileUploadValue: 'attachment.md',
  354. SessionStartSource: 'core.md',
  355. SessionLogSnapshot: 'session-query.md',
  356. SessionSurfaceSnapshot: 'session-query.md',
  357. ApprovalOutcome: 'approval.md',
  358. ApprovalPolicy: 'approval.md',
  359. ApprovalRequest: 'approval.md',
  360. ApprovalRequestEvent: 'approval.md',
  361. ApprovalService: 'approval.md',
  362. AskUserQuestionRequestEvent: 'user-questions.md',
  363. AdmittedPromptContentPart: 'attachment.md',
  364. AttachmentAdmissionPart: 'attachment.md',
  365. AttachmentError: 'attachment.md',
  366. EncodedFileAttachment: 'attachment.md',
  367. EncodedImageAttachment: 'attachment.md',
  368. FileAttachmentRef: 'attachment.md',
  369. SaveFileAttachment: 'attachment.md',
  370. SaveFileStreamAttachment: 'attachment.md',
  371. ImageAttachmentAccess: 'llm-streaming.md',
  372. ImageAttachmentRef: 'attachment.md',
  373. ImageRequestPolicy: 'attachment.md',
  374. PromptContentPart: 'attachment.md',
  375. RequestImageAttachment: 'attachment.md',
  376. SaveImageAttachment: 'attachment.md',
  377. StoredImageAttachment: 'attachment.md',
  378. ShellExecRequest: 'shell.md',
  379. ShellExecSpec: 'shell.md',
  380. ShellProcess: 'shell.md',
  381. ShellRunResult: 'shell.md',
  382. DshEnvironment: 'subprocess.md',
  383. SubprocessHandle: 'subprocess.md',
  384. SubprocessOutcome: 'subprocess.md',
  385. SubprocessOutputRead: 'subprocess.md',
  386. SubprocessOutputReader: 'subprocess.md',
  387. SubprocessSpawnSpec: 'subprocess.md',
  388. SubprocessTerminalHandle: 'subprocess.md',
  389. SubprocessTerminalSpawnSpec: 'subprocess.md',
  390. CodeRunRequest: 'code-runtime.md',
  391. CodeRunResult: 'code-runtime.md',
  392. CompactionResult: 'compaction.md',
  393. CompactionTrigger: 'compaction.md',
  394. PruneResult: 'compaction.md',
  395. FileReadOutcome: 'filesystem.md',
  396. FsDirEntry: 'filesystem.md',
  397. FsEditOutcome: 'filesystem.md',
  398. FsEditRequest: 'filesystem.md',
  399. FsInfo: 'filesystem.md',
  400. FsObservation: 'filesystem.md',
  401. FsPathInfo: 'filesystem.md',
  402. FsObservationActor: 'filesystem.md',
  403. FsTarget: 'filesystem.md',
  404. FsVersion: 'filesystem.md',
  405. FsWriteIntent: 'filesystem.md',
  406. FsWriteOutcome: 'filesystem.md',
  407. CreateGoalRequest: 'goal.md',
  408. EditGoalRequest: 'goal.md',
  409. GoalBlockReason: 'goal.md',
  410. GoalActivationChanged: 'goal.md',
  411. GoalChanged: 'goal.md',
  412. GoalRef: 'goal.md',
  413. GoalView: 'goal.md',
  414. CreateGoalResult: 'goal.md',
  415. CommandDefinition: 'commands.md',
  416. CommandDescriptor: 'commands.md',
  417. CommandFileReceiptResolver: 'commands.md',
  418. CommandId: 'commands.md',
  419. CommandResult: 'commands.md',
  420. CommandSubmitAttachment: 'commands.md',
  421. CommandSurface: 'commands.md',
  422. LspProvider: 'lsp.md',
  423. LspQueryRequest: 'lsp.md',
  424. LspQueryResult: 'lsp.md',
  425. LlmAdapter: 'llm-streaming.md',
  426. PreparedLlmCall: 'llm-streaming.md',
  427. PreparedDeepSeekLlmApiExtensions: 'llm-streaming.md',
  428. LlmRuntime: 'llm-streaming.md',
  429. StreamChunk: 'llm-streaming.md',
  430. SkillProviderControl: 'skills.md',
  431. CreateSessionOptions: 'persistence.md',
  432. PrepareSessionOptions: 'persistence.md',
  433. SessionHeader: 'persistence.md',
  434. SessionLocation: 'persistence.md',
  435. SessionPreparation: 'persistence.md',
  436. SessionAccess: 'persistence.md',
  437. SessionHandle: 'persistence.md',
  438. SessionPersistenceCreateOptions: 'persistence.md',
  439. SessionPersistenceOpenOptions: 'persistence.md',
  440. SessionPersistenceStatOptions: 'persistence.md',
  441. SessionPersistenceListOptions: 'persistence.md',
  442. SessionPersistenceSnapshot: 'persistence.md',
  443. SessionInspection: 'persistence.md',
  444. SessionStorageMetadata: 'persistence.md',
  445. ConfinedArgv: 'sandbox.md',
  446. SandboxExecutionPolicy: 'sandbox.md',
  447. SandboxMode: 'sandbox.md',
  448. SandboxPolicy: 'sandbox.md',
  449. TerminalBackend: 'terminal.md',
  450. TerminalReadRequest: 'terminal.md',
  451. TerminalReadResult: 'terminal.md',
  452. TerminalSendOperation: 'terminal.md',
  453. TerminalSendRequest: 'terminal.md',
  454. TerminalSessionId: 'terminal.md',
  455. TerminalSessionSnapshot: 'terminal.md',
  456. TerminalSignal: 'terminal.md',
  457. TerminalSignalResult: 'terminal.md',
  458. TerminalSpawnRequest: 'terminal.md',
  459. TerminalSpawnResult: 'terminal.md',
  460. SandboxPolicyRequest: 'sandbox.md',
  461. ScopeKey: 'scope.md',
  462. Scoped: 'scope.md',
  463. EpochHeader: 'session.md',
  464. Session: 'session.md',
  465. SessionEventMap: 'session.md',
  466. TurnEndReason: 'session.md',
  467. TurnTrigger: 'session.md',
  468. SessionEventReadRequest: 'session-query.md',
  469. SessionEventRecord: 'session-query.md',
  470. SessionEventResultFilter: 'session-query.md',
  471. SessionEventSearchDocument: 'session-query.md',
  472. SessionEventSearchHit: 'session-query.md',
  473. SessionEventSearchPage: 'session-query.md',
  474. SessionEventSearchRequest: 'session-query.md',
  475. SessionEventTrace: 'session-query.md',
  476. SessionEventTraceObservation: 'session-query.md',
  477. SessionEventTraceRequest: 'session-query.md',
  478. SessionEventWindow: 'session-query.md',
  479. SessionLineageTrace: 'session-query.md',
  480. SessionObservation: 'session-query.md',
  481. SessionObservationOptions: 'session-query.md',
  482. SessionRecord: 'session-query.md',
  483. SessionResultFilter: 'session-query.md',
  484. SessionSearchExecContext: 'session-query.md',
  485. SessionSearchHit: 'session-query.md',
  486. SessionSearchPage: 'session-query.md',
  487. SessionSearchRequest: 'session-query.md',
  488. SessionTitleObservation: 'session-query.md',
  489. SessionTitleObservationResult: 'session-query.md',
  490. SessionTitleProvider: 'session-title.md',
  491. SessionTitleSnapshot: 'session-title.md',
  492. SkillCatalogSnapshot: 'skills.md',
  493. SkillDefinition: 'skills.md',
  494. SkillLookupOptions: 'skills.md',
  495. SkillProvider: 'skills.md',
  496. SkillProviderObservation: 'skills.md',
  497. SkillRegistration: 'skills.md',
  498. SkillViewOptions: 'skills.md',
  499. SkillSummary: 'skills.md',
  500. SaveTextSpill: 'spill.md',
  501. SpillRef: 'spill.md',
  502. ContinuableCreateRequest: 'subagent.md',
  503. ContinuableCreateSpec: 'subagent.md',
  504. ContinuableStart: 'subagent.md',
  505. ContinuableStartSpec: 'subagent.md',
  506. AgentMessageSource: 'subagent.md',
  507. SubagentCatalog: 'subagent.md',
  508. SubagentDescendantListEntry: 'subagent.md',
  509. SubagentSendMessageOptions: 'subagent.md',
  510. SubagentInterruptAuthority: 'subagent.md',
  511. SubagentInterruptReceipt: 'subagent.md',
  512. SubagentListEntry: 'subagent.md',
  513. SubagentPromptReceipt: 'subagent.md',
  514. SubagentPromptRequest: 'subagent.md',
  515. SubagentProvider: 'subagent.md',
  516. SubagentRun: 'subagent.md',
  517. SubagentRuntime: 'subagent.md',
  518. SubagentStartRequest: 'subagent.md',
  519. AssembleContext: 'system-prompt.md',
  520. PromptContext: 'system-prompt.md',
  521. PromptContextOrderName: 'system-prompt.md',
  522. PromptSection: 'system-prompt.md',
  523. PromptSectionOrderName: 'system-prompt.md',
  524. SystemPrompt: 'system-prompt.md',
  525. ToolProviderResult: 'system-prompt.md',
  526. JobDoneListener: 'jobs.md',
  527. JobId: 'jobs.md',
  528. JobRead: 'jobs.md',
  529. JobSnapshot: 'jobs.md',
  530. JobStart: 'jobs.md',
  531. JobsChangedListener: 'jobs.md',
  532. CreateTeamTaskRequest: 'agent-team.md',
  533. SendTeamMessageRequest: 'agent-team.md',
  534. SendTeamMessageResult: 'agent-team.md',
  535. SpawnTeammateRequest: 'agent-team.md',
  536. SpawnTeammateResult: 'agent-team.md',
  537. TeamId: 'agent-team.md',
  538. TeamMemberView: 'agent-team.md',
  539. TeamMembership: 'agent-team.md',
  540. TeamTaskMutationResult: 'agent-team.md',
  541. TeamTaskId: 'agent-team.md',
  542. TeamTaskView: 'agent-team.md',
  543. TeamView: 'agent-team.md',
  544. TeamWaitResult: 'agent-team.md',
  545. UpdateTeamTaskRequest: 'agent-team.md',
  546. TokenMeasurement: 'token-meter.md',
  547. PtcDispatchLog: 'tools.md',
  548. PostToolDecision: 'tools.md',
  549. PreToolDecision: 'tools.md',
  550. ToolDefinition: 'tools.md',
  551. ToolExecution: 'tools.md',
  552. ToolDispatchExecution: 'tools.md',
  553. ToolExecutionInput: 'tools.md',
  554. ToolExecutionMode: 'tools.md',
  555. ToolExecutionResult: 'tools.md',
  556. ToolExecutionToken: 'tools.md',
  557. ToolGuard: 'tools.md',
  558. ToolPresentationMode: 'tools.md',
  559. ToolRuntime: 'tools.md',
  560. ToolRestriction: 'tools.md',
  561. ToolSchema: 'tools.md',
  562. SettingsNamespace: 'settings.md',
  563. SettingsNamespaceInput: 'settings.md',
  564. SettingsRegisterOptions: 'settings.md',
  565. SettingsSectionHooks: 'settings.md',
  566. SettingsScope: 'settings.md',
  567. SettingsDescriptor: 'settings.md',
  568. SettingsDescribeValue: 'settings.md',
  569. SettingsDocumentOpenValue: 'settings.md',
  570. AgentPresetDirectoryOpenValue: 'settings.md',
  571. SettingsNamespaceView: 'settings.md',
  572. SettingsPathOpView: 'settings.md',
  573. SettingsSecretView: 'settings.md',
  574. SettingsPathOp: 'settings.md',
  575. SettingsDescribeOptions: 'settings.md',
  576. SettingsUpdateSource: 'settings.md',
  577. SkillListRequest: 'skills.md',
  578. SkillListValue: 'skills.md',
  579. AuthorizationEntry: 'credentials.md',
  580. AuthorizationFlow: 'credentials.md',
  581. AuthorizationInteraction: 'credentials.md',
  582. AuthorizationMethod: 'credentials.md',
  583. AuthorizationNotice: 'credentials.md',
  584. AuthorizationOutcome: 'credentials.md',
  585. AuthorizationPrompt: 'credentials.md',
  586. AuthorizationRequest: 'credentials.md',
  587. AuthorizationSession: 'credentials.md',
  588. AuthorizationSettlement: 'credentials.md',
  589. AuthorizationStatus: 'credentials.md',
  590. CredentialRef: 'credentials.md',
  591. CredentialKey: 'credentials.md',
  592. CredentialInfo: 'credentials.md',
  593. CredentialRecord: 'credentials.md',
  594. CredentialRecordEntry: 'credentials.md',
  595. CredentialRecordInfo: 'credentials.md',
  596. ResolvedCredential: 'credentials.md',
  597. AskUserQuestionAnswer: 'user-questions.md',
  598. AskUserQuestionRequest: 'user-questions.md',
  599. UserQuestionProvider: 'user-questions.md',
  600. WebFetchProvider: 'web.md',
  601. WebFetchRequest: 'web.md',
  602. WebFetchResult: 'web.md',
  603. WebSearchProvider: 'web.md',
  604. WebSearchRequest: 'web.md',
  605. WebSearchResult: 'web.md',
  606. WorkflowRun: 'workflow.md',
  607. VerifiedWebhookDelivery: 'webhook.md',
  608. WebhookRule: 'webhook.md',
  609. PresetOption: 'permission-presets.md',
  610. PresetSpec: 'permission-presets.md',
  611. InvariantInstaller: 'invariants.md',
  612. WebRoute: 'web-server.md',
  613. IndexInjection: 'web-server.md',
  614. StorageBackend: 'storage.md',
  615. StorageForms: 'storage.md',
  616. Domain: 'storage.md',
  617. DomainSpec: 'storage.md',
  618. DomainChanged: 'storage.md',
  619. DomainFacility: 'storage.md',
  620. Workspace: 'workspace.md',
  621. WorkspaceArchiveSessionRequest: 'workspace.md',
  622. WorkspaceArchiveValue: 'workspace.md',
  623. WorkspaceCreateRequest: 'workspace.md',
  624. WorkspaceCreateValue: 'workspace.md',
  625. WorkspaceDeleteRequest: 'workspace.md',
  626. WorkspaceDeleteValue: 'workspace.md',
  627. WorkspaceFollowFrame: 'workspace.md',
  628. WorkspaceId: 'workspace.md',
  629. WorkspaceInsertBeforeRequest: 'workspace.md',
  630. WorkspaceInsertSessionBeforeRequest: 'workspace.md',
  631. WorkspaceOrderValue: 'workspace.md',
  632. WorkspaceRenameRequest: 'workspace.md',
  633. WorkspaceValue: 'workspace.md',
  634. ClientArtifactBaseline: 'client-modules.md',
  635. WebBootGraph: 'client-modules.md',
  636. SessionTelemetryRecord: 'session-telemetry.md',
  637. WorkflowRunInfo: 'workflow.md',
  638. WorkflowStartRequest: 'workflow.md',
  639. ProjectionDefinition: 'session-projection.md',
  640. SessionProjectionMap: 'session-projection.md',
  641. SessionProjectionStateMap: 'session-projection.md',
  642. ProjectionChangeListener: 'session-projection.md',
  643. ProjectionSnapshot: 'session-projection.md',
  644. ProjectionCheckpoint: 'session-projection.md',
  645. DirectoryPickerCapability: 'workspace.md',
  646. DirectoryListing: 'workspace.md',
  647. TypertContribution: 'invariants.md',
  648. TypertRemoteEventSource: 'typert.md',
  649. RemoteEventHostInfo: 'typert.md',
  650. TypertFace: 'invariants.md',
  651. TypertPackageFilter: 'invariants.md',
  652. TypertPackageRecord: 'invariants.md',
  653. TypertSchemaFilter: 'invariants.md',
  654. TypertSchemaRecord: 'invariants.md',
  655. }
  656. /** TypeScript lib and pinned framework types with no repository-owned data page. */
  657. export const FOUNDATION_TYPE_NAMES: ReadonlySet<string> = new Set([
  658. 'AbortSignal',
  659. 'AsyncIterable',
  660. 'Context',
  661. 'Error',
  662. 'EntryTree',
  663. 'Exclude',
  664. 'Extract',
  665. 'Map',
  666. 'NonNullable',
  667. 'Omit',
  668. 'Partial',
  669. 'Pick',
  670. 'Promise',
  671. 'Record',
  672. 'Readonly',
  673. 'ReadonlyMap',
  674. 'Request',
  675. 'Response',
  676. 'Uint8Array',
  677. ])
  678. /** Project types deliberately documented outside the subsystems catalog. */
  679. export const TYPE_LINK_EXEMPTIONS: Readonly<Record<string, string>> = {
  680. z: 'schemastery schema constructor is owned by vendor/schemastery (vendored upstream)',
  681. BeginCommandRequest: 'event-local request contract is owned by packages/client/ui-input-trigger/src/types.ts',
  682. InsertReferenceRequest: 'event-local request contract is owned by packages/client/ui-input-trigger/src/types.ts',
  683. ConsumeTokenRequest: 'event-local request contract is owned by packages/client/ui-input-trigger/src/types.ts',
  684. InsertTextRequest: 'event-local request contract is owned by packages/client/ui-input-trigger/src/types.ts',
  685. AgentHandle: 'agent ownership handle is owned by packages/core/agent/README.md',
  686. AgentPreset: 'discovered preset record is owned by packages/preset/agent-presets/README.md',
  687. AgentPresetRoster: 'path-free preset roster is owned by packages/preset/agent-presets/README.md',
  688. AgentPresetDocument: 'preset composition view is owned by packages/preset/agent-presets/README.md',
  689. AgentPresetComposition: 'flattened composition rows are owned by packages/preset/agent-presets/README.md',
  690. PresetMetadata: 'preset display text is owned by packages/preset/agent-presets/README.md',
  691. BashEnvContributor: 'service-local extension type is owned by packages/shell/tool-bash/src/index.ts',
  692. BashEnvVariableInfo: 'service-local metadata type is owned by packages/shell/tool-bash/src/index.ts',
  693. CompactionAgentContext: 'compaction service input is owned by packages/compaction/compaction/src/index.ts',
  694. ManualCompactAgentContext: 'manual compaction service input is owned by packages/compaction/compaction/src/index.ts',
  695. ClientResponse: 'wire response message is owned by packages/client/connection/src/rpc.ts',
  696. ApprovalRequestId: 'dynamic Plugin approval identity is owned by packages/extensions/cordis-host-runner/src/types.ts',
  697. CordisErrorDetails: 'Cordis runtime error payload is owned by packages/extensions/cordis-host-runner/src/types.ts',
  698. CordisInspectPlatform: 'Cordis inspect platform identity is owned by packages/extensions/cordis-host-runner/src/types.ts',
  699. CordisInspectProviderManifest: 'Cordis inspect provider manifest is owned by packages/extensions/cordis-host-runner/src/types.ts',
  700. CordisInspectProviderView: 'Cordis inspect provider view is owned by packages/extensions/cordis-host-runner/src/types.ts',
  701. CordisInspectQueryRequest: 'Cordis inspect transport payload is owned by packages/extensions/cordis-host-runner/src/types.ts',
  702. CordisInspectQueryResolution: 'Cordis inspect query result is owned by packages/extensions/cordis-host-runner/src/types.ts',
  703. CordisInspectQueryResolved: 'Cordis inspect transport payload is owned by packages/extensions/cordis-host-runner/src/types.ts',
  704. CordisInspectRequestId: 'Cordis inspect request identity is owned by packages/extensions/cordis-host-runner/src/types.ts',
  705. CordisInspectResolveAck: 'Cordis inspect resolution acknowledgement is owned by packages/extensions/cordis-host-runner/src/types.ts',
  706. CordisDynamicPackageId: 'dynamic Package identity is owned by packages/extensions/cordis-host-runner/src/types.ts',
  707. CordisDynamicPluginId: 'dynamic Plugin identity is owned by packages/extensions/cordis-host-runner/src/types.ts',
  708. CordisDynamicPluginRunId: 'dynamic Plugin run identity is owned by packages/extensions/cordis-host-runner/src/types.ts',
  709. CordisDynamicRunMode: 'dynamic Plugin activation mode is owned by packages/extensions/cordis-host-runner/src/types.ts',
  710. DynamicCordisClientSource: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  711. DynamicCordisDefineReceipt: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  712. DynamicCordisDefineRequest: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  713. DynamicCordisHostHalfResult: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  714. DynamicCordisInventoryRow: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  715. DynamicCordisInvokeResult: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  716. DynamicCordisPackageInspection: 'dynamic Package source inspection is owned by packages/extensions/cordis-host-runner/src/registry.ts',
  717. DynamicCordisPluginInspection: 'dynamic Plugin inspection is owned by packages/extensions/cordis-host-runner/src/registry.ts',
  718. DynamicCordisRequestResolved: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  719. DynamicCordisRetracted: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  720. DynamicCordisRunRequest: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  721. DynamicCordisPackage: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  722. DynamicCordisReference: 'dynamic Plugin reference is owned by packages/extensions/cordis-host-runner/src/registry.ts',
  723. DynamicCordisRenderFailure: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  724. DynamicCordisResolveAck: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  725. DynamicCordisRunResolution: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  726. DynamicCordisRunResponse: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  727. DynamicCordisSnapshotRow: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  728. DynamicCordisStopResponse: 'dynamic Plugin stop result is owned by packages/extensions/cordis-host-runner/src/types.ts',
  729. DynamicCordisUndefineReceipt: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  730. HostCordisInspectProviderRegistration: 'Host inspect provider registration is owned by packages/extensions/cordis-host-runner/src/inspect-registry.ts',
  731. DomainImpl: 'domain implementation contract is owned by packages/storage/storage-domain/README.md',
  732. CommandExecution: 'executor return contract is owned by packages/interaction/commands/src/index.ts',
  733. 'z.core.JSONSchema.BaseSchema': 'zod projection output is owned by the zod v4 API',
  734. 'z.core.ToJSONSchemaParams': 'zod projection parameters are owned by the zod v4 API',
  735. TypertDisposer: 'Typert lifecycle contract is owned by packages/typert/protocol/README.md',
  736. InvokeRemoteRequest: 'gateway invocation contract is owned by packages/api/gateway/README.md',
  737. LocaleDict: 'service-local dictionary fields are owned by packages/client/i18n/src/index.ts',
  738. ThemeTokens: 'service-local token dictionary is owned by packages/client/ui-theme/src/index.ts',
  739. Translate: 'service-local bound translator is owned by packages/client/i18n/src/index.ts',
  740. WebUpgradeRoute:
  741. 'upgrade route registration contract is owned by packages/host/webserver/src/index.ts',
  742. InvariantRegistration: 'service-local lifecycle handle is owned by packages/runtime-diagnostics/invariants/README.md',
  743. JsonValue: 'JSON value union is owned by packages/core/session/src/json.ts',
  744. KnobState: 'projection unit state fields are owned by packages/interaction/permission-presets/README.md',
  745. PermissionSelect: 'permissions projection payload is owned by packages/interaction/permission-presets/src/types.ts',
  746. PromptAssembly: 'assembly result is owned by packages/core/system-prompt/README.md',
  747. RequestRunId: 'dynamic-package payload contract is owned by packages/extensions/cordis-host-runner/src/types.ts',
  748. RpcReceipt: 'carrier-layer receipt is owned by packages/client/connection/src/rpc.ts',
  749. Sandbox: 'external E2B SDK handle is owned by packages/e2b/e2b/README.md',
  750. SessionForkSource: 'service-local fork input is owned by packages/core/session/src/index.ts',
  751. SubagentRunEndInfo: 'event payload contract is owned by packages/subagent/subagent/src/types.ts',
  752. SubagentRunInfo: 'event payload contract is owned by packages/subagent/subagent/src/types.ts',
  753. WorkflowAgentEndInfo: 'event-local snapshot is owned by packages/workflow/workflow/src/index.ts',
  754. WorkflowAgentInfo: 'event-local snapshot is owned by packages/workflow/workflow/src/index.ts',
  755. WorkflowResultInfo: 'event-local snapshot is owned by packages/workflow/workflow/src/index.ts',
  756. WorkspaceFileScope: 'Host workspace file lookup contract is owned by packages/api/workspace-files/README.md',
  757. WorkspaceByteRange: 'Host workspace file endpoint contract is owned by packages/api/workspace-files/README.md',
  758. WorkspaceDirectoryListing: 'Host workspace file endpoint contract is owned by packages/api/workspace-files/README.md',
  759. WorkspaceFileBytes: 'Host workspace file endpoint contract is owned by packages/api/workspace-files/README.md',
  760. WorkspaceFileChange: 'Host workspace file endpoint contract is owned by packages/api/workspace-files/README.md',
  761. WorkspaceFileWatchFrame: 'Host workspace file endpoint contract is owned by packages/api/workspace-files/README.md',
  762. WorkspaceFileRange: 'Host workspace file endpoint contract is owned by packages/api/workspace-files/README.md',
  763. WorkspaceFileStat: 'Host workspace file endpoint contract is owned by packages/api/workspace-files/README.md',
  764. WorkspaceFileText: 'Host workspace file endpoint contract is owned by packages/api/workspace-files/README.md',
  765. }
  766. /** Repository data policy consumed by the Cordis catalog projector. */
  767. export const CORDIS_CATALOG_POLICY: CordisCatalogPolicy = {
  768. linkedTypePages: LINK_MAP,
  769. foundationTypeNames: FOUNDATION_TYPE_NAMES,
  770. typeLinkExemptions: TYPE_LINK_EXEMPTIONS,
  771. runtimeServiceExclusions: new Set(['cordisInspect', 'dynamicCordisRunner']),
  772. runtimeServices: [{
  773. key: 'timer',
  774. type: 'TimerService',
  775. abstract: false,
  776. doc: 'Disposable timer helpers mixed into Cordis contexts.',
  777. source: 'vendor/timer/src/index.ts:12',
  778. methods: [
  779. {
  780. signature: 'timeout(callback: () => void, delay: number): () => void',
  781. jsDoc: '/** Run a callback once and return its disposer. */',
  782. },
  783. {
  784. signature: 'timeout(delay: number): Promise<void>',
  785. jsDoc: '/** Resolve after a delay; disposal rejects the pending promise. */',
  786. },
  787. {
  788. signature: 'interval(callback: () => void, delay: number): () => void',
  789. jsDoc: '/** Run a callback repeatedly and return its disposer. */',
  790. },
  791. {
  792. signature: 'interval<R = any>(delay: number): AsyncIterableIterator<void, R, void>',
  793. jsDoc: '/** Return an async iterator of timer ticks. */',
  794. },
  795. {
  796. signature: 'throttle<F extends (...args: any[]) => void>(callback: F, delay: number, noTrailing?: boolean): F & { dispose: () => void }',
  797. jsDoc: '/** Return a throttled function whose timer is disposed with the current fiber. */',
  798. },
  799. {
  800. signature: 'debounce<F extends (...args: any[]) => void>(callback: F, delay: number): F & { dispose: () => void }',
  801. jsDoc: '/** Return a debounced function whose timer is disposed with the current fiber. */',
  802. },
  803. ],
  804. }],
  805. inheritedEvents: [
  806. { name: 'internal/plugin', summary: 'A plugin fiber was created.', source: 'vendor/cordis/src/events.ts:328' },
  807. { name: 'internal/status', summary: 'A fiber changed lifecycle state.', source: 'vendor/cordis/src/events.ts:330' },
  808. { name: 'internal/service', summary: 'Interception hook for a service binding (no core producer).', source: 'vendor/cordis/src/events.ts:332' },
  809. { name: 'internal/update', summary: 'Waterfall: a fiber config update is being applied.', source: 'vendor/cordis/src/events.ts:334' },
  810. { name: 'internal/get', summary: 'Waterfall: a service is being read from the store.', source: 'vendor/cordis/src/events.ts:336' },
  811. { name: 'internal/set', summary: 'Waterfall: a service is being written to the store.', source: 'vendor/cordis/src/events.ts:338' },
  812. { name: 'internal/listener', summary: 'A listener was registered.', source: 'vendor/cordis/src/events.ts:340' },
  813. { name: 'internal/dispatch', summary: 'An event is being dispatched to listeners.', source: 'vendor/cordis/src/events.ts:342' },
  814. { name: 'hmr/change', summary: 'A watched source file changed on disk.', source: 'vendor/hmr/src/index.ts:20' },
  815. { name: 'hmr/reload', summary: 'Plugins are being reloaded after a change.', source: 'vendor/hmr/src/index.ts:21' },
  816. { name: 'exit', summary: 'The process is exiting on a signal.', source: 'vendor/loader/src/index.ts:23' },
  817. { name: 'loader/config-update', summary: 'The loader config tree changed.', source: 'vendor/loader/src/index.ts:24' },
  818. { name: 'loader/entry-init', summary: 'A config entry is being initialized.', source: 'vendor/loader/src/index.ts:25' },
  819. { name: 'loader/partial-dispose', summary: 'An entry is being partially disposed on reload.', source: 'vendor/loader/src/index.ts:26' },
  820. { name: 'loader/patch-context', summary: 'A context is being patched during a reload.', source: 'vendor/loader/src/index.ts:27' },
  821. ],
  822. inheritedServices: [
  823. { name: 'ctx.on / ctx.once', summary: 'Register an event listener (disposable).', source: 'vendor/cordis/src/events.ts:34' },
  824. { name: 'ctx.emit / ctx.parallel / ctx.serial / ctx.bail / ctx.waterfall', summary: 'Dispatch an event (sync / awaited / first-bail / short-circuit chain).', source: 'vendor/cordis/src/events.ts:34' },
  825. { name: 'ctx.plugin / ctx.inject', summary: 'Load a plugin / declare required services.', source: 'vendor/cordis/src/registry.ts:164' },
  826. { name: 'ctx.effect', summary: 'Register a disposable side effect tied to the fiber.', source: 'vendor/cordis/src/fiber.ts:9' },
  827. { name: 'ctx.get / ctx.set / ctx.provide / ctx.accessor / ctx.mixin', summary: 'Low-level service-store access and binding.', source: 'vendor/cordis/src/reflect.ts:7' },
  828. { name: 'ctx.extend / ctx.isolate / ctx.intercept', summary: 'Derive a child context (scoped services / isolation / interception).', source: 'vendor/cordis/src/context.ts:42' },
  829. { name: 'ctx.root / ctx.fiber / ctx.registry / ctx.reflect / ctx.events / ctx.logger', summary: 'Ambient handles onto the running context graph.', source: 'vendor/cordis/src/context.ts:16' },
  830. { name: 'ctx.timer (+ interval / timeout / throttle / debounce)', summary: 'Disposable timer helpers. The `timer` key is provided at runtime; the four supported helpers are mixed onto ctx directly (declared via Pick).', source: 'vendor/timer/src/index.ts:4' },
  831. { name: 'ctx.loader', summary: 'The config Loader that booted the app (present under the loader).', source: 'vendor/loader/src/index.ts:30' },
  832. { name: 'ctx.hmr', summary: 'The hot-module-reload watcher (present under the hmr plugin).', source: 'vendor/hmr/src/index.ts:15' },
  833. ],
  834. }
  835. /**
  836. * Splice a page's generated Cordis API region into its Markdown content.
  837. * The page must contain exactly one `cordis-surface` marker region (the markers are
  838. * part of the hand-owned page skeleton once, then owned by the generator);
  839. * zero or several is a partition error the caller reports with the page path.
  840. * The match is on THIS generator's exact markers, not the generic region
  841. * grammar, so a page carrying only some other generator's region fails loud
  842. * instead of having that region overwritten.
  843. * @param content - the page's current full Markdown text.
  844. * @param region - the freshly rendered marker-delimited region.
  845. * @returns the page text with the region replaced.
  846. */
  847. export function spliceRegion(content: string, region: string): string {
  848. const lines = content.split('\n')
  849. const begins = lines.flatMap((line, index) => (line === REGION_BEGIN ? [index] : []))
  850. const ends = lines.flatMap((line, index) => (line === REGION_END ? [index] : []))
  851. if (begins.length !== 1 || ends.length !== 1) {
  852. throw new Error(`expected exactly 1 cordis-surface region, found ${begins.length} BEGIN/${ends.length} END; add the BEGIN/END cordis-surface markers once`)
  853. }
  854. const begin = begins[0] ?? -1
  855. const end = ends[0] ?? -1
  856. if (end < begin) throw new Error('cordis-surface END marker precedes its BEGIN')
  857. return [...lines.slice(0, begin), ...region.split('\n'), ...lines.slice(end + 1)].join('\n')
  858. }
  859. /** The declared-vs-rendered inputs {@link walkPartitionProblems} judges. */
  860. export interface WalkPartitionInput {
  861. /** Service key → source pointer, as the rendering projection produced them. */
  862. readonly renderedKeys: ReadonlyMap<string, string>
  863. /** Event scopes the rendering projection produced. */
  864. readonly renderedScopes: ReadonlySet<string>
  865. /** Event names the rendering projection produced. */
  866. readonly renderedEventNames: ReadonlySet<string>
  867. /** Context key → first declaring file, from the independent AST scan. */
  868. readonly declaredKeys: ReadonlyMap<string, string>
  869. /** Event name → first declaring file, from the independent AST scan. */
  870. readonly declaredEvents: ReadonlyMap<string, string>
  871. }
  872. /** The curated partition maps {@link walkPartitionProblems} enforces. */
  873. export interface WalkPartitionMaps {
  874. readonly servicePage: Readonly<Record<string, string>>
  875. readonly serviceWalkExemptions: Readonly<Record<string, string>>
  876. readonly eventScopePage: Readonly<Record<string, string>>
  877. readonly eventWalkExemptions: Readonly<Record<string, string>>
  878. }
  879. /** Project paired Markdown destinations in one generated region to the page's locale. */
  880. export function localizePageRegion(region: string, pageRel: string, scanRoot: string = root): string {
  881. if (!pageRel.endsWith('.zh.md')) return region
  882. const manifest = parseTranslationPairingManifest(
  883. readFileSync(resolve(scanRoot, 'scripts/translation-pairing.manifest.json'), 'utf8'),
  884. )
  885. return rewriteTranslationLinkLocales(region, {
  886. repoRoot: scanRoot,
  887. sourcePath: pageRel,
  888. isTranslationPairSource: translationPairSourcePredicate(manifest),
  889. }).content
  890. }
  891. /**
  892. * Judge the rendered API and the independent AST scan against the curated
  893. * partition maps, fail-closed in both directions for services AND events: a
  894. * rendered key/scope must be mapped to a page, a mapped key/scope must still
  895. * render, and — the backstop — a DECLARED key/event the projection cannot see
  896. * must carry a named walk exemption (a rendered one must not). A third
  897. * direction guards the scan itself: everything rendered must also be declared
  898. * to the scan, so a scan blind spot cannot decay silently. Pure so the
  899. * acceptance paths are provable without running the projection.
  900. * @param input - rendered API plus the declared-key/event scans.
  901. * @param maps - the curated page maps and walk exemptions.
  902. * @returns one message per violation, empty when the partition holds.
  903. */
  904. export function walkPartitionProblems(input: WalkPartitionInput, maps: WalkPartitionMaps): string[] {
  905. const problems: string[] = []
  906. for (const [key, source] of input.renderedKeys) {
  907. if (!Object.hasOwn(maps.servicePage, key)) problems.push(`service ctx.${key} (${source}) has no SERVICE_PAGE entry; every service maps to exactly one subsystems page.`)
  908. }
  909. for (const scope of [...input.renderedScopes].sort()) {
  910. if (!Object.hasOwn(maps.eventScopePage, scope)) problems.push(`event scope '${scope}/*' has no EVENT_SCOPE_PAGE entry; every event scope maps to exactly one subsystems page.`)
  911. }
  912. for (const key of Object.keys(maps.servicePage)) {
  913. if (!input.renderedKeys.has(key)) problems.push(`SERVICE_PAGE maps 'ctx.${key}' but the projection discovers no such service; remove the stale entry.`)
  914. }
  915. for (const scope of Object.keys(maps.eventScopePage)) {
  916. if (!input.renderedScopes.has(scope)) problems.push(`EVENT_SCOPE_PAGE maps '${scope}/*' but the projection discovers no such scope; remove the stale entry.`)
  917. }
  918. // The rendering projection only sees a Context key it can resolve to a
  919. // documented service class. The independent scan reads EVERY Context merge
  920. // so a key the projection cannot render must either be rendered (mapped) or
  921. // carry a named SERVICE_WALK_EXEMPTIONS reason — never vanish silently.
  922. for (const [key, rel] of input.declaredKeys) {
  923. const rendered = input.renderedKeys.has(key)
  924. const exempt = Object.hasOwn(maps.serviceWalkExemptions, key)
  925. if (!rendered && !exempt) {
  926. problems.push(`ctx.${key} (${rel}) is declared in a Context merge but invisible to the rendering projection; map it in SERVICE_PAGE (after making it renderable) or name it in SERVICE_WALK_EXEMPTIONS with its documentation owner.`)
  927. }
  928. if (rendered && exempt) problems.push(`ctx.${key} is rendered by the projection but still listed in SERVICE_WALK_EXEMPTIONS; remove the stale exemption.`)
  929. }
  930. for (const key of Object.keys(maps.serviceWalkExemptions)) {
  931. if (!input.declaredKeys.has(key)) problems.push(`SERVICE_WALK_EXEMPTIONS names 'ctx.${key}' but no Context merge declares it; remove the stale exemption.`)
  932. }
  933. // The event mirror of the service backstop: the projection walks only files
  934. // reachable from host-face package exports, so a client-face or unreachable
  935. // Events merge would otherwise vanish without a trace.
  936. for (const [name, rel] of input.declaredEvents) {
  937. const rendered = input.renderedEventNames.has(name)
  938. const exempt = Object.hasOwn(maps.eventWalkExemptions, name)
  939. if (!rendered && !exempt) {
  940. problems.push(`event '${name}' (${rel}) is declared in an Events merge but invisible to the rendering projection; make it renderable (mapped via EVENT_SCOPE_PAGE) or name it in EVENT_WALK_EXEMPTIONS with its documentation owner.`)
  941. }
  942. if (rendered && exempt) problems.push(`event '${name}' is rendered by the projection but still listed in EVENT_WALK_EXEMPTIONS; remove the stale exemption.`)
  943. }
  944. for (const name of Object.keys(maps.eventWalkExemptions)) {
  945. if (!input.declaredEvents.has(name)) problems.push(`EVENT_WALK_EXEMPTIONS names '${name}' but no Events merge declares it; remove the stale exemption.`)
  946. }
  947. // Self-check the scan itself: everything the projection renders is declared
  948. // in a Context/Events merge the scan must also reach, so a rendered key or
  949. // event the scan cannot see means the SCAN regressed (glob, prefilter, or
  950. // block walk) — a partial blind spot that exemption staleness alone would
  951. // never appear.
  952. for (const key of input.renderedKeys.keys()) {
  953. if (!input.declaredKeys.has(key)) problems.push(`ctx.${key} is rendered by the projection but the independent scan finds no Context merge declaring it; the scan has a blind spot (glob, prefilter, or module-block walk) — fix the scan, not the maps.`)
  954. }
  955. for (const name of input.renderedEventNames) {
  956. if (!input.declaredEvents.has(name)) problems.push(`event '${name}' is rendered by the projection but the independent scan finds no Events merge declaring it; the scan has a blind spot (glob, prefilter, or module-block walk) — fix the scan, not the maps.`)
  957. }
  958. return problems
  959. }
  960. /**
  961. * Compute every generated artifact: the inherited-tier page, the model-facing
  962. * runtime API module, plus, per mapped subsystems page, the pair's two updated
  963. * documents with the injected region. Fail-loud partition checks live here: an
  964. * unmapped service/event scope, a mapping whose page file does not exist, a
  965. * curated entry whose key/scope the projection no longer discovers, a declared
  966. * Context key or Events member the projection cannot see without a named walk
  967. * exemption, and a mapped page missing its markers are all aggregated errors.
  968. * @returns `[repo-relative path, exact content]` for every generated artifact.
  969. */
  970. export function computeOutputs(): [string, string][] {
  971. const { projector, model } = projectCordisCatalog(root, CORDIS_CATALOG_POLICY)
  972. const services = [...model.services]
  973. const events = [...model.events]
  974. const declaredKeys = new Map<string, string>()
  975. const declaredEvents = new Map<string, string>()
  976. for (const { rel, sf, body } of contextMergeFiles(root, ['packages/*/*/src/**/*.ts', 'packages/*/*/src/**/*.tsx'])) {
  977. for (const key of contextKeyMap(body, sf).keys()) {
  978. if (!declaredKeys.has(key)) declaredKeys.set(key, rel)
  979. }
  980. for (const name of eventNameList(body, sf)) {
  981. if (!declaredEvents.has(name)) declaredEvents.set(name, rel)
  982. }
  983. }
  984. const problems = walkPartitionProblems({
  985. renderedKeys: new Map(services.map(s => [s.key, s.source])),
  986. renderedScopes: new Set(events.map(e => e.scope)),
  987. renderedEventNames: new Set(events.map(e => e.name)),
  988. declaredKeys,
  989. declaredEvents,
  990. }, {
  991. servicePage: SERVICE_PAGE,
  992. serviceWalkExemptions: SERVICE_WALK_EXEMPTIONS,
  993. eventScopePage: EVENT_SCOPE_PAGE,
  994. eventWalkExemptions: EVENT_WALK_EXEMPTIONS,
  995. })
  996. if (problems.length > 0) throw new Error(`gen-cordis-catalog: ${problems.length} partition violation(s):\n${problems.map(p => ` ${p}`).join('\n')}`)
  997. const pages = [...new Set([...Object.values(SERVICE_PAGE), ...Object.values(EVENT_SCOPE_PAGE)])].sort()
  998. const outputs: [string, string][] = [
  999. [OUT_INHERITED, renderInheritedPage(CORDIS_CATALOG_POLICY)],
  1000. [OUT_RUNTIME_API, projector.renderRuntimeApi(model)],
  1001. ]
  1002. for (const page of pages) {
  1003. const region = renderPageRegion(
  1004. page,
  1005. services.filter(s => SERVICE_PAGE[s.key] === page),
  1006. events.filter(e => EVENT_SCOPE_PAGE[e.scope] === page),
  1007. CORDIS_CATALOG_POLICY,
  1008. )
  1009. for (const side of [page, page.replace(/\.md$/, '.zh.md')]) {
  1010. const rel = `${SUBSYSTEMS_DIR}/${side}`
  1011. const localizedRegion = localizePageRegion(region, rel)
  1012. let current: string
  1013. try {
  1014. current = readFileSync(resolve(root, rel), 'utf8')
  1015. } catch {
  1016. // Both pair sides must exist before a region can be injected; the
  1017. // pairing gate owns pair completeness, this generator names the miss.
  1018. problems.push(`${rel}: mapped subsystems page does not exist.`)
  1019. continue
  1020. }
  1021. try {
  1022. outputs.push([rel, spliceRegion(current, localizedRegion)])
  1023. } catch (error) {
  1024. problems.push(`${rel}: ${error instanceof Error ? error.message : String(error)}`)
  1025. }
  1026. }
  1027. }
  1028. if (problems.length > 0) throw new Error(`gen-cordis-catalog: ${problems.length} page violation(s):\n${problems.map(p => ` ${p}`).join('\n')}`)
  1029. return outputs
  1030. }
  1031. /**
  1032. * Re-record a pair's `.i18n.yaml` after a region write ONLY when the write is
  1033. * region-confined: both sides' region-stripped content must be byte-equal to
  1034. * the region-stripped previous content whose hashes the record holds. The
  1035. * caller supplies the previous bytes (read before writing); human-content
  1036. * drift leaves the record untouched so the pairing gate still demands the
  1037. * normal translation flow.
  1038. * @param pageRel - repo-relative English page path (`docs/subsystems/x.md`).
  1039. * @param before - pre-write bytes per repo-relative path.
  1040. * @param scanRoot - repository root override for tests.
  1041. * @returns true when the record was refreshed.
  1042. */
  1043. export function maybeRecordPair(pageRel: string, before: Map<string, Buffer>, scanRoot: string = root): boolean {
  1044. const zhRel = pageRel.replace(/\.md$/, '.zh.md')
  1045. const metaRel = pageRel.replace(/\.md$/, '.i18n.yaml')
  1046. const metaAbs = resolve(scanRoot, metaRel)
  1047. let meta: string
  1048. try {
  1049. meta = readFileSync(metaAbs, 'utf8')
  1050. } catch {
  1051. // No record yet: a brand-new pair is recorded by the author's --write
  1052. // after review, never silently by regeneration.
  1053. return false
  1054. }
  1055. // The record must contain exactly the two valid entries for THIS pair;
  1056. // a malformed or renamed-key sidecar is the pairing gate's problem to
  1057. // report, never something regeneration silently repairs into validity.
  1058. const recorded = parsePairMeta(meta)
  1059. const names = [pageRel, zhRel].map(rel => rel.split('/').at(-1) ?? rel)
  1060. if (!recorded || recorded.size !== 2 || !names.every(name => recorded.has(name))) return false
  1061. for (const rel of [pageRel, zhRel]) {
  1062. const previous = before.get(rel)
  1063. if (!previous) return false
  1064. if (recorded.get(rel.split('/').at(-1) ?? rel) !== blobHash(previous)) return false
  1065. const current = readFileSync(resolve(scanRoot, rel))
  1066. const strippedBefore = partitionGeneratedRegions(previous.toString('utf8')).stripped
  1067. const strippedAfter = partitionGeneratedRegions(current.toString('utf8')).stripped
  1068. if (strippedBefore !== strippedAfter) return false
  1069. }
  1070. const source = readFileSync(resolve(scanRoot, pageRel))
  1071. const zh = readFileSync(resolve(scanRoot, zhRel))
  1072. writeFileSync(metaAbs, renderPairMeta(pageRel, blobHash(source), zhRel, blobHash(zh)))
  1073. return true
  1074. }
  1075. /** CLI entry: default regenerates every artifact, `--check` fails if any is
  1076. * stale. Guarded behind an entry-point check so importing this module for
  1077. * tests neither regenerates the committed files nor calls process.exit.
  1078. * @returns nothing; writes files or reports freshness through the process.
  1079. */
  1080. export function main(): void {
  1081. const outputs: [string, string][] = [
  1082. ...computeOutputs(),
  1083. ...renderCordisCoreApiPages(),
  1084. ]
  1085. if (process.argv.includes('--check')) {
  1086. const stale: string[] = []
  1087. for (const [out, content] of outputs) {
  1088. let committed: string | null = null
  1089. try {
  1090. committed = readFileSync(resolve(root, out), 'utf8')
  1091. } catch {
  1092. // Only ENOENT (not yet generated) is expected; a present-but-unreadable
  1093. // file is not a state this repo produces. Either way the remedy is the
  1094. // same — regenerate — so treat a read failure as "stale".
  1095. committed = null
  1096. }
  1097. if (committed !== content) stale.push(out)
  1098. }
  1099. if (stale.length === 0) {
  1100. console.log(`gen-cordis-catalog: ${outputs.length} generated file(s)/region(s) are up to date.`)
  1101. process.exit(0)
  1102. }
  1103. console.error(`gen-cordis-catalog: stale — ${stale.join(', ')}. Run \`pnpm run gen-cordis-catalog\` and commit the result.`)
  1104. process.exit(1)
  1105. }
  1106. const before = new Map<string, Buffer>()
  1107. for (const [out] of outputs) {
  1108. try {
  1109. before.set(out, readFileSync(resolve(root, out)))
  1110. } catch {
  1111. // First generation of this artifact; nothing to guard, nothing to record.
  1112. }
  1113. }
  1114. let changedPages = 0
  1115. let recorded = 0
  1116. for (const [out, content] of outputs) {
  1117. const destination = resolve(root, out)
  1118. if (before.get(out)?.toString('utf8') === content) continue
  1119. mkdirSync(dirname(destination), { recursive: true })
  1120. writeFileSync(destination, content)
  1121. changedPages++
  1122. }
  1123. for (const page of [...new Set([...Object.values(SERVICE_PAGE), ...Object.values(EVENT_SCOPE_PAGE)])]) {
  1124. const rel = `${SUBSYSTEMS_DIR}/${page}`
  1125. const zhRel = rel.replace(/\.md$/, '.zh.md')
  1126. const wroteEither = [rel, zhRel].some((side) => {
  1127. const previous = before.get(side)
  1128. return previous !== undefined && previous.toString('utf8') !== readFileSync(resolve(root, side), 'utf8')
  1129. })
  1130. if (wroteEither && maybeRecordPair(rel, before)) recorded++
  1131. }
  1132. console.log(`gen-cordis-catalog: ${outputs.length} artifact(s) computed, ${changedPages} written, ${recorded} pair record(s) refreshed.`)
  1133. }
  1134. if (process.argv[1] && import.meta.filename === resolve(process.argv[1])) {
  1135. main()
  1136. }