mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
* feat(vfs): add lazy vfs + remove dynamic fields for prompt caching hits * feat(vfs): send typed workspace snapshot for append-only deltas Build the workspace inventory from the primary db (fixes replica-lag staleness) and emit it as a typed VfsSnapshotV1 `vfs` payload alongside the markdown, so the mothership can diff it into append-only baseline/delta messages. Generate the TS contract mirror from the Go-owned JSON schema (sync-vfs-snapshot-contract) and sort connector types so diffs stay byte-stable. * fix(lint): fix lint * fix(vfs): forward the typed snapshot through the branch payload builder The branch buildPayload implementations hand-list the params they pass to buildCopilotRequestPayload and forwarded workspaceContext but dropped vfs, so the typed snapshot never reached the Go request (req.Vfs was always nil and the append-only delta path never engaged). Forward vfs in both the workflow and workspace branches, and add a regression guard asserting the branch threads it through (the bug slipped past tests because post.test mocked the payload builder and payload.test called it directly, bypassing the branch). * improvement(contracts): update vfs contracts
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import { mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
import { dirname, resolve } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { compile } from 'json-schema-to-typescript'
|
|
import { formatGeneratedSource } from './format-generated-source'
|
|
|
|
const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url))
|
|
const ROOT = resolve(SCRIPT_DIR, '..')
|
|
// Matches the sibling sync scripts' canonical layout. In a repo where the Go
|
|
// service lives at `mothership/copilot`, pass `--input=` (e.g.
|
|
// `--input=../mothership/copilot/contracts/vfs-snapshot-v1.schema.json`).
|
|
const DEFAULT_CONTRACT_PATH = resolve(
|
|
ROOT,
|
|
'../copilot/copilot/contracts/vfs-snapshot-v1.schema.json'
|
|
)
|
|
const OUTPUT_PATH = resolve(ROOT, 'apps/sim/lib/copilot/generated/vfs-snapshot-v1.ts')
|
|
|
|
async function main() {
|
|
const checkOnly = process.argv.includes('--check')
|
|
const inputPathArg = process.argv.find((arg) => arg.startsWith('--input='))
|
|
const inputPath = inputPathArg
|
|
? resolve(ROOT, inputPathArg.slice('--input='.length))
|
|
: DEFAULT_CONTRACT_PATH
|
|
|
|
const raw = await readFile(inputPath, 'utf8')
|
|
const schema = JSON.parse(raw)
|
|
const types = await compile(schema, 'VfsSnapshotV1', {
|
|
bannerComment: '// AUTO-GENERATED FILE. DO NOT EDIT.\n//',
|
|
unreachableDefinitions: true,
|
|
additionalProperties: false,
|
|
})
|
|
const rendered = formatGeneratedSource(types, OUTPUT_PATH, ROOT)
|
|
|
|
if (checkOnly) {
|
|
const existing = await readFile(OUTPUT_PATH, 'utf8').catch(() => null)
|
|
if (existing !== rendered) {
|
|
throw new Error('Generated vfs snapshot contract is stale. Run: bun run mship:generate')
|
|
}
|
|
return
|
|
}
|
|
|
|
await mkdir(dirname(OUTPUT_PATH), { recursive: true })
|
|
await writeFile(OUTPUT_PATH, rendered, 'utf8')
|
|
}
|
|
|
|
await main()
|