osdy-pi 0.1.9 → 1.3.0

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.
Files changed (50) hide show
  1. package/README.md +333 -155
  2. package/bin/osdy-pi.mjs +150 -0
  3. package/bin/osdy.mjs +43 -0
  4. package/extensions/osdy-pi/account-profiles.test.ts +531 -0
  5. package/extensions/osdy-pi/account-profiles.ts +510 -0
  6. package/extensions/osdy-pi/animation.test.ts +84 -0
  7. package/extensions/osdy-pi/animation.ts +62 -11
  8. package/extensions/osdy-pi/codex-usage-ui.test.ts +1145 -0
  9. package/extensions/osdy-pi/codex-usage-ui.ts +728 -0
  10. package/extensions/osdy-pi/codex-usage.test.ts +276 -0
  11. package/extensions/osdy-pi/codex-usage.ts +276 -0
  12. package/extensions/osdy-pi/constants.ts +412 -133
  13. package/extensions/osdy-pi/context-usage-ui.test.ts +168 -0
  14. package/extensions/osdy-pi/context-usage-ui.ts +60 -0
  15. package/extensions/osdy-pi/diff-panel.ts +6 -14
  16. package/extensions/osdy-pi/editor-settings.test.ts +261 -0
  17. package/extensions/osdy-pi/editor-settings.ts +148 -0
  18. package/extensions/osdy-pi/metrics.test.ts +95 -0
  19. package/extensions/osdy-pi/metrics.ts +47 -136
  20. package/extensions/osdy-pi/plugin-events.ts +26 -0
  21. package/extensions/osdy-pi/profile-label.ts +29 -0
  22. package/extensions/osdy-pi/runtime-helpers.test.ts +245 -0
  23. package/extensions/osdy-pi/runtime-helpers.ts +117 -51
  24. package/extensions/osdy-pi/runtime.test.ts +410 -0
  25. package/extensions/osdy-pi/runtime.ts +557 -87
  26. package/extensions/osdy-pi/types.ts +59 -11
  27. package/extensions/osdy-pi/ui.test.ts +179 -0
  28. package/extensions/osdy-pi/ui.ts +323 -122
  29. package/extensions/osdy-pi/utils.ts +43 -1
  30. package/extensions/osdy-pi/working-tree.ts +25 -6
  31. package/package.json +25 -5
  32. package/scripts/osdy-pi-account-profiles.mjs +946 -0
  33. package/scripts/osdy-pi-gentle-coexistence.mjs +200 -0
  34. package/scripts/osdy-pi-profile-setup.mjs +175 -0
  35. package/themes/osdy-pi-catppuccin-frappe.json +98 -0
  36. package/themes/osdy-pi-catppuccin-latte.json +98 -0
  37. package/themes/osdy-pi-catppuccin-macchiato.json +98 -0
  38. package/themes/osdy-pi-catppuccin-mocha.json +98 -0
  39. package/themes/osdy-pi-dark.json +6 -8
  40. package/themes/osdy-pi-dracula.json +87 -0
  41. package/themes/osdy-pi-kanagawa-dragon.json +95 -0
  42. package/themes/osdy-pi-kanagawa-lotus.json +96 -0
  43. package/themes/osdy-pi-kanagawa-wave.json +95 -0
  44. package/themes/osdy-pi-lucent-orange.json +84 -0
  45. package/themes/osdy-pi-matrix.json +87 -0
  46. package/themes/osdy-pi-new.json +95 -0
  47. package/themes/osdy-pi-sexy.json +88 -0
  48. package/themes/osdy-pi-tokyo-night.json +87 -0
  49. package/themes/osdy-pi-light.json +0 -84
  50. package/themes/osdy-pi-simple.json +0 -83
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+ import { homedir } from "node:os";
4
+ import { dirname, join, resolve } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { setupOsdyProfile } from "../scripts/osdy-pi-profile-setup.mjs";
7
+ import { configureGentleCoexistence } from "../scripts/osdy-pi-gentle-coexistence.mjs";
8
+ import {
9
+ clearDefaultAccount,
10
+ ensureProfileLayout,
11
+ getSharedAgentDir,
12
+ listProfiles,
13
+ parseAccountCommand,
14
+ planDefaultLaunch,
15
+ planPiLaunch,
16
+ readDefaultAccount,
17
+ removeProfile,
18
+ renameProfile,
19
+ setDefaultAccount,
20
+ switchAccountAuth,
21
+ } from "../scripts/osdy-pi-account-profiles.mjs";
22
+
23
+ function writeStdout(message) {
24
+ process.stdout.write(`${message}\n`);
25
+ }
26
+
27
+ function writeStderr(message) {
28
+ process.stderr.write(`${message}\n`);
29
+ }
30
+
31
+ function printUsage() {
32
+ writeStderr(
33
+ "Usage: osdy-pi setup | gentle setup <absolute-source-path> | account list | create <name> | add <name> | rename <old> <new> | remove <name> --confirm <name> [--replacement <other>] | use <name> [-- <pi args...] | default [<name> | --clear]",
34
+ );
35
+ }
36
+
37
+ function boundedMessage(error) {
38
+ const message =
39
+ error instanceof Error ? error.message : "Unable to manage Osdy Pi accounts.";
40
+ return message.slice(0, 240);
41
+ }
42
+
43
+ function sendLauncherMessage(message) {
44
+ if (typeof process.send === "function") process.send(message);
45
+ }
46
+
47
+ function reportLauncherFailure(error) {
48
+ const message = boundedMessage(error);
49
+ sendLauncherMessage({ type: "osdy-pi-error", message });
50
+ writeStderr(message);
51
+ }
52
+
53
+ function startPi(plan) {
54
+ const child = spawn(plan.command, plan.args, {
55
+ stdio: "inherit",
56
+ env: { ...process.env, ...plan.env },
57
+ });
58
+ child.once("spawn", () => {
59
+ sendLauncherMessage({ type: "osdy-pi-ready" });
60
+ });
61
+ child.on("error", (error) => {
62
+ reportLauncherFailure(new Error(`Failed to start Pi: ${error.message}`));
63
+ process.exitCode = 1;
64
+ });
65
+ child.on("exit", (code, signal) => {
66
+ if (signal) process.kill(process.pid, signal);
67
+ else process.exitCode = code ?? 1;
68
+ });
69
+ }
70
+
71
+ try {
72
+ const args = process.argv.slice(2);
73
+ if (args[0] === "setup") {
74
+ if (args.length !== 1) throw new Error("Usage: osdy-pi setup");
75
+ const home = homedir();
76
+ const result = await setupOsdyProfile({
77
+ officialDir: process.env.OSDY_PI_SOURCE_AGENT_DIR || join(home, ".pi", "agent"),
78
+ profileDir: process.env.OSDY_PI_AGENT_DIR || join(home, ".pi", "osdy-agent"),
79
+ osdyRoot: process.env.OSDY_PI_EXTENSION_ROOT || resolve(dirname(fileURLToPath(import.meta.url)), ".."),
80
+ gentleRoot: process.env.GENTLE_PI_EXTENSION_ROOT || undefined,
81
+ });
82
+ writeStdout(`Isolated Osdy profile ${result.status}: ${result.profileDir}`);
83
+ } else if (args[0] === "gentle") {
84
+ if (args[1] !== "setup" || args.length !== 3)
85
+ throw new Error("Usage: osdy-pi gentle setup <absolute-source-path>");
86
+ const result = await configureGentleCoexistence(args[2]);
87
+ writeStdout(
88
+ `Gentle coexistence ${result.status}. Restart Pi or run /reload to apply it.`,
89
+ );
90
+ } else if (args.length === 0) {
91
+ const sharedAgentDir = getSharedAgentDir();
92
+ const result = await planDefaultLaunch(sharedAgentDir);
93
+ if (result.defaultAccount.status === "invalid")
94
+ writeStderr("Ignoring invalid Osdy Pi default account metadata.");
95
+ startPi(result.plan);
96
+ } else {
97
+ const sharedAgentDir = getSharedAgentDir();
98
+ const command = parseAccountCommand(args);
99
+ if (command.action === "list") {
100
+ const profiles = await listProfiles(sharedAgentDir);
101
+ if (profiles.length === 0)
102
+ writeStdout(
103
+ "No Osdy Pi accounts. Add one with: osdy-pi account add <name>",
104
+ );
105
+ else writeStdout(profiles.join("\n"));
106
+ } else if (command.action === "default") {
107
+ if (command.operation === "query") {
108
+ const account = await readDefaultAccount(sharedAgentDir);
109
+ if (account.status === "valid") writeStdout(account.profile);
110
+ else if (account.status === "unset") writeStdout("No default account.");
111
+ else
112
+ writeStdout("Default account metadata is invalid; no account selected.");
113
+ } else if (command.operation === "clear") {
114
+ await clearDefaultAccount(sharedAgentDir);
115
+ writeStdout("Default account cleared.");
116
+ } else {
117
+ await setDefaultAccount(sharedAgentDir, command.name);
118
+ writeStdout(`Default account set to ${command.name}.`);
119
+ }
120
+ } else if (command.action === "create") {
121
+ await ensureProfileLayout(sharedAgentDir, command.name);
122
+ writeStdout(
123
+ "Account profile created. Use /osdy-account Switch, then run /login and select ChatGPT Plus/Pro (Codex).",
124
+ );
125
+ } else if (command.action === "add") {
126
+ await ensureProfileLayout(sharedAgentDir, command.name);
127
+ writeStdout(
128
+ "Account profile is ready. In Pi, run /login and select ChatGPT Plus/Pro (Codex).",
129
+ );
130
+ await switchAccountAuth(sharedAgentDir, command.name);
131
+ startPi(planPiLaunch(sharedAgentDir, command.name));
132
+ } else if (command.action === "rename") {
133
+ await renameProfile(sharedAgentDir, command.oldName, command.newName);
134
+ writeStdout(`Account profile renamed to ${command.newName}.`);
135
+ } else if (command.action === "remove") {
136
+ await removeProfile(sharedAgentDir, command.name, {
137
+ confirmation: command.name,
138
+ replacement: command.replacement,
139
+ });
140
+ writeStdout(`Account profile ${command.name} permanently removed.`);
141
+ } else {
142
+ await switchAccountAuth(sharedAgentDir, command.name);
143
+ startPi(planPiLaunch(sharedAgentDir, command.name, command.piArgs));
144
+ }
145
+ }
146
+ } catch (error) {
147
+ reportLauncherFailure(error);
148
+ printUsage();
149
+ process.exitCode = 1;
150
+ }
package/bin/osdy.mjs ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ /* global process, console */
3
+ import { spawn } from "node:child_process";
4
+ import { constants as osConstants, homedir } from "node:os";
5
+ import { dirname, join, resolve } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ import { setupOsdyProfile } from "../scripts/osdy-pi-profile-setup.mjs";
8
+
9
+ const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
10
+ const home = homedir();
11
+ const officialDir = process.env.OSDY_PI_SOURCE_AGENT_DIR || join(home, ".pi", "agent");
12
+ const profileDir = process.env.OSDY_PI_AGENT_DIR || join(home, ".pi", "osdy-agent");
13
+ const osdyRoot = process.env.OSDY_PI_EXTENSION_ROOT || packageRoot;
14
+ const gentleRoot = process.env.GENTLE_PI_EXTENSION_ROOT || undefined;
15
+
16
+ try {
17
+ if (process.argv[2] === "setup" && process.argv.length !== 3)
18
+ throw new Error("Usage: osdy setup");
19
+ const result = await setupOsdyProfile({ officialDir, profileDir, osdyRoot, gentleRoot });
20
+ if (process.argv[2] === "setup") {
21
+ console.log(`Isolated Osdy profile ${result.status}: ${result.profileDir}`);
22
+ } else {
23
+ const child = spawn("pi", process.argv.slice(2), {
24
+ stdio: "inherit",
25
+ env: {
26
+ ...process.env,
27
+ PI_CODING_AGENT_DIR: result.profileDir,
28
+ OSDY_PI_DEV_EXTENSION_ROOT: osdyRoot,
29
+ },
30
+ });
31
+ child.on("error", (error) => {
32
+ console.error(`osdy: Could not launch installed pi from PATH: ${error.message}`);
33
+ process.exitCode = 1;
34
+ });
35
+ child.on("exit", (code, signal) => {
36
+ if (signal) process.exitCode = 128 + (osConstants.signals[signal] ?? 1);
37
+ else process.exitCode = code ?? 1;
38
+ });
39
+ }
40
+ } catch (error) {
41
+ console.error(`osdy: ${error instanceof Error ? error.message : String(error)}`);
42
+ process.exitCode = 1;
43
+ }