Skip to content

Commit a660ea2

Browse files
committed
feat: Bug fixes and additional completions
1 parent 4a7c952 commit a660ea2

12 files changed

Lines changed: 229 additions & 85 deletions

File tree

CLAUDE.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,13 @@ The Codify Editor supports auto-complete for certain resource parameters (e.g. H
380380
- `codex.$.config.model.ts``resource_type=codex`, `parameter_path=$.config.model`
381381
4. For parameters **nested inside array items** (e.g. a property on each object in an array), use `[x]` in the filename to encode the `[*]` array wildcard — bundlers treat `[*]` as a glob pattern in import paths, so `[x]` is used as the safe filename equivalent and is translated to `[*]` by the codegen script:
382382
- `ios-simulators.$.simulators[x].deviceType.ts``parameter_path=$.simulators[*].deviceType`
383-
5. Run `npm run build:completions` to regenerate the index
383+
5. For **mirror completions** — where a parameter's suggestions should reflect the current value of a sibling parameter on the same resource — export a plain object instead of a fetch function:
384+
```typescript
385+
// xcodes.$.selected.ts — offers whatever the user typed in xcodeVersions
386+
export default { mirrorParameter: '$.xcodeVersions' } as const;
387+
```
388+
The codegen script detects the export type at build time. The cron job writes a single metadata row to Supabase (with `mirror_parameter_path` set and no `value` rows). The dashboard reads this and serves completions client-side from the resource's current config — no DB query needed.
389+
6. Run `npm run build:completions` to regenerate the index
384390

385391
```bash
386392
npm run build:completions # regenerate completions-cron/src/__generated__/completions-index.ts

completions-cron/src/__generated__/completions-index.ts

Lines changed: 162 additions & 70 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

completions-cron/src/index.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ async function getResourceId(
2828
return data[0].id
2929
}
3030

31-
async function processModule(
31+
async function processFetchModule(
3232
supabase: SupabaseClient,
3333
resourceType: string,
3434
parameterPath: string,
3535
fetchFn: () => Promise<string[]>,
3636
prerelease: boolean,
3737
resourceIdCache: Map<string, string>
3838
): Promise<void> {
39-
console.log(`Processing ${resourceType}${parameterPath}...`)
39+
console.log(`Processing ${resourceType}${parameterPath}...`)
4040

4141
const values = await fetchFn()
42-
console.log(` [${resourceType}${parameterPath}] Fetched ${values.length} values`)
42+
console.log(` [${resourceType}${parameterPath}] Fetched ${values.length} values`)
4343

4444
const resourceId = await getResourceId(supabase, resourceType, prerelease, resourceIdCache)
4545

@@ -63,11 +63,47 @@ async function processModule(
6363
.insert(rows.slice(i, i + BATCH_SIZE))
6464

6565
if (error) {
66-
throw new Error(`Insert failed for ${resourceType}${parameterPath}: ${error.message}`)
66+
throw new Error(`Insert failed for ${resourceType}${parameterPath}: ${error.message}`)
6767
}
6868
}
6969

70-
console.log(` [${resourceType}${parameterPath}] Done: inserted ${values.length} completions`)
70+
console.log(` [${resourceType}${parameterPath}] Done: inserted ${values.length} completions`)
71+
}
72+
73+
async function processMirrorModule(
74+
supabase: SupabaseClient,
75+
resourceType: string,
76+
parameterPath: string,
77+
mirrorParameter: string,
78+
prerelease: boolean,
79+
resourceIdCache: Map<string, string>
80+
): Promise<void> {
81+
console.log(`Processing mirror ${resourceType}${parameterPath} (mirrors ${mirrorParameter})...`)
82+
83+
const resourceId = await getResourceId(supabase, resourceType, prerelease, resourceIdCache)
84+
85+
// Delete any existing metadata row for this path (value IS NULL for mirror rows)
86+
await supabase
87+
.from('resource_parameter_completions')
88+
.delete()
89+
.eq('resource_type', resourceType)
90+
.eq('resource_id', resourceId)
91+
.eq('parameter_path', parameterPath)
92+
93+
const { error } = await supabase
94+
.from('resource_parameter_completions')
95+
.insert({
96+
resource_type: resourceType,
97+
resource_id: resourceId,
98+
parameter_path: parameterPath,
99+
mirror_parameter_path: mirrorParameter,
100+
})
101+
102+
if (error) {
103+
throw new Error(`Mirror insert failed for ${resourceType}${parameterPath}: ${error.message}`)
104+
}
105+
106+
console.log(` [${resourceType}${parameterPath}] Done: mirror metadata row written`)
71107
}
72108

73109
async function runCompletions(env: Env): Promise<void> {
@@ -76,8 +112,10 @@ async function runCompletions(env: Env): Promise<void> {
76112
const resourceIdCache = new Map<string, string>()
77113

78114
const results = await Promise.allSettled(
79-
completionModules.map(({ resourceType, parameterPath, fetch }: CompletionModule) =>
80-
processModule(supabase, resourceType, parameterPath, fetch, prerelease, resourceIdCache)
115+
completionModules.map((mod: CompletionModule) =>
116+
mod.kind === 'fetch'
117+
? processFetchModule(supabase, mod.resourceType, mod.parameterPath, mod.fetch, prerelease, resourceIdCache)
118+
: processMirrorModule(supabase, mod.resourceType, mod.parameterPath, mod.mirrorParameter, prerelease, resourceIdCache)
81119
)
82120
)
83121

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "default",
3-
"version": "1.15.0-beta.4",
3+
"version": "1.15.0-beta.6",
44
"description": "Default plugin for Codify - provides 50+ declarative resources for managing development tools and system configuration across macOS and Linux",
55
"main": "dist/index.js",
66
"scripts": {

scripts/generate-completions-index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@ for (const { importName, importPath } of modules) {
4343
}
4444

4545
lines.push('')
46-
lines.push('export interface CompletionModule {')
47-
lines.push(' resourceType: string')
48-
lines.push(' parameterPath: string')
49-
lines.push(' fetch: () => Promise<string[]>')
50-
lines.push('}')
46+
lines.push('export type CompletionModule =')
47+
lines.push(' | { kind: \'fetch\'; resourceType: string; parameterPath: string; fetch: () => Promise<string[]> }')
48+
lines.push(' | { kind: \'mirror\'; resourceType: string; parameterPath: string; mirrorParameter: string }')
5149
lines.push('')
5250
lines.push('export const completionModules: CompletionModule[] = [')
5351
for (const { importName, resourceType, parameterPath } of modules) {
54-
lines.push(` { resourceType: '${resourceType}', parameterPath: '${parameterPath}', fetch: ${importName} },`)
52+
// A mirror module exports { mirrorParameter: '...' }, a fetch module exports a function.
53+
lines.push(` typeof ${importName} === 'function'`)
54+
lines.push(` ? { kind: 'fetch', resourceType: '${resourceType}', parameterPath: '${parameterPath}', fetch: ${importName} }`)
55+
lines.push(` : { kind: 'mirror', resourceType: '${resourceType}', parameterPath: '${parameterPath}', mirrorParameter: (${importName} as any).mirrorParameter },`)
5556
}
5657
lines.push(']')
5758
lines.push('')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default { mirrorParameter: '$.goVersions' } as const;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default { mirrorParameter: '$.add' } as const;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default { mirrorParameter: '$.nodeVersions' } as const;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default { mirrorParameter: '$.nodeVersions' } as const;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default { mirrorParameter: '$.pythonVersions' } as const;

0 commit comments

Comments
 (0)