@ohos-ports/assistant-ui 0.0.0-stage → 0.0.136-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -2
- package/bin/assistant-ui.js +2 -0
- package/dist/codemods/utils/createTransformer.d.ts +15 -0
- package/dist/codemods/utils/createTransformer.d.ts.map +1 -0
- package/dist/codemods/utils/createTransformer.js +19 -0
- package/dist/codemods/utils/createTransformer.js.map +1 -0
- package/dist/codemods/utils/resolveBinding.d.ts +3 -0
- package/dist/codemods/utils/resolveBinding.d.ts.map +1 -0
- package/dist/codemods/utils/resolveBinding.js +77 -0
- package/dist/codemods/utils/resolveBinding.js.map +1 -0
- package/dist/codemods/v0-11/content-part-to-message-part.d.ts +3 -0
- package/dist/codemods/v0-11/content-part-to-message-part.d.ts.map +1 -0
- package/dist/codemods/v0-11/content-part-to-message-part.js +189 -0
- package/dist/codemods/v0-11/content-part-to-message-part.js.map +1 -0
- package/dist/codemods/v0-12/assistant-api-to-aui.d.ts +3 -0
- package/dist/codemods/v0-12/assistant-api-to-aui.d.ts.map +1 -0
- package/dist/codemods/v0-12/assistant-api-to-aui.js +117 -0
- package/dist/codemods/v0-12/assistant-api-to-aui.js.map +1 -0
- package/dist/codemods/v0-12/event-names-to-camelcase.d.ts +3 -0
- package/dist/codemods/v0-12/event-names-to-camelcase.d.ts.map +1 -0
- package/dist/codemods/v0-12/event-names-to-camelcase.js +38 -0
- package/dist/codemods/v0-12/event-names-to-camelcase.js.map +1 -0
- package/dist/codemods/v0-12/primitive-if-to-aui-if.d.ts +3 -0
- package/dist/codemods/v0-12/primitive-if-to-aui-if.d.ts.map +1 -0
- package/dist/codemods/v0-12/primitive-if-to-aui-if.js +226 -0
- package/dist/codemods/v0-12/primitive-if-to-aui-if.js.map +1 -0
- package/dist/codemods/v0-15/aui-accessor-calls-to-properties.d.ts +3 -0
- package/dist/codemods/v0-15/aui-accessor-calls-to-properties.d.ts.map +1 -0
- package/dist/codemods/v0-15/aui-accessor-calls-to-properties.js +85 -0
- package/dist/codemods/v0-15/aui-accessor-calls-to-properties.js.map +1 -0
- package/dist/codemods/v0-8/ui-package-split.d.ts +3 -0
- package/dist/codemods/v0-8/ui-package-split.d.ts.map +1 -0
- package/dist/codemods/v0-8/ui-package-split.js +102 -0
- package/dist/codemods/v0-8/ui-package-split.js.map +1 -0
- package/dist/codemods/v0-9/edge-package-split.d.ts +3 -0
- package/dist/codemods/v0-9/edge-package-split.d.ts.map +1 -0
- package/dist/codemods/v0-9/edge-package-split.js +47 -0
- package/dist/codemods/v0-9/edge-package-split.js.map +1 -0
- package/dist/commands/add.d.ts +17 -0
- package/dist/commands/add.d.ts.map +1 -0
- package/dist/commands/add.js +63 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/agent.d.ts +3 -0
- package/dist/commands/agent.d.ts.map +1 -0
- package/dist/commands/agent.js +27 -0
- package/dist/commands/agent.js.map +1 -0
- package/dist/commands/cloud.d.ts +25 -0
- package/dist/commands/cloud.d.ts.map +1 -0
- package/dist/commands/cloud.js +239 -0
- package/dist/commands/cloud.js.map +1 -0
- package/dist/commands/create.d.ts +58 -0
- package/dist/commands/create.d.ts.map +1 -0
- package/dist/commands/create.js +626 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/doctor.d.ts +22 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +255 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/info.d.ts +6 -0
- package/dist/commands/info.d.ts.map +1 -0
- package/dist/commands/info.js +288 -0
- package/dist/commands/info.js.map +1 -0
- package/dist/commands/init.d.ts +13 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +100 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/mcp.d.ts +3 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +279 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/setup.d.ts +24 -0
- package/dist/commands/setup.d.ts.map +1 -0
- package/dist/commands/setup.js +136 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/commands/update.d.ts +3 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +58 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/upgrade.d.ts +10 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/commands/upgrade.js +38 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/agent-gate.d.ts +66 -0
- package/dist/lib/agent-gate.d.ts.map +1 -0
- package/dist/lib/agent-gate.js +180 -0
- package/dist/lib/agent-gate.js.map +1 -0
- package/dist/lib/agent-setup-hint.d.ts +20 -0
- package/dist/lib/agent-setup-hint.d.ts.map +1 -0
- package/dist/lib/agent-setup-hint.js +33 -0
- package/dist/lib/agent-setup-hint.js.map +1 -0
- package/dist/lib/agent-skill.d.ts +14 -0
- package/dist/lib/agent-skill.d.ts.map +1 -0
- package/dist/lib/agent-skill.js +83 -0
- package/dist/lib/agent-skill.js.map +1 -0
- package/dist/lib/cloud-abort.d.ts +2 -0
- package/dist/lib/cloud-abort.d.ts.map +1 -0
- package/dist/lib/cloud-abort.js +12 -0
- package/dist/lib/cloud-abort.js.map +1 -0
- package/dist/lib/cloud-auth.d.ts +30 -0
- package/dist/lib/cloud-auth.d.ts.map +1 -0
- package/dist/lib/cloud-auth.js +179 -0
- package/dist/lib/cloud-auth.js.map +1 -0
- package/dist/lib/cloud-config.d.ts +31 -0
- package/dist/lib/cloud-config.d.ts.map +1 -0
- package/dist/lib/cloud-config.js +128 -0
- package/dist/lib/cloud-config.js.map +1 -0
- package/dist/lib/cloud-organizations.d.ts +17 -0
- package/dist/lib/cloud-organizations.d.ts.map +1 -0
- package/dist/lib/cloud-organizations.js +36 -0
- package/dist/lib/cloud-organizations.js.map +1 -0
- package/dist/lib/cloud-provision.d.ts +20 -0
- package/dist/lib/cloud-provision.d.ts.map +1 -0
- package/dist/lib/cloud-provision.js +59 -0
- package/dist/lib/cloud-provision.js.map +1 -0
- package/dist/lib/cloud-remote.d.ts +37 -0
- package/dist/lib/cloud-remote.d.ts.map +1 -0
- package/dist/lib/cloud-remote.js +118 -0
- package/dist/lib/cloud-remote.js.map +1 -0
- package/dist/lib/cloud-setup-login.d.ts +9 -0
- package/dist/lib/cloud-setup-login.d.ts.map +1 -0
- package/dist/lib/cloud-setup-login.js +136 -0
- package/dist/lib/cloud-setup-login.js.map +1 -0
- package/dist/lib/cloud-url.d.ts +3 -0
- package/dist/lib/cloud-url.d.ts.map +1 -0
- package/dist/lib/cloud-url.js +10 -0
- package/dist/lib/cloud-url.js.map +1 -0
- package/dist/lib/create-project.d.ts +51 -0
- package/dist/lib/create-project.d.ts.map +1 -0
- package/dist/lib/create-project.js +458 -0
- package/dist/lib/create-project.js.map +1 -0
- package/dist/lib/handle-cli-error.d.ts +2 -0
- package/dist/lib/handle-cli-error.d.ts.map +1 -0
- package/dist/lib/handle-cli-error.js +16 -0
- package/dist/lib/handle-cli-error.js.map +1 -0
- package/dist/lib/init-finish.d.ts +46 -0
- package/dist/lib/init-finish.d.ts.map +1 -0
- package/dist/lib/init-finish.js +187 -0
- package/dist/lib/init-finish.js.map +1 -0
- package/dist/lib/install-ai-sdk-lib.d.ts +2 -0
- package/dist/lib/install-ai-sdk-lib.d.ts.map +1 -0
- package/dist/lib/install-ai-sdk-lib.js +21 -0
- package/dist/lib/install-ai-sdk-lib.js.map +1 -0
- package/dist/lib/install-edge-lib.d.ts +2 -0
- package/dist/lib/install-edge-lib.d.ts.map +1 -0
- package/dist/lib/install-edge-lib.js +14 -0
- package/dist/lib/install-edge-lib.js.map +1 -0
- package/dist/lib/run-spawn.d.ts +21 -0
- package/dist/lib/run-spawn.d.ts.map +1 -0
- package/dist/lib/run-spawn.js +118 -0
- package/dist/lib/run-spawn.js.map +1 -0
- package/dist/lib/safe-project-file.d.ts +2 -0
- package/dist/lib/safe-project-file.d.ts.map +1 -0
- package/dist/lib/safe-project-file.js +25 -0
- package/dist/lib/safe-project-file.js.map +1 -0
- package/dist/lib/setup-session.d.ts +44 -0
- package/dist/lib/setup-session.d.ts.map +1 -0
- package/dist/lib/setup-session.js +122 -0
- package/dist/lib/setup-session.js.map +1 -0
- package/dist/lib/transform-options.d.ts +7 -0
- package/dist/lib/transform-options.d.ts.map +1 -0
- package/dist/lib/transform-options.js +0 -0
- package/dist/lib/transform.d.ts +17 -0
- package/dist/lib/transform.d.ts.map +1 -0
- package/dist/lib/transform.js +75 -0
- package/dist/lib/transform.js.map +1 -0
- package/dist/lib/upgrade.d.ts +9 -0
- package/dist/lib/upgrade.d.ts.map +1 -0
- package/dist/lib/upgrade.js +68 -0
- package/dist/lib/upgrade.js.map +1 -0
- package/dist/lib/utils/config.d.ts +20 -0
- package/dist/lib/utils/config.d.ts.map +1 -0
- package/dist/lib/utils/config.js +28 -0
- package/dist/lib/utils/config.js.map +1 -0
- package/dist/lib/utils/download.d.ts +5 -0
- package/dist/lib/utils/download.d.ts.map +1 -0
- package/dist/lib/utils/download.js +40 -0
- package/dist/lib/utils/download.js.map +1 -0
- package/dist/lib/utils/file-scanner.d.ts +15 -0
- package/dist/lib/utils/file-scanner.d.ts.map +1 -0
- package/dist/lib/utils/file-scanner.js +37 -0
- package/dist/lib/utils/file-scanner.js.map +1 -0
- package/dist/lib/utils/logger.d.ts +9 -0
- package/dist/lib/utils/logger.d.ts.map +1 -0
- package/dist/lib/utils/logger.js +25 -0
- package/dist/lib/utils/logger.js.map +1 -0
- package/dist/lib/utils/package-installer.d.ts +9 -0
- package/dist/lib/utils/package-installer.d.ts.map +1 -0
- package/dist/lib/utils/package-installer.js +21 -0
- package/dist/lib/utils/package-installer.js.map +1 -0
- package/dist/lib/utils/package-json.d.ts +2 -0
- package/dist/lib/utils/package-json.d.ts.map +1 -0
- package/dist/lib/utils/package-json.js +10 -0
- package/dist/lib/utils/package-json.js.map +1 -0
- package/dist/lib/utils/package-manager.d.ts +24 -0
- package/dist/lib/utils/package-manager.d.ts.map +1 -0
- package/dist/lib/utils/package-manager.js +117 -0
- package/dist/lib/utils/package-manager.js.map +1 -0
- package/dist/lib/utils/registry.d.ts +6 -0
- package/dist/lib/utils/registry.d.ts.map +1 -0
- package/dist/lib/utils/registry.js +35 -0
- package/dist/lib/utils/registry.js.map +1 -0
- package/dist/lib/utils/workspace.d.ts +3 -0
- package/dist/lib/utils/workspace.d.ts.map +1 -0
- package/dist/lib/utils/workspace.js +27 -0
- package/dist/lib/utils/workspace.js.map +1 -0
- package/dist/program.d.ts +3 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +22 -0
- package/dist/program.js.map +1 -0
- package/dist/run.d.ts +2 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +8 -0
- package/dist/run.js.map +1 -0
- package/package.json +76 -4
- package/src/codemods/utils/createTransformer.ts +41 -0
- package/src/codemods/utils/resolveBinding.test.ts +107 -0
- package/src/codemods/utils/resolveBinding.ts +130 -0
- package/src/codemods/v0-11/README.md +246 -0
- package/src/codemods/v0-11/__tests__/content-part-to-message-part.test.ts +496 -0
- package/src/codemods/v0-11/content-part-to-message-part.ts +302 -0
- package/src/codemods/v0-12/__tests__/assistant-api-to-aui.test.ts +1220 -0
- package/src/codemods/v0-12/__tests__/event-names-to-camelcase.test.ts +150 -0
- package/src/codemods/v0-12/__tests__/primitive-if-to-aui-if.test.ts +1166 -0
- package/src/codemods/v0-12/assistant-api-to-aui.ts +270 -0
- package/src/codemods/v0-12/event-names-to-camelcase.ts +47 -0
- package/src/codemods/v0-12/primitive-if-to-aui-if.ts +372 -0
- package/src/codemods/v0-15/__tests__/aui-accessor-calls-to-properties.test.ts +210 -0
- package/src/codemods/v0-15/aui-accessor-calls-to-properties.ts +138 -0
- package/src/codemods/v0-8/__tests__/ui-package-split.test.ts +83 -0
- package/src/codemods/v0-8/ui-package-split.ts +159 -0
- package/src/codemods/v0-9/edge-package-split.test.ts +100 -0
- package/src/codemods/v0-9/edge-package-split.ts +70 -0
- package/src/commands/add.ts +111 -0
- package/src/commands/agent.ts +31 -0
- package/src/commands/cloud.test.ts +477 -0
- package/src/commands/cloud.ts +523 -0
- package/src/commands/create.ts +914 -0
- package/src/commands/doctor.ts +425 -0
- package/src/commands/info.ts +481 -0
- package/src/commands/init.ts +156 -0
- package/src/commands/mcp.test.ts +123 -0
- package/src/commands/mcp.ts +475 -0
- package/src/commands/setup.test.ts +285 -0
- package/src/commands/setup.ts +240 -0
- package/src/commands/update.ts +86 -0
- package/src/commands/upgrade.ts +66 -0
- package/src/index.ts +6 -0
- package/src/lib/agent-gate.test.ts +435 -0
- package/src/lib/agent-gate.ts +271 -0
- package/src/lib/agent-setup-hint.test.ts +134 -0
- package/src/lib/agent-setup-hint.ts +56 -0
- package/src/lib/agent-skill.ts +107 -0
- package/src/lib/cloud-abort.ts +12 -0
- package/src/lib/cloud-auth.test.ts +536 -0
- package/src/lib/cloud-auth.ts +299 -0
- package/src/lib/cloud-config.test.ts +220 -0
- package/src/lib/cloud-config.ts +217 -0
- package/src/lib/cloud-organizations.test.ts +76 -0
- package/src/lib/cloud-organizations.ts +55 -0
- package/src/lib/cloud-provision.test.ts +157 -0
- package/src/lib/cloud-provision.ts +96 -0
- package/src/lib/cloud-remote.test.ts +252 -0
- package/src/lib/cloud-remote.ts +236 -0
- package/src/lib/cloud-setup-login.test.ts +361 -0
- package/src/lib/cloud-setup-login.ts +240 -0
- package/src/lib/cloud-url.ts +21 -0
- package/src/lib/create-project-format.test.ts +122 -0
- package/src/lib/create-project.test.ts +158 -0
- package/src/lib/create-project.ts +717 -0
- package/src/lib/handle-cli-error.test.ts +67 -0
- package/src/lib/handle-cli-error.ts +17 -0
- package/src/lib/init-finish.ts +293 -0
- package/src/lib/install-ai-sdk-lib.ts +25 -0
- package/src/lib/install-edge-lib.ts +16 -0
- package/src/lib/run-spawn.test.ts +194 -0
- package/src/lib/run-spawn.ts +154 -0
- package/src/lib/safe-project-file.ts +31 -0
- package/src/lib/setup-session.test.ts +184 -0
- package/src/lib/setup-session.ts +179 -0
- package/src/lib/transform-files.test.ts +69 -0
- package/src/lib/transform-options.ts +6 -0
- package/src/lib/transform.test.ts +155 -0
- package/src/lib/transform.ts +131 -0
- package/src/lib/upgrade.ts +89 -0
- package/src/lib/utils/config.ts +60 -0
- package/src/lib/utils/download.ts +57 -0
- package/src/lib/utils/file-scanner.ts +51 -0
- package/src/lib/utils/logger.ts +22 -0
- package/src/lib/utils/package-installer.test.ts +39 -0
- package/src/lib/utils/package-installer.ts +40 -0
- package/src/lib/utils/package-json.ts +12 -0
- package/src/lib/utils/package-manager.ts +160 -0
- package/src/lib/utils/registry.test.ts +164 -0
- package/src/lib/utils/registry.ts +78 -0
- package/src/lib/utils/workspace.ts +34 -0
- package/src/program.ts +37 -0
- package/src/run.test.ts +23 -0
- package/src/run.ts +5 -0
- package/templates/cloud-harness/.assistant-ui/template.json +3 -0
- package/templates/cloud-harness/.env.example +1 -0
- package/templates/cloud-harness/.oxfmtrc.json +32 -0
- package/templates/cloud-harness/README.md +28 -0
- package/templates/cloud-harness/app/api/chat/route.ts +22 -0
- package/templates/cloud-harness/app/api/credential/route.ts +14 -0
- package/templates/cloud-harness/app/api/request-context.ts +16 -0
- package/templates/cloud-harness/app/assistant.tsx +83 -0
- package/templates/cloud-harness/app/favicon.ico +0 -0
- package/templates/cloud-harness/app/globals.css +139 -0
- package/templates/cloud-harness/app/layout.tsx +37 -0
- package/templates/cloud-harness/app/page.tsx +5 -0
- package/templates/cloud-harness/components/assistant-ui/elements/attachment-state.ts +59 -0
- package/templates/cloud-harness/components/assistant-ui/elements/attachment.aui.tsx +246 -0
- package/templates/cloud-harness/components/assistant-ui/elements/collapsible-root.tsx +19 -0
- package/templates/cloud-harness/components/assistant-ui/elements/markdown-text.tsx +238 -0
- package/templates/cloud-harness/components/assistant-ui/elements/thread.aui.tsx +521 -0
- package/templates/cloud-harness/components/assistant-ui/elements/tool-fallback.aui.tsx +1336 -0
- package/templates/cloud-harness/components/assistant-ui/elements/tooltip-icon-button.tsx +49 -0
- package/templates/cloud-harness/components/ui/avatar.tsx +109 -0
- package/templates/cloud-harness/components/ui/button.tsx +58 -0
- package/templates/cloud-harness/components/ui/collapsible.tsx +21 -0
- package/templates/cloud-harness/components/ui/dialog.tsx +159 -0
- package/templates/cloud-harness/components/ui/textarea.tsx +18 -0
- package/templates/cloud-harness/components/ui/tooltip.tsx +69 -0
- package/templates/cloud-harness/components.json +24 -0
- package/templates/cloud-harness/hooks/use-attachment-src.ts +46 -0
- package/templates/cloud-harness/hooks/use-copy-to-clipboard.ts +54 -0
- package/templates/cloud-harness/lib/utils.ts +1 -0
- package/templates/cloud-harness/next.config.ts +6 -0
- package/templates/cloud-harness/package.json +51 -0
- package/templates/cloud-harness/postcss.config.mjs +5 -0
- package/templates/cloud-harness/tsconfig.json +33 -0
- package/templates/cloud-harness/vendor/LICENSE +21 -0
- package/templates/cloud-harness/vendor/README.md +13 -0
- package/templates/cloud-harness/vendor/assistant-ui-react-harness-sdk-0.0.2.tgz +0 -0
- package/templates/cloud-harness/vendor/harness-sdk-0.3.1.tgz +0 -0
- package/templates/cloud-harness/vendor/provenance.json +38 -0
- package/templates/cloud-harness/vendor/statewire-0.19.3.tgz +0 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
AGENT_SETUP_HINT,
|
|
5
|
+
addAgentSetupHint,
|
|
6
|
+
isRunByAgent,
|
|
7
|
+
} from "./agent-setup-hint";
|
|
8
|
+
import { buildProgram } from "../program";
|
|
9
|
+
|
|
10
|
+
const tty = { isTTY: true };
|
|
11
|
+
|
|
12
|
+
describe("isRunByAgent", () => {
|
|
13
|
+
it("is true under an agent or without a terminal", () => {
|
|
14
|
+
expect(isRunByAgent({ CLAUDECODE: "1" }, tty, tty)).toBe(true);
|
|
15
|
+
expect(isRunByAgent({}, { isTTY: undefined }, tty)).toBe(true);
|
|
16
|
+
expect(isRunByAgent({}, tty, tty)).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe("addAgentSetupHint", () => {
|
|
21
|
+
const env = { ...process.env };
|
|
22
|
+
const argv = process.argv;
|
|
23
|
+
const afterCleanup: (() => void)[] = [];
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
for (const cleanup of afterCleanup.splice(0)) cleanup();
|
|
26
|
+
process.env = { ...env };
|
|
27
|
+
process.argv = argv;
|
|
28
|
+
vi.restoreAllMocks();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const help = (command: Command) => {
|
|
32
|
+
let text = "";
|
|
33
|
+
command.configureOutput({ writeOut: (chunk) => (text += chunk) });
|
|
34
|
+
command.outputHelp();
|
|
35
|
+
return text;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
it("ends the help with the hint for an agent only, so `--help | tail` keeps it", () => {
|
|
39
|
+
const command = addAgentSetupHint(new Command("init"), {
|
|
40
|
+
afterAction: false,
|
|
41
|
+
});
|
|
42
|
+
process.env.CLAUDECODE = "1";
|
|
43
|
+
expect(help(command).endsWith(`${AGENT_SETUP_HINT}\n`)).toBe(true);
|
|
44
|
+
expect(help(command).startsWith(AGENT_SETUP_HINT)).toBe(false);
|
|
45
|
+
// Only PATH survives, so no agent variable from the shell running the tests leaks in.
|
|
46
|
+
process.env = { PATH: env.PATH };
|
|
47
|
+
const stdin = Object.getOwnPropertyDescriptor(process.stdin, "isTTY");
|
|
48
|
+
const stdout = Object.getOwnPropertyDescriptor(process.stdout, "isTTY");
|
|
49
|
+
Object.defineProperty(process.stdin, "isTTY", {
|
|
50
|
+
value: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(process.stdout, "isTTY", {
|
|
54
|
+
value: true,
|
|
55
|
+
configurable: true,
|
|
56
|
+
});
|
|
57
|
+
try {
|
|
58
|
+
expect(help(command)).not.toContain(AGENT_SETUP_HINT);
|
|
59
|
+
} finally {
|
|
60
|
+
for (const [stream, descriptor] of [
|
|
61
|
+
[process.stdin, stdin],
|
|
62
|
+
[process.stdout, stdout],
|
|
63
|
+
] as const) {
|
|
64
|
+
if (descriptor) Object.defineProperty(stream, "isTTY", descriptor);
|
|
65
|
+
else delete (stream as { isTTY?: boolean }).isTTY;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("ends the root help with the hint for an agent", () => {
|
|
71
|
+
process.env.CLAUDECODE = "1";
|
|
72
|
+
const text = help(buildProgram());
|
|
73
|
+
expect(text.trimEnd().endsWith(AGENT_SETUP_HINT)).toBe(true);
|
|
74
|
+
expect(text.split(AGENT_SETUP_HINT)).toHaveLength(2);
|
|
75
|
+
for (const name of ["init", "create"]) {
|
|
76
|
+
const command = buildProgram().commands.find((c) => c.name() === name)!;
|
|
77
|
+
expect(help(command).trimEnd().endsWith(AGENT_SETUP_HINT)).toBe(true);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("prints the hint once after the command typed without a terminal", async () => {
|
|
82
|
+
const write = vi
|
|
83
|
+
.spyOn(process.stdout, "write")
|
|
84
|
+
.mockImplementation(() => true);
|
|
85
|
+
// No agent markers, so the agent gate lets it through; no terminal, so the hint shows.
|
|
86
|
+
process.env = { PATH: env.PATH };
|
|
87
|
+
const stdin = Object.getOwnPropertyDescriptor(process.stdin, "isTTY");
|
|
88
|
+
Object.defineProperty(process.stdin, "isTTY", {
|
|
89
|
+
value: undefined,
|
|
90
|
+
configurable: true,
|
|
91
|
+
});
|
|
92
|
+
afterCleanup.push(() => {
|
|
93
|
+
if (stdin) Object.defineProperty(process.stdin, "isTTY", stdin);
|
|
94
|
+
else delete (process.stdin as { isTTY?: boolean }).isTTY;
|
|
95
|
+
});
|
|
96
|
+
process.argv = ["node", "assistant-ui", "create", "my-app"];
|
|
97
|
+
const action = vi.fn(() => {
|
|
98
|
+
process.stdout.write("Next steps: npm run dev\n");
|
|
99
|
+
});
|
|
100
|
+
const command = addAgentSetupHint(
|
|
101
|
+
new Command("create").argument("[dir]").action(action),
|
|
102
|
+
);
|
|
103
|
+
await command.parseAsync(["my-app"], { from: "user" });
|
|
104
|
+
await command.parseAsync(["my-app"], { from: "user" });
|
|
105
|
+
expect(action).toHaveBeenCalledTimes(2);
|
|
106
|
+
const chunks = write.mock.calls.map(([chunk]) => String(chunk));
|
|
107
|
+
expect(chunks.filter((chunk) => chunk.includes(AGENT_SETUP_HINT))).toEqual([
|
|
108
|
+
`\n${AGENT_SETUP_HINT}\n`,
|
|
109
|
+
]);
|
|
110
|
+
// After the command's own output, where the tail of it shows.
|
|
111
|
+
expect(chunks.findIndex((chunk) => chunk.includes(AGENT_SETUP_HINT))).toBe(
|
|
112
|
+
1,
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("leaves the hint out for an agent past the gate, which is already in setup or forced", async () => {
|
|
117
|
+
const write = vi
|
|
118
|
+
.spyOn(process.stdout, "write")
|
|
119
|
+
.mockImplementation(() => true);
|
|
120
|
+
process.env.CLAUDECODE = "1";
|
|
121
|
+
process.argv = ["node", "assistant-ui", "init", "--yes"];
|
|
122
|
+
const action = vi.fn();
|
|
123
|
+
const command = addAgentSetupHint(
|
|
124
|
+
new Command("init").option("--yes").action(action),
|
|
125
|
+
);
|
|
126
|
+
await command.parseAsync(["--yes"], { from: "user" });
|
|
127
|
+
expect(action).toHaveBeenCalledOnce();
|
|
128
|
+
expect(
|
|
129
|
+
write.mock.calls.filter(([chunk]) =>
|
|
130
|
+
String(chunk).includes(AGENT_SETUP_HINT),
|
|
131
|
+
),
|
|
132
|
+
).toHaveLength(0);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import { detectAgentKind, isDirectInvocation } from "setup-agent/cli";
|
|
3
|
+
import { typedCommand } from "./agent-gate";
|
|
4
|
+
|
|
5
|
+
export const AGENT_SETUP_HINT =
|
|
6
|
+
"Recommended for coding agents: run `npx assistant-ui@latest setup` in the background (Claude Code: run_in_background) and read its output. It keeps running as the guided setup's stream, walks you through the install, and opens the user's browser when it needs their input. If `setup` isn't a known command (a cached or pnpm release-age-gated version), run `npx -y --prefer-online assistant-ui@latest setup` instead.";
|
|
7
|
+
|
|
8
|
+
/** True when a coding agent, or anything else without a terminal, runs the CLI. */
|
|
9
|
+
export const isRunByAgent = (
|
|
10
|
+
env: NodeJS.ProcessEnv = process.env,
|
|
11
|
+
stdin: { isTTY?: boolean | undefined } = process.stdin,
|
|
12
|
+
stdout: { isTTY?: boolean | undefined } = process.stdout,
|
|
13
|
+
) => !isDirectInvocation(env, stdin, stdout);
|
|
14
|
+
|
|
15
|
+
const hinted = new WeakSet<Command>();
|
|
16
|
+
let printed = false;
|
|
17
|
+
|
|
18
|
+
/** Ends `command`'s help with the agent setup hint when an agent reads it, so `--help | tail` keeps it. */
|
|
19
|
+
export const addAgentSetupHelp = (command: Command) => {
|
|
20
|
+
command.addHelpText("after", () =>
|
|
21
|
+
isRunByAgent() ? `\n${AGENT_SETUP_HINT}` : "",
|
|
22
|
+
);
|
|
23
|
+
return command;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Ends `command`'s help with the agent setup hint when an agent reads it,
|
|
28
|
+
* and prints the hint once after the command finishes for one, where an
|
|
29
|
+
* agent reading the tail of the output sees it. People at a terminal see the
|
|
30
|
+
* usual help and output.
|
|
31
|
+
*/
|
|
32
|
+
export const addAgentSetupHint = (
|
|
33
|
+
command: Command,
|
|
34
|
+
{ afterAction = true }: { afterAction?: boolean } = {},
|
|
35
|
+
) => {
|
|
36
|
+
if (hinted.has(command)) return command;
|
|
37
|
+
hinted.add(command);
|
|
38
|
+
addAgentSetupHelp(command);
|
|
39
|
+
if (afterAction) {
|
|
40
|
+
command.hook("postAction", () => {
|
|
41
|
+
// Other commands run create internally; only the one typed gets the hint.
|
|
42
|
+
// A detected agent got here past the agent gate, from a setup session or
|
|
43
|
+
// with --force, so pointing it at setup again would only send it in circles.
|
|
44
|
+
if (
|
|
45
|
+
printed ||
|
|
46
|
+
typedCommand() !== command.name() ||
|
|
47
|
+
!isRunByAgent() ||
|
|
48
|
+
detectAgentKind() !== undefined
|
|
49
|
+
)
|
|
50
|
+
return;
|
|
51
|
+
printed = true;
|
|
52
|
+
process.stdout.write(`\n${AGENT_SETUP_HINT}\n`);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return command;
|
|
56
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { withStagedDownload } from "./utils/download";
|
|
5
|
+
import { dlxCommand, type PackageManagerName } from "./utils/package-manager";
|
|
6
|
+
|
|
7
|
+
export const SKILLS_PACKAGE = "assistant-ui/skills";
|
|
8
|
+
/** The `skills` CLI version that installs {@link SKILLS_PACKAGE}. */
|
|
9
|
+
const SKILLS_CLI_PACKAGE = "skills@1.7.4";
|
|
10
|
+
export const SKILLS_COMMIT = "b0609e66baff7e19f21053d5492464dcc22ec9c3";
|
|
11
|
+
export const SKILLS_PLUGIN_SOURCE = `gh:${SKILLS_PACKAGE}/assistant-ui#${SKILLS_COMMIT}`;
|
|
12
|
+
|
|
13
|
+
export function resolveSkillsInstall(params: {
|
|
14
|
+
skills?: boolean;
|
|
15
|
+
stdinIsTTY?: boolean;
|
|
16
|
+
}): boolean | undefined {
|
|
17
|
+
const { skills, stdinIsTTY = process.stdin.isTTY } = params;
|
|
18
|
+
if (skills !== undefined) return skills;
|
|
19
|
+
if (!stdinIsTTY) return true;
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function buildSkillsAddCommand(
|
|
24
|
+
pm: PackageManagerName,
|
|
25
|
+
params: { stdinIsTTY?: boolean } = {},
|
|
26
|
+
): [string, string[]] {
|
|
27
|
+
const { stdinIsTTY = process.stdin.isTTY } = params;
|
|
28
|
+
const [command, dlxArgs] = dlxCommand(pm);
|
|
29
|
+
const args = [...dlxArgs, SKILLS_CLI_PACKAGE, "add", SKILLS_PACKAGE];
|
|
30
|
+
|
|
31
|
+
// Without a TTY the skills CLI cannot prompt for agent platforms, so skip its
|
|
32
|
+
// confirmation; with a TTY it owns the platform selection interactively.
|
|
33
|
+
if (!stdinIsTTY) args.push("--yes");
|
|
34
|
+
|
|
35
|
+
return [command, args];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function skillsPluginDir(): string {
|
|
39
|
+
const cacheHome =
|
|
40
|
+
process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache");
|
|
41
|
+
return path.join(cacheHome, "assistant-ui", "skills", SKILLS_COMMIT);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function ensureSkillsPlugin(): Promise<string> {
|
|
45
|
+
const dir = skillsPluginDir();
|
|
46
|
+
const marker = path.join(dir, ".claude-plugin", "plugin.json");
|
|
47
|
+
if (fs.existsSync(marker)) return dir;
|
|
48
|
+
|
|
49
|
+
const parent = path.dirname(dir);
|
|
50
|
+
await fs.promises.mkdir(parent, { recursive: true });
|
|
51
|
+
const staging = await fs.promises.mkdtemp(path.join(parent, ".staging-"));
|
|
52
|
+
// Node emits no "exit" when a signal kills the process, so the staging
|
|
53
|
+
// directory is removed on the signal and the signal re-raised. The
|
|
54
|
+
// listeners stay armed until the removal runs, which a download that
|
|
55
|
+
// outlives the timeout defers past the caller's own exit.
|
|
56
|
+
const removeStaging = () => {
|
|
57
|
+
process.removeListener("exit", removeStaging);
|
|
58
|
+
process.removeListener("SIGINT", removeStagingOnSignal);
|
|
59
|
+
process.removeListener("SIGTERM", removeStagingOnSignal);
|
|
60
|
+
fs.rmSync(staging, { recursive: true, force: true });
|
|
61
|
+
};
|
|
62
|
+
const removeStagingOnSignal = (signal: NodeJS.Signals) => {
|
|
63
|
+
removeStaging();
|
|
64
|
+
process.kill(process.pid, signal);
|
|
65
|
+
};
|
|
66
|
+
process.once("exit", removeStaging);
|
|
67
|
+
process.once("SIGINT", removeStagingOnSignal);
|
|
68
|
+
process.once("SIGTERM", removeStagingOnSignal);
|
|
69
|
+
|
|
70
|
+
await withStagedDownload(
|
|
71
|
+
SKILLS_PLUGIN_SOURCE,
|
|
72
|
+
{ dir: staging, preferOffline: true, silent: true },
|
|
73
|
+
"Download timed out.",
|
|
74
|
+
removeStaging,
|
|
75
|
+
async (download) => {
|
|
76
|
+
await download.catch((error: unknown) => {
|
|
77
|
+
throw new Error(
|
|
78
|
+
"Could not fetch the assistant-ui skills from GitHub. Check your network, or set GITHUB_TOKEN if you are rate limited.",
|
|
79
|
+
{ cause: error },
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
await publish(staging, dir, marker);
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
return dir;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// A rename fails when the target directory exists and is not empty. A
|
|
90
|
+
// concurrent invocation that published the same commit meanwhile wins and
|
|
91
|
+
// the staged copy is dropped; a directory without the marker is a stale
|
|
92
|
+
// partial cache and is replaced.
|
|
93
|
+
async function publish(
|
|
94
|
+
staging: string,
|
|
95
|
+
dir: string,
|
|
96
|
+
marker: string,
|
|
97
|
+
retry = true,
|
|
98
|
+
): Promise<void> {
|
|
99
|
+
try {
|
|
100
|
+
await fs.promises.rename(staging, dir);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (fs.existsSync(marker)) return;
|
|
103
|
+
if (!retry) throw error;
|
|
104
|
+
await fs.promises.rm(dir, { recursive: true, force: true });
|
|
105
|
+
await publish(staging, dir, marker, false);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const abortable = <T>(
|
|
2
|
+
promise: Promise<T>,
|
|
3
|
+
signal: AbortSignal,
|
|
4
|
+
): Promise<T> =>
|
|
5
|
+
new Promise((resolve, reject) => {
|
|
6
|
+
const abort = () => reject(signal.reason);
|
|
7
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
8
|
+
if (signal.aborted) abort();
|
|
9
|
+
promise.then(resolve, reject).finally(() => {
|
|
10
|
+
signal.removeEventListener("abort", abort);
|
|
11
|
+
});
|
|
12
|
+
});
|