Skip to content

MVP: establish cross-platform Computer Doctor CLI architecture with controlled E2E repair loop#2

Open
Copilot wants to merge 5 commits into
mainfrom
copilot/mvp-cross-platform-cli-framework
Open

MVP: establish cross-platform Computer Doctor CLI architecture with controlled E2E repair loop#2
Copilot wants to merge 5 commits into
mainfrom
copilot/mvp-cross-platform-cli-framework

Conversation

Copy link
Copy Markdown

Copilot AI commented May 18, 2026

This PR lays down the MVP framework for a technician-facing, USB-portable CLI repair agent: clear architectural boundaries first, platform-specific capability later. It introduces the first runnable end-to-end loop (session → diagnostics → plan → action → persistence → markdown audit artifacts) with cross-platform extension points from day one.

  • CLI entry + command architecture (commander-jsx)

    • Added JSX-defined command tree with a unified mvp entrypoint.
    • Added concise global verbose handling via zx ($.verbose) and workspace routing for local runtime artifacts.
    • Renamed command module to src/command/MVP.tsx.
  • Core domain contracts (extensibility boundaries)

    • Kept JSON object shapes as interfaces.
    • Refactored behavior boundaries (PlatformAdapter, DiagnosticProvider, PlanGenerator, RepairAction, ActionExecutor, SessionStore, MarkdownReportRenderer) to abstract base classes for cleaner type reuse and implementation style.
    • Separated workflow orchestration from infra details to keep platform and capability modules swappable.
  • Platform adapter layout

    • Added adapter registry + selection.
    • Implemented Windows adapter skeleton as first-class target.
    • Added Linux/macOS adapter placeholders with identical contract surface.
    • Applied simplified arrow-function/deconstruction style where appropriate.
  • Controlled execution + planning path

    • Removed the extra zx wrapper layer; command execution is now directly written with zx in actions.
    • Kept Vercel AI SDK planning skeleton with strict action allowlist fallback behavior (LLM does not get arbitrary execution rights).
    • Switched MVP default provider path to Gemini (@ai-sdk/google) and added configurable model selection via AI_MODEL.
    • Updated key handling to AI_API_KEY.
  • Local persistence + auditability

    • Refactored persistence directory from infra/db to infra/store.
    • Updated TypeORM data source to better-sqlite3.
    • Refactored entities with shared Base class and simplified repository usage in TypeormSessionStore.
    • Persisted stage payloads across diagnostic/plan/repair/rollback lifecycle.
  • Markdown documentation outputs

    • Kept per-stage markdown renderer and file layout under reports/<session-id>/.
    • Updated renderer to use template-literal multi-line markdown output and requested import style.
    • Every stage in the loop emits a human-readable + archivable markdown artifact.
  • MVP orchestration

    • Added workflow runner composing all contracts and infra into one minimal closed loop.
    • Added CLI summary component to render session/action/report outputs in terminal using JSX (.tsx).
  • Project tooling and tests

    • Updated scripts to debug and pack-exe (using pnpm pack-app).
    • Moved tests to the root test/ directory and updated test script accordingly.
/** @jsxImportSource commander-jsx */
Command.execute(
  <Command name="computer-doctor" parameters="[command]">
    <Command
      name="mvp"
      options={{
        verbose: { shortcut: 'V', description: 'Enable verbose mode' },
        workspace: { shortcut: 'w', parameters: '<path>' }
      }}
      executor={async ({ verbose, workspace }) => {
        const oldVerbose = $.verbose;
        $.verbose = !!verbose;
        await runMVPCommand({
          workspaceDir: typeof workspace === 'string' ? workspace : process.cwd(),
          verbose: !!verbose
        });
        $.verbose = oldVerbose;
      }}
    />
  </Command>,
  process.argv.slice(2)
);

