Skip to content

Scaffold prompd ai command (Phase 1)#11

Open
sbaker wants to merge 1 commit into
mainfrom
prompd-ai/phase-1-cli-scaffold
Open

Scaffold prompd ai command (Phase 1)#11
sbaker wants to merge 1 commit into
mainfrom
prompd-ai/phase-1-cli-scaffold

Conversation

@sbaker
Copy link
Copy Markdown
Member

@sbaker sbaker commented Apr 19, 2026

Summary

First PR in the Prompd AI local-runtime workstream. Wires up the prompd ai command with all five verbs (install / uninstall / start / stop / status) plus supporting lib modules, but only implements the non-destructive read path.

What's in this PR

New command: typescript/src/commands/ai.ts — top-level ai with five subcommands, flag parsing (--model, -y/--yes) wired up via commander.

New lib modules at typescript/src/lib/ai/:

  • paths.ts — resolves ~/.prompd/ai/ and subdirs
  • types.tsModelEntry, Catalog, DaemonLock, DaemonStatus
  • catalog.ts — load/save, findModel, getDefaultModel (explicit-default → first-installed fallback)
  • daemon.tsreadLock, clearLock, isPidAlive, getStatus with stale-lock cleanup

Behavior in this PR:

  • prompd ai --help — clean output, all 5 verbs listed
  • prompd ai status — fully functional; reads catalog + lock file, clears stale locks, prints running state and installed-models list
  • prompd ai install / uninstall / start / stop — print "Phase 1 scaffolding — not yet implemented" with their parsed flags echoed back

Tests: 8 new tests covering catalog round-trip, default-model resolution, corrupt-file handling, not-running status, and stale-lock cleanup on dead PIDs. Full suite passes (21 suites, 339 pass, 5 skipped).

Why this shape

Small, reviewable PR. Commits the command surface (names, flags, help text) and proves the plumbing without making the big llama-server bundling decision. Follow-ups will fill in install (downloader + manifest), start (llama-server spawn + lock write), etc.

Why prompd ai

Chosen in Prompd/prompd-app#46. The AIDEN / AI Fox codenames were dropped — Aiden-space is crowded in the AI-assistant market and prompd ai is intuitive in --help output + trademark-collision-proof.

Plan

Full plan in prompd-app/docs/PROMPD-AI-PLAN.md.

Test plan

  • npm run build succeeds
  • npx jest passes (21 suites, 339 tests)
  • node ./bin/prompd.js ai --help renders cleanly
  • node ./bin/prompd.js ai status reports "Not running" and "(none)" on a fresh machine
  • node ./bin/prompd.js ai install --model gemma-4-e4b-q4 -y echoes the parsed flags

Generated with Claude Code

Adds the five-verb CLI surface for the on-device Prompd AI runtime:
install / uninstall / start / stop / status. All verbs are wired through
commander with --model and --yes flags where applicable.

Only `status` is fully functional in this PR — it reads the catalog and
daemon.lock, checks for a live PID, clears stale locks, and prints
installed-models + running state. The other four verbs print a "Phase 1
scaffolding — not yet implemented" message with their parsed flags.

Supporting lib modules at src/lib/ai/:
- paths.ts: resolves ~/.prompd/ai/ and its subdirs
- types.ts: ModelEntry, Catalog, DaemonLock, DaemonStatus
- catalog.ts: load/save, findModel, getDefaultModel (default-first fallback)
- daemon.ts: readLock, clearLock, isPidAlive, getStatus with stale-lock cleanup

Tests cover catalog round-trip, default-model resolution, corrupt-file
handling, not-running status, and stale-lock cleanup on dead PIDs (8 tests).

See docs/PROMPD-AI-PLAN.md in prompd-app for the full plan.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c22f5a666f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +38 to +39
} catch {
return false;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Treat EPERM as alive in PID liveness checks

isPidAlive currently maps every process.kill(pid, 0) exception to “dead”, but Node throws EPERM when a process exists but the current user cannot signal it. In that case getStatus will incorrectly clear daemon.lock and report “Not running”, which can happen when the daemon is started under a different user/context (e.g., sudo/service account) while the same home directory is reused.

Useful? React with 👍 / 👎.

Comment on lines +14 to +17
if (!raw || raw.version !== 1 || !Array.isArray(raw.models)) {
return { version: 1, models: [] };
}
return raw as Catalog;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate model entries before accepting catalog JSON

loadCatalog only checks that models is an array, so partially corrupt data like {"version":1,"models":[null]} is treated as valid. The ai status renderer then dereferences each entry (m.isDefault / m.name) and crashes on null entries, which breaks the intended “graceful handling” path for corrupted catalog files.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant