@userreason/wizard 0.1.0 → 0.2.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 +116 -28
- package/dist/THIRD_PARTY_NOTICES.txt +488 -0
- package/dist/agent-note.js +17 -0
- package/dist/agent-skill.js +16 -0
- package/dist/bin.js +720 -689
- package/dist/chunk-3RDJORRS.js +153 -0
- package/dist/chunk-5SC2K42Q.js +899 -0
- package/dist/chunk-5Z5J6PY5.js +258 -0
- package/dist/chunk-6CJ4ANMN.js +70 -0
- package/dist/chunk-GGARVSPT.js +211893 -0
- package/dist/chunk-HACTNBV3.js +51 -0
- package/dist/chunk-JD5U4U26.js +125 -0
- package/dist/chunk-OEGNGGZ2.js +7403 -0
- package/dist/chunk-SJVLAYGG.js +1477 -0
- package/dist/chunk-ULHKVBPD.js +165 -0
- package/dist/chunk-WL3NOIM6.js +42 -0
- package/dist/chunk-YMSGDC4B.js +280 -0
- package/dist/chunk-ZGZOBW2B.js +115 -0
- package/dist/cli-access.js +10 -0
- package/dist/connection.js +18 -0
- package/dist/global-cli.js +14 -0
- package/dist/integrate.js +21 -0
- package/dist/project.js +35 -101
- package/dist/registry.js +8 -0
- package/dist/skills/userreason/SKILL.md +55 -0
- package/dist/skills/userreason/references/management.md +61 -0
- package/dist/startup.js +11 -0
- package/dist/state.js +18 -0
- package/dist/ui.js +23 -0
- package/package.json +7 -17
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createRequire as createWizardRequire } from 'node:module'; import { fileURLToPath as wizardFileURLToPath } from 'node:url'; import { dirname as wizardDirname } from 'node:path'; const require = createWizardRequire(import.meta.url); const __filename = wizardFileURLToPath(import.meta.url); const __dirname = wizardDirname(__filename);
|
|
2
|
+
import {
|
|
3
|
+
Cancelled,
|
|
4
|
+
openBrowser
|
|
5
|
+
} from "./chunk-SJVLAYGG.js";
|
|
6
|
+
import {
|
|
7
|
+
authorizeCli,
|
|
8
|
+
grantSummary,
|
|
9
|
+
printable,
|
|
10
|
+
resolveCredentials,
|
|
11
|
+
saveConfig
|
|
12
|
+
} from "./chunk-GGARVSPT.js";
|
|
13
|
+
|
|
14
|
+
// src/cli-access.ts
|
|
15
|
+
async function offerCliAccess(config, terminal, options) {
|
|
16
|
+
if (!options.installed || options.skip || !terminal.interactive && !options.requested) return { status: "skipped" };
|
|
17
|
+
if (options.preview !== false) terminal.note("Connect the project CLI for ongoing work. The browser lets you choose workspaces and permissions; all current and future workspaces and available permissions are selected initially. Your workspace role still limits every action. This is separate from the short installation approval.", "Ongoing CLI access");
|
|
18
|
+
let waiting;
|
|
19
|
+
try {
|
|
20
|
+
if (!options.requested && !await terminal.confirm("Connect the CLI for ongoing use?", true, { recommended: true })) return { status: "declined" };
|
|
21
|
+
let signedIn = false;
|
|
22
|
+
const show = async (url, label, previous) => {
|
|
23
|
+
const opened = !options.noOpen && await openBrowser(url);
|
|
24
|
+
waiting?.stop(previous);
|
|
25
|
+
waiting = terminal.waiting(label, opened ? {} : { link: url });
|
|
26
|
+
};
|
|
27
|
+
const result = await authorizeCli(config, resolveCredentials(config), {
|
|
28
|
+
onDevice: (device) => {
|
|
29
|
+
signedIn = true;
|
|
30
|
+
return show(device.verificationUriComplete, `Sign in for the CLI ${terminal.kit.S.dot} ${terminal.kit.c.muted("code")} ${terminal.kit.c.code(device.userCode)}`);
|
|
31
|
+
},
|
|
32
|
+
onApproval: (request) => show(request.approval_url, "Review and approve CLI access in the browser", signedIn ? "Signed in" : void 0)
|
|
33
|
+
});
|
|
34
|
+
waiting?.stop();
|
|
35
|
+
await saveConfig(config, options.development);
|
|
36
|
+
const grant = "grant" in result ? result.grant : void 0;
|
|
37
|
+
const summary = grantSummary(grant);
|
|
38
|
+
terminal.success(`CLI access approved${summary ? ` ${terminal.kit.c.muted(`(${summary})`)}` : ""}`);
|
|
39
|
+
return { status: "approved", grant };
|
|
40
|
+
} catch (error) {
|
|
41
|
+
waiting?.stop();
|
|
42
|
+
if (error instanceof Cancelled) return { status: "declined" };
|
|
43
|
+
if (error instanceof Error) terminal.warn(printable(error.message));
|
|
44
|
+
terminal.warn("The application is installed, but ongoing CLI access was not connected. Run the project CLI with login --open to finish.");
|
|
45
|
+
return { status: "failed" };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
offerCliAccess
|
|
51
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { createRequire as createWizardRequire } from 'node:module'; import { fileURLToPath as wizardFileURLToPath } from 'node:url'; import { dirname as wizardDirname } from 'node:path'; const require = createWizardRequire(import.meta.url); const __filename = wizardFileURLToPath(import.meta.url); const __dirname = wizardDirname(__filename);
|
|
2
|
+
import {
|
|
3
|
+
Cancelled
|
|
4
|
+
} from "./chunk-SJVLAYGG.js";
|
|
5
|
+
import {
|
|
6
|
+
cliCommand,
|
|
7
|
+
compatibleCliVersion
|
|
8
|
+
} from "./chunk-YMSGDC4B.js";
|
|
9
|
+
import {
|
|
10
|
+
packageProfile
|
|
11
|
+
} from "./chunk-GGARVSPT.js";
|
|
12
|
+
|
|
13
|
+
// src/global-cli.ts
|
|
14
|
+
import { execFile } from "node:child_process";
|
|
15
|
+
import { constants } from "node:fs";
|
|
16
|
+
import { access, mkdtemp, readFile, realpath, rm } from "node:fs/promises";
|
|
17
|
+
import { delimiter, dirname, join, resolve } from "node:path";
|
|
18
|
+
import { promisify } from "node:util";
|
|
19
|
+
var run = promisify(execFile);
|
|
20
|
+
var registry = (profile) => profile.kind === "local-development" ? profile.registry : "https://registry.npmjs.org";
|
|
21
|
+
var registryArgs = (profile) => [`--registry=${registry(profile)}`, `--@userreason:registry=${registry(profile)}`];
|
|
22
|
+
var installArgs = (profile) => ["install", "--global", "--ignore-scripts", `@userreason/cli@${profile.cliVersion}`, ...registryArgs(profile)];
|
|
23
|
+
function globalCliInstallCommand(profile = packageProfile()) {
|
|
24
|
+
return ["npm", ...installArgs(profile)].join(" ");
|
|
25
|
+
}
|
|
26
|
+
async function installedCli(directory) {
|
|
27
|
+
const { stdout } = await run("npm", ["root", "--global"], { cwd: directory, timeout: 15e3, maxBuffer: 64e3 });
|
|
28
|
+
const root = stdout.trim();
|
|
29
|
+
if (!root) throw new Error("npm did not report its global package directory.");
|
|
30
|
+
try {
|
|
31
|
+
const manifest = JSON.parse(await readFile(join(root, "@userreason/cli/package.json"), "utf8"));
|
|
32
|
+
if (manifest.name !== "@userreason/cli" || typeof manifest.version !== "string") throw new Error("Invalid global CLI package.");
|
|
33
|
+
return { root, version: manifest.version };
|
|
34
|
+
} catch (error) {
|
|
35
|
+
if (error.code === "ENOENT") return void 0;
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function commandAvailable(root, projectDirectory) {
|
|
40
|
+
const windows = process.platform === "win32";
|
|
41
|
+
const expected = await realpath(windows ? join(dirname(root), "userreason.cmd") : join(root, "@userreason/cli/dist/bin.js"));
|
|
42
|
+
let projectCommand;
|
|
43
|
+
try {
|
|
44
|
+
projectCommand = await realpath(join(projectDirectory, windows ? "node_modules/.bin/userreason.cmd" : "node_modules/@userreason/cli/dist/bin.js"));
|
|
45
|
+
} catch {
|
|
46
|
+
}
|
|
47
|
+
const names = windows ? ["userreason.com", "userreason.exe", "userreason.bat", "userreason.cmd"] : ["userreason"];
|
|
48
|
+
for (const directory of (process.env.PATH ?? "").split(delimiter)) {
|
|
49
|
+
if (!directory || resolve(directory) !== directory) continue;
|
|
50
|
+
for (const name of names) {
|
|
51
|
+
const candidate = join(directory, name);
|
|
52
|
+
try {
|
|
53
|
+
await access(candidate, windows ? constants.F_OK : constants.X_OK);
|
|
54
|
+
const target = await realpath(candidate);
|
|
55
|
+
if (target === projectCommand) continue;
|
|
56
|
+
return target === expected;
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
async function offerGlobalCli(project, terminal, options) {
|
|
64
|
+
if (!options.installed || options.skip || !terminal.interactive && !options.requested) return { status: "skipped" };
|
|
65
|
+
const profile = options.profile ?? packageProfile();
|
|
66
|
+
const command = globalCliInstallCommand(profile);
|
|
67
|
+
if (options.preview !== false) terminal.note(`Make the userreason command available across your projects. The project keeps its own CLI for teammates and agents.${profile.kind === "local-development" ? `
|
|
68
|
+
This installs development CLI ${profile.cliVersion} from ${profile.registry}, replacing the CLI in npm's current global prefix. Its default API and documentation are development.` : ""}`, "Optional global CLI");
|
|
69
|
+
let cache;
|
|
70
|
+
try {
|
|
71
|
+
if (!options.requested && !await terminal.confirm("Make userreason available across your projects?", true)) return { status: "declined" };
|
|
72
|
+
let installed = await installedCli(project.directory);
|
|
73
|
+
const reuse = installed && compatibleCliVersion(installed.version, profile) && !options.force;
|
|
74
|
+
if (!reuse) {
|
|
75
|
+
cache = await mkdtemp(join(await realpath(project.directory), ".userreason-npm-"));
|
|
76
|
+
await terminal.task("Installing the global UserReason CLI", async () => {
|
|
77
|
+
try {
|
|
78
|
+
const child = run("npm", [...installArgs(profile), "--cache", cache], {
|
|
79
|
+
cwd: project.directory,
|
|
80
|
+
timeout: 12e4,
|
|
81
|
+
maxBuffer: 4e6,
|
|
82
|
+
env: { ...process.env, npm_config_cache: cache, NPM_CONFIG_CACHE: cache, npm_config_ignore_scripts: "true" }
|
|
83
|
+
});
|
|
84
|
+
if (options.verbose) {
|
|
85
|
+
child.child.stdout?.on("data", (chunk) => process.stderr.write(chunk));
|
|
86
|
+
child.child.stderr?.on("data", (chunk) => process.stderr.write(chunk));
|
|
87
|
+
}
|
|
88
|
+
await child;
|
|
89
|
+
} catch {
|
|
90
|
+
throw new Error("Global CLI installation failed. Check npm permissions or rerun with --debug; project setup is complete.");
|
|
91
|
+
}
|
|
92
|
+
}, "Global CLI installed");
|
|
93
|
+
installed = await installedCli(project.directory);
|
|
94
|
+
}
|
|
95
|
+
if (!installed || !compatibleCliVersion(installed.version, profile)) throw new Error("npm did not install the required global CLI version.");
|
|
96
|
+
let available = false;
|
|
97
|
+
try {
|
|
98
|
+
available = await commandAvailable(installed.root, project.directory);
|
|
99
|
+
} catch {
|
|
100
|
+
}
|
|
101
|
+
if (reuse) terminal.success(`Global CLI ${installed.version} is already installed`);
|
|
102
|
+
if (!available) terminal.warn(`Global CLI ${installed.version} is installed, but this terminal does not resolve userreason to it. Check npm's global bin directory in PATH and restart your terminal or agent. Use ${cliCommand(project)} in this project meanwhile.`);
|
|
103
|
+
return { status: reuse ? "already_present" : "installed", version: installed.version, command_available: available };
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (error instanceof Cancelled) return { status: "declined" };
|
|
106
|
+
terminal.warn(`The optional global CLI could not be set up. ${error instanceof Error ? error.message : ""}`);
|
|
107
|
+
terminal.note(`${command}
|
|
108
|
+
|
|
109
|
+
The project CLI remains available: ${cliCommand(project)}`, "Install globally later");
|
|
110
|
+
return { status: "failed", install_command: command };
|
|
111
|
+
} finally {
|
|
112
|
+
if (cache) {
|
|
113
|
+
try {
|
|
114
|
+
await rm(cache, { recursive: true, force: true });
|
|
115
|
+
} catch {
|
|
116
|
+
terminal.warn("Unable to remove the temporary .userreason-npm-* cache inside your project.");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export {
|
|
123
|
+
globalCliInstallCommand,
|
|
124
|
+
offerGlobalCli
|
|
125
|
+
};
|