Copilot AI changed the title [WIP] Build MVP framework for cross-platform CLI tool for tech repair MVP: establish cross-platform Computer Doctor CLI architecture with controlled E2E repair loop May 18, 2026
Copilot AI requested a review from TechQuery May 18, 2026 17:29
Comment thread package.json Outdated
Comment thread package.json Outdated
Comment thread src/index.tsx Outdated
Comment thread src/commander-jsx-compat.d.ts Outdated
Comment thread test/mvp-runner.test.ts
Comment thread src/infra/db/data-source.ts Outdated
Comment thread src/core/contracts.ts Outdated
Comment on lines +58 to +63
export interface Session {
id: string;
platform: string;
status: 'running' | 'completed' | 'failed';
createdAt: Date;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
export interface Session {
id: string;
platform: string;
status: 'running' | 'completed' | 'failed';
createdAt: Date;
}

class 本身就具备 interface 的类型信息。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

已移除这块重复接口定义,并让相关抽象边界改为基类承载类型信息。见提交 94a68d3。UI 截图:https://github.com/user-attachments/assets/6de680e3-1c9c-4668-a876-1186f9d4a284

Comment thread src/core/contracts.ts
Comment thread src/core/action-executor.ts Outdated
Comment thread src/command/MVP.tsx
Copilot AI requested a review from TechQuery May 18, 2026 19:17
Comment thread src/command/MVP.tsx Outdated
Comment thread src/core/actions.ts Outdated
Comment thread src/ui/run-summary.tsx Outdated
Comment thread package-lock.json Outdated
Comment thread README.md Outdated
Comment thread tsconfig.json Outdated
@TechQuery TechQuery marked this pull request as ready for review May 18, 2026 19:54
Copilot AI review requested due to automatic review settings May 18, 2026 19:54
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR establishes the initial TypeScript CLI architecture for Computer Doctor, including a runnable MVP diagnostic/planning/repair/reporting loop with platform adapters, local SQLite persistence, markdown reports, and tests.

Changes:

  • Adds CLI entrypoint, command wiring, Ink summary UI, and MVP workflow orchestration.
  • Introduces core contracts, platform adapters, action execution, AI-backed/fallback planning, TypeORM persistence, and markdown report rendering.
  • Adds project tooling, pnpm lockfile, README usage notes, gitignore updates, and an MVP integration test.

Reviewed changes

Copilot reviewed 20 out of 23 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
.gitignore Ignores SQLite/report artifacts and npm lockfile.
package.json Defines package metadata, scripts, runtime deps, and CLI bin.
pnpm-lock.yaml Locks newly introduced pnpm dependencies.
README.md Documents MVP framework, usage, development, and artifacts.
tsconfig.json Adds strict TypeScript/JSX/decorator build config.
src/index.tsx Adds commander-jsx CLI entrypoint.
src/command/MVP.tsx Composes MVP dependencies and renders run summary.
src/core/contracts.ts Defines domain contracts and shared types.
src/core/actions.ts Adds health-check repair action.
src/core/action-executor.ts Adds default action executor.
src/core/diagnostic-provider.ts Adds default diagnostic provider wrapper.
src/infra/llm/vercel-ai-plan-generator.ts Adds Gemini/Vercel AI SDK plan generator with fallback.
src/infra/store/data-source.ts Adds TypeORM better-sqlite3 data source factory.
src/infra/store/entities.ts Adds session and stage persistence entities.
src/infra/store/typeorm-session-store.ts Implements session store with TypeORM repositories.
src/platform/registry.ts Adds platform adapter registry and selector.
src/platform/linux/adapter.ts Adds Linux diagnostic adapter skeleton.
src/platform/macos/adapter.ts Adds macOS diagnostic adapter skeleton.
src/platform/windows/adapter.ts Adds Windows diagnostic adapter skeleton.
src/report/markdown-report-renderer.ts Adds markdown report writer.
src/ui/run-summary.tsx Adds Ink summary component.
src/workflow/mvp-runner.ts Orchestrates session, diagnostic, plan, repair, rollback, and persistence.
test/mvp-runner.test.ts Adds MVP flow persistence/report integration test.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread package.json
Comment on lines +8 to +13
"computer-doctor": "dist/index.js"
},
"scripts": {
"build": "tsc -p tsconfig.json",
"dev": "tsx src/index.tsx",
"start": "node dist/index.js",
Comment thread package.json
Comment thread src/core/actions.ts
Comment on lines +9 to +11
async execute(_context: RuntimeContext, payload: Record<string, string>): Promise<ActionExecution> {
const command = payload.command ?? 'node';
const args = [payload.arg0 ?? '-e', payload.arg1 ?? "console.log('health-check-ok')"];
Comment thread src/index.tsx
@@ -0,0 +1,50 @@
/** @jsxImportSource commander-jsx */
Comment thread src/command/MVP.tsx
Comment on lines +18 to +28
const result = await runMVPFlow(context, {
diagnosticProvider: new DefaultDiagnosticProvider(),
planGenerator: new VercelAIPlanGenerator(),
actionExecutor: new DefaultActionExecutor([new HealthCheckAction()]),
sessionStore,
reportRenderer: new DefaultMarkdownReportRenderer(context.workspaceDir)
});

render(<RunSummary result={result} verbose={context.verbose} />);

await dataSource.destroy();
Comment thread src/index.tsx
Comment on lines +45 to +48
() => process.exit(),
error => {
console.error(error);
process.exit(1);
Comment thread README.md
# Computer-Doctor-CLI
AI command line toolkit for Computer Repairing

AI command line toolkit for Computer Repairing.
Comment thread test/mvp-runner.test.ts
Comment on lines +25 to +61
const workspaceDir = await mkdtemp(path.join(os.tmpdir(), 'computer-doctor-'));
tempDirs.push(workspaceDir);

const dataSource = createAppDataSource(workspaceDir);

const result = await runMVPFlow(
{ verbose: false, workspaceDir },
{
diagnosticProvider: new DefaultDiagnosticProvider(),
planGenerator: new VercelAIPlanGenerator(),
actionExecutor: new DefaultActionExecutor([new HealthCheckAction()]),
sessionStore: new TypeormSessionStore(dataSource),
reportRenderer: new DefaultMarkdownReportRenderer(workspaceDir)
}
);

assert.equal(result.actionCount, 1);

const stageFiles = await Promise.all([
readFile(result.reports.diagnostic, 'utf8'),
readFile(result.reports.plan, 'utf8'),
readFile(result.reports.repair, 'utf8'),
readFile(result.reports.rollback, 'utf8')
]);

for (const content of stageFiles) {
assert.match(content, /# [A-Z]+ 报告/);
assert.match(content, /Session:/);
}

const sessionCount = await dataSource.getRepository(Session).count();
const stageCount = await dataSource.getRepository(StageRecord).count();

assert.equal(sessionCount, 1);
assert.equal(stageCount, 4);

await dataSource.destroy();
Comment on lines +23 to +33
const { text } = await generateText({
model: google(process.env.AI_MODEL || 'gemini-2.5-flash'),
prompt: [
'你是电脑维修助手。',
'请基于输入诊断信息输出 JSON:{"summary": string, "actions": [{"id": "health-check", "title": string, "payload": {"command": "node", "arg0": "-e", "arg1": "console.log(\\"health-check-ok\\")"}}]}。',
'只能使用 id=health-check,不能生成其他命令。',
`输入: ${JSON.stringify(input)}`
].join('\n')
});

try {
Comment on lines +44 to +49

const rollback = repairs.map(({ actionId, rollbackHint }) => ({ actionId, rollbackHint }));
const rollbackReport = await deps.reportRenderer.renderStage(session.id, 'rollback', rollback);
await deps.sessionStore.appendStage(session.id, 'rollback', rollback, rollbackReport);

await deps.sessionStore.updateSessionStatus(session.id, 'completed');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MVP: 搭建面向电脑维修技术员的跨平台 CLI 修复 Agent 程序框架

3 participants