@namiml/cli 3.4.11-dev.202609222238 → 3.4.11-dev.202609230009

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/dist/cli.js CHANGED
@@ -11,6 +11,7 @@ import { apps } from "./commands/apps.js";
11
11
  import { platforms } from "./commands/platforms.js";
12
12
  import { shell } from "./commands/shell.js";
13
13
  import { configure } from "./commands/configure.js";
14
+ import { use } from "./commands/use.js";
14
15
  import { config } from "./commands/config.js";
15
16
  import { onboarding } from "./commands/onboarding.js";
16
17
  import { devices } from "./commands/devices.js";
@@ -23,6 +24,7 @@ const program = createProgram({
23
24
  apps: async (opts) => apps(opts, await buildContext(opts.host)),
24
25
  platforms: async (opts) => platforms(opts, await buildContext(opts.host)),
25
26
  configure: async (opts) => configure(opts, await buildContext(opts.host)),
27
+ use: async (opts) => use(opts, await buildContext(opts.host)),
26
28
  config: async (opts) => config(opts, await buildContext(opts.host)),
27
29
  onboarding: async (opts) => onboarding(opts, await buildContext(opts.host)),
28
30
  devices: async (opts) => devices(opts, await buildContext(opts.host)),
@@ -0,0 +1,131 @@
1
+ import { AuthError } from "../auth/errors.js";
2
+ import { listApps } from "../control-center/apps.js";
3
+ import { listPlatforms } from "../control-center/platforms.js";
4
+ import { findAppPlatformById, pastedStandIn } from "../control-center/lookup.js";
5
+ import { findApp, findPlatform, resolve, ResolveError } from "../control-center/resolve.js";
6
+ import { appFrom, platformFrom, selectionFrom } from "../config/selection.js";
7
+ import { resolveDevice, toSelection } from "../devices/presets.js";
8
+ import { verifyAppPlatform, VerifyError } from "../sdk/verify.js";
9
+ const NOT_SIGNED_IN = "Not signed in. Run `nami login` first.";
10
+ const NO_FLAGS = "nami use needs one of --org, --app, --platform, --app-platform-id or --device. Run nami for the interactive picker.";
11
+ const NO_CURRENT_APP = "No app selected yet. Pass --app too, or run nami once.";
12
+ const summary = (s) => {
13
+ const device = s.device ? ` · ${s.device.displayName}` : "";
14
+ return `Now using ${s.appName} · ${s.platformName} (${s.platformType})${device}`;
15
+ };
16
+ /** `nami use` — record and validate a selection (org, app, platform, app-platform-id or device). Never runs the SDK. */
17
+ export async function use(opts, ctx, deps = {}) {
18
+ const verify = deps.verify ?? verifyAppPlatform;
19
+ const doListApps = deps.listApps ?? listApps;
20
+ const doListPlatforms = deps.listPlatforms ?? listPlatforms;
21
+ if (!opts.org && !opts.app && !opts.platform && !opts.appPlatformId && !opts.device) {
22
+ ctx.err(NO_FLAGS);
23
+ return 2;
24
+ }
25
+ try {
26
+ if (opts.org) {
27
+ const stored = await ctx.store.load();
28
+ if (!stored) {
29
+ ctx.err(NOT_SIGNED_IN);
30
+ return 1;
31
+ }
32
+ const profile = await ctx.auth.fetchAccount(stored.accessToken);
33
+ const org = resolve(profile.orgs, opts.org, "organization");
34
+ const accessToken = await ctx.auth.selectOrg(stored.refreshToken, org.id);
35
+ const next = { ...stored, accessToken, orgId: org.id, orgName: org.name, savedAt: new Date().toISOString() };
36
+ await ctx.store.save(next);
37
+ await ctx.config.setSession({ orgId: org.id, orgName: org.name });
38
+ // Apps are org-scoped: a bare --org switch invalidates whatever app/platform was current.
39
+ if (!opts.app && !opts.appPlatformId)
40
+ await ctx.config.clearCurrent();
41
+ if (!opts.app && !opts.platform && !opts.appPlatformId && !opts.device) {
42
+ if (opts.json) {
43
+ const { config } = await ctx.config.load();
44
+ ctx.out(JSON.stringify(config.current, null, 2));
45
+ }
46
+ else {
47
+ ctx.out(`Now using organization ${org.name}.`);
48
+ }
49
+ return 0;
50
+ }
51
+ }
52
+ let app;
53
+ let platform;
54
+ if (opts.appPlatformId) {
55
+ await verify(ctx.host.baseUrl, opts.appPlatformId, deps.fetch ?? globalThis.fetch);
56
+ // The id is verified on a public endpoint; naming it needs a session, so a
57
+ // failed lookup degrades to the stand-ins instead of refusing the switch.
58
+ const named = (await findAppPlatformById(ctx.session, opts.appPlatformId, { listApps: doListApps, listPlatforms: doListPlatforms })) ?? pastedStandIn(opts.appPlatformId);
59
+ app = named.app;
60
+ platform = named.platform;
61
+ }
62
+ else if (opts.app) {
63
+ app = findApp(await doListApps(ctx.session), opts.app);
64
+ const platforms = await doListPlatforms(ctx.session, app.id);
65
+ if (opts.platform) {
66
+ platform = findPlatform(platforms, opts.platform);
67
+ }
68
+ else if (platforms.length === 1) {
69
+ platform = platforms[0];
70
+ }
71
+ else {
72
+ ctx.err(`"${app.name}" has more than one platform: ${platforms.map((p) => p.name).join(", ")}. Pass --platform too.`);
73
+ return 2;
74
+ }
75
+ }
76
+ else if (opts.platform) {
77
+ const { config } = await ctx.config.load();
78
+ if (!config.current) {
79
+ ctx.err(NO_CURRENT_APP);
80
+ return 2;
81
+ }
82
+ app = appFrom(config.current);
83
+ const platforms = await doListPlatforms(ctx.session, app.id);
84
+ platform = findPlatform(platforms, opts.platform);
85
+ }
86
+ else if (opts.device) {
87
+ // --device with no app/platform/app-platform-id targets the current selection.
88
+ const { config } = await ctx.config.load();
89
+ if (!config.current) {
90
+ ctx.err(NO_CURRENT_APP);
91
+ return 2;
92
+ }
93
+ app = appFrom(config.current);
94
+ platform = platformFrom(config.current);
95
+ }
96
+ if (!app || !platform) {
97
+ ctx.err(NO_FLAGS);
98
+ return 2;
99
+ }
100
+ let device = null;
101
+ if (opts.device) {
102
+ const resolved = resolveDevice(platform.type, opts.device);
103
+ device = toSelection(resolved);
104
+ }
105
+ const selection = selectionFrom(app, platform, device);
106
+ const next = await ctx.config.setCurrent(selection, { host: ctx.host.name });
107
+ if (opts.json) {
108
+ ctx.out(JSON.stringify(next.current, null, 2));
109
+ }
110
+ else {
111
+ ctx.out(summary(selection));
112
+ ctx.out(`App Platform ID ${selection.appPlatformId} · ${ctx.host.name}`);
113
+ }
114
+ return 0;
115
+ }
116
+ catch (error) {
117
+ if (error instanceof ResolveError) {
118
+ ctx.err(error.message);
119
+ return 2;
120
+ }
121
+ if (error instanceof VerifyError) {
122
+ ctx.err(error.message);
123
+ return error.code === "invalid_id" ? 2 : 1;
124
+ }
125
+ if (error instanceof AuthError) {
126
+ ctx.err(error.message);
127
+ return 1;
128
+ }
129
+ throw error;
130
+ }
131
+ }
@@ -30,7 +30,8 @@ function assertNoCredentials(value, path = "config") {
30
30
  }
31
31
  }
32
32
  }
33
- const recentKey = (s) => `${s.appPlatformId}::${s.device?.id ?? ""}`;
33
+ /** Identity of a selection in `recent`: the platform plus the device it was used on. */
34
+ export const recentKey = (s) => `${s.appPlatformId}::${s.device?.id ?? ""}`;
34
35
  /** Upgrade older shapes; unknown versions fall back to defaults (with a warning from load()). */
35
36
  export function migrate(raw) {
36
37
  if (!raw || typeof raw !== "object")
@@ -111,6 +112,24 @@ export class ConfigStore {
111
112
  return next;
112
113
  });
113
114
  }
115
+ /** Forget the active selection (e.g. after switching org); `recent` is untouched. */
116
+ clearCurrent() {
117
+ return this.enqueue(async () => {
118
+ const { config } = await this.load();
119
+ const next = { ...config, current: null };
120
+ await this.save(next);
121
+ return next;
122
+ });
123
+ }
124
+ /** Replace the session block (org context) only. */
125
+ setSession(session) {
126
+ return this.enqueue(async () => {
127
+ const { config } = await this.load();
128
+ const next = { ...config, session };
129
+ await this.save(next);
130
+ return next;
131
+ });
132
+ }
114
133
  setOnboardingStep(step) {
115
134
  return this.enqueue(async () => {
116
135
  const { config } = await this.load();
@@ -0,0 +1,42 @@
1
+ import { listApps } from "./apps.js";
2
+ import { listPlatforms, platformTypeLabel } from "./platforms.js";
3
+ /**
4
+ * Find the app and platform behind an App Platform ID.
5
+ *
6
+ * There is no "platform by id" endpoint in this client, so this walks the apps
7
+ * the session can see. Naming is a convenience on top of the public verify
8
+ * call: any failure (signed out, another org's id, an unreachable list) returns
9
+ * null so the caller can fall back to `pastedStandIn` rather than refuse a valid id.
10
+ */
11
+ export async function findAppPlatformById(session, appPlatformId, deps = {}) {
12
+ const apps = deps.listApps ?? listApps;
13
+ const platforms = deps.listPlatforms ?? listPlatforms;
14
+ try {
15
+ for (const app of await apps(session)) {
16
+ const platform = (await platforms(session, app.id)).find((p) => p.id === appPlatformId);
17
+ if (platform)
18
+ return { app, platform };
19
+ }
20
+ }
21
+ catch {
22
+ // Naming is optional; the id itself was already verified.
23
+ }
24
+ return null;
25
+ }
26
+ /** What an unnamed App Platform ID looks like until the device step narrows it down. */
27
+ export function pastedStandIn(appPlatformId) {
28
+ return {
29
+ app: { id: appPlatformId, name: "Pasted ID", archived: false, defaultLanguage: null, logo: null },
30
+ platform: {
31
+ id: appPlatformId,
32
+ appId: null,
33
+ name: "App Platform",
34
+ type: "web",
35
+ typeLabel: platformTypeLabel("web"),
36
+ sdkEnabled: true,
37
+ isConfigValid: true,
38
+ archived: false,
39
+ marketplaceAppId: null,
40
+ },
41
+ };
42
+ }
package/dist/program.js CHANGED
@@ -79,6 +79,19 @@ export function createProgram(h, options = {}) {
79
79
  .action(async (_opts, cmd) => {
80
80
  process.exitCode = await h.configure(cmd.optsWithGlobals());
81
81
  });
82
+ program
83
+ .command("use")
84
+ .description("Switch the current organization, app, app platform or device (headless).")
85
+ .option("--org <id-or-name>", "switch organization (re-scopes the access token; clears the current selection)")
86
+ .option("--app <id-or-name>", "app id, exact name, or unique substring")
87
+ .option("--platform <id-or-name>", "platform id, exact name, or unique substring")
88
+ .option("--app-platform-id <uuid>", "select by App Platform ID directly")
89
+ .option("--device <id-or-name>", "target device preset, previewer id or name")
90
+ .option(HOST_FLAG, HOST_HELP)
91
+ .option("--json", "machine-readable result")
92
+ .action(async (_opts, cmd) => {
93
+ process.exitCode = await h.use(cmd.optsWithGlobals());
94
+ });
82
95
  program
83
96
  .command("devices")
84
97
  .description("List the target device presets and the full previewer device list for a platform type.")
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Box, Text } from "ink";
3
+ import { SelectList } from "../components/SelectList.js";
4
+ export function PickOrg({ orgs, currentOrgId, onSelect, onCancel }) {
5
+ if (orgs.length === 0) {
6
+ return (_jsx(Box, { flexDirection: "column", children: _jsx(Text, { bold: true, children: "Your account does not belong to any organization yet." }) }));
7
+ }
8
+ return (_jsx(SelectList, { title: "Choose an organization", items: orgs.map((o) => ({ key: o.id, label: o.name })), initialKey: currentOrgId ?? undefined, onSelect: (key) => { const org = orgs.find((o) => o.id === key); if (org)
9
+ onSelect(org); }, onCancel: onCancel }));
10
+ }
@@ -5,6 +5,8 @@ import { LoginFlow } from "./LoginFlow.js";
5
5
  import { PickApp } from "./PickApp.js";
6
6
  import { PickPlatform } from "./PickPlatform.js";
7
7
  import { PickDevice } from "./PickDevice.js";
8
+ import { PickOrg } from "./PickOrg.js";
9
+ import { SwitchScreen } from "./SwitchScreen.js";
8
10
  import { SuccessScreen } from "./SuccessScreen.js";
9
11
  import { deviceById, presetsFor, resolveDevice, toSelection } from "../devices/presets.js";
10
12
  import { SelectionHeader } from "./SelectionHeader.js";
@@ -14,12 +16,17 @@ import { AuthError } from "../auth/errors.js";
14
16
  import { listApps } from "../control-center/apps.js";
15
17
  import { listPlatforms } from "../control-center/platforms.js";
16
18
  import { findApp, findPlatform, ResolveError } from "../control-center/resolve.js";
19
+ import { findAppPlatformById, pastedStandIn } from "../control-center/lookup.js";
17
20
  import { ConfigureScreen } from "./ConfigureScreen.js";
18
21
  import { appFrom, platformFrom, selectionFrom } from "../config/selection.js";
22
+ import { verifyAppPlatform as verifyAppPlatformFn, VerifyError } from "../sdk/verify.js";
23
+ import TextInput from "ink-text-input";
19
24
  /**
20
- * Bare `nami`: sign in if needed → pick app → pick platform → home.
21
- * Selection is in-memory for now (persistence: NAM-4501; configure: NAM-4500;
22
- * full Switch with Recent/org switching: NAM-4503).
25
+ * Bare `nami`: sign in if needed → pick app → platform → device → home.
26
+ * `s` opens the Switch hub, which reaches every axis `nami use` can switch
27
+ * headlessly: a recent selection, app, platform, device, organization, or a
28
+ * pasted App Platform ID. Every path funnels back through `configure`, so the
29
+ * SDK is re-configured in place and each platform keeps its own storage file.
23
30
  */
24
31
  export function Shell({ ctx, appQuery, platformQuery, deviceQuery, onExit, exitWhenDone = true, phase, verify, configure }) {
25
32
  const { exit } = useApp();
@@ -28,6 +35,7 @@ export function Shell({ ctx, appQuery, platformQuery, deviceQuery, onExit, exitW
28
35
  const [orgId, setOrgId] = useState(null);
29
36
  const step = (name) => void ctx.config.setOnboardingStep(name).catch(() => { });
30
37
  const [queries, setQueries] = useState({ app: appQuery, platform: platformQuery, device: deviceQuery });
38
+ const [pasted, setPasted] = useState("");
31
39
  const finish = (code) => {
32
40
  onExit?.(code);
33
41
  if (exitWhenDone)
@@ -62,6 +70,85 @@ export function Shell({ ctx, appQuery, platformQuery, deviceQuery, onExit, exitW
62
70
  }
63
71
  setState({ kind: "pick-device", app, platform, current });
64
72
  };
73
+ /** Open the Switch hub over the current home state; recent/current come from config.json. */
74
+ const openSwitch = async (home) => {
75
+ const { config } = await ctx.config.load();
76
+ setState({ kind: "switch", home, recent: config.recent, current: config.current });
77
+ };
78
+ /** A recent entry is a selection we already know — rebuild it and reconfigure, no network call. */
79
+ const useRecent = (home, selection) => {
80
+ const sameDevice = (selection.device?.id ?? null) === (home.device?.id ?? null);
81
+ if (selection.appPlatformId === home.platform.id && sameDevice)
82
+ return setState(home);
83
+ const device = selection.device ? deviceById(selection.device.id) ?? null : null;
84
+ step("configure");
85
+ setState({ kind: "configure", app: appFrom(selection), platform: platformFrom(selection), device });
86
+ };
87
+ const openOrgs = async (home) => {
88
+ setState({ kind: "busy", label: "Loading your organizations…" });
89
+ try {
90
+ const stored = await ctx.store.load();
91
+ if (!stored)
92
+ return setState({ kind: "signin" });
93
+ const profile = await ctx.auth.fetchAccount(stored.accessToken);
94
+ setState({ kind: "pick-org", home, orgs: profile.orgs });
95
+ }
96
+ catch (error) {
97
+ handleError(error);
98
+ }
99
+ };
100
+ /** Re-scope the token to another org. No re-login; the old selection no longer applies. */
101
+ const switchOrg = async (org) => {
102
+ setState({ kind: "busy", label: `Switching to ${org.name}…` });
103
+ try {
104
+ const stored = await ctx.store.load();
105
+ if (!stored)
106
+ return setState({ kind: "signin" });
107
+ const accessToken = await ctx.auth.selectOrg(stored.refreshToken, org.id);
108
+ await ctx.store.save({ ...stored, accessToken, orgId: org.id, orgName: org.name, savedAt: new Date().toISOString() });
109
+ setOrgName(org.name);
110
+ setOrgId(org.id);
111
+ await ctx.config.clearCurrent().catch(() => { });
112
+ await loadApps();
113
+ }
114
+ catch (error) {
115
+ handleError(error);
116
+ }
117
+ };
118
+ /**
119
+ * A pasted App Platform ID: verify it on the public config endpoint, then find
120
+ * its name by scanning the apps this account can see. An id from another org
121
+ * still works — it just shows as a pasted id until the device step.
122
+ */
123
+ const usePastedId = async (home, raw) => {
124
+ const id = raw.trim();
125
+ if (!id)
126
+ return;
127
+ setState({ kind: "busy", label: "Checking that ID…" });
128
+ try {
129
+ await (verify ?? verifyAppPlatformFn)(ctx.host.baseUrl, id);
130
+ }
131
+ catch (error) {
132
+ if (error instanceof VerifyError)
133
+ return setState({ kind: "paste-id", home, notice: error.message });
134
+ return handleError(error);
135
+ }
136
+ const named = (await findAppPlatformById(ctx.session, id)) ?? pastedStandIn(id);
137
+ chooseDevice(named.app, named.platform);
138
+ };
139
+ const onSwitchChoice = (home, action) => {
140
+ if (action.kind === "recent")
141
+ return useRecent(home, action.selection);
142
+ if (action.kind === "app")
143
+ return void loadApps(home.app);
144
+ if (action.kind === "platform")
145
+ return void loadPlatforms(home.app, home.platform);
146
+ if (action.kind === "device")
147
+ return setState({ kind: "pick-device", app: home.app, platform: home.platform, current: home.device ?? undefined });
148
+ if (action.kind === "org")
149
+ return void openOrgs(home);
150
+ setState({ kind: "paste-id", home });
151
+ };
65
152
  const loadApps = async (current) => {
66
153
  setState({ kind: "busy", label: "Loading your apps…" });
67
154
  try {
@@ -121,13 +208,21 @@ export function Shell({ ctx, appQuery, platformQuery, deviceQuery, onExit, exitW
121
208
  if (state.kind === "fatal")
122
209
  finish(state.code);
123
210
  }, [state.kind]);
211
+ useInput((_input, key) => {
212
+ if (state.kind !== "paste-id")
213
+ return;
214
+ if (key.escape) {
215
+ setPasted("");
216
+ setState(state.home);
217
+ }
218
+ }, { isActive: state.kind === "paste-id" });
124
219
  useInput((input, key) => {
125
220
  if (state.kind !== "home")
126
221
  return;
127
222
  if (input === "q" || key.escape)
128
223
  return finish(0);
129
224
  if (input === "s")
130
- return void loadApps(state.app);
225
+ return void openSwitch(state);
131
226
  if (input === "p")
132
227
  return void loadPlatforms(state.app, state.platform);
133
228
  if (input === "d" && presetsFor(state.platform.type).length > 1)
@@ -135,12 +230,15 @@ export function Shell({ ctx, appQuery, platformQuery, deviceQuery, onExit, exitW
135
230
  if (input === "l")
136
231
  return setState({ ...state, launchHint: true });
137
232
  }, { isActive: state.kind === "home" });
138
- const header = (_jsx(SelectionHeader, { orgName: orgName, appName: "app" in state ? state.app.name : undefined, platformName: "platform" in state ? state.platform.name : undefined, platformType: "platform" in state ? state.platform.typeLabel : undefined, deviceName: "device" in state ? state.device?.displayName : undefined, host: ctx.host.name }));
233
+ // The hub and its sub-screens keep the home state they came from, so the header
234
+ // keeps showing what is loaded while you choose what to switch to.
235
+ const shown = "home" in state ? state.home : "app" in state ? state : {};
236
+ const header = (_jsx(SelectionHeader, { orgName: orgName, appName: shown.app?.name, platformName: shown.platform?.name, platformType: shown.platform?.typeLabel, deviceName: shown.device?.displayName, host: ctx.host.name }));
139
237
  return (_jsxs(Box, { flexDirection: "column", children: [header, _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [state.kind === "boot" && _jsx(Thinking, { label: "Starting\u2026", phase: phase }), state.kind === "signin" && (_jsxs(Box, { flexDirection: "column", children: [state.notice && _jsx(Text, { color: palette.aqua, children: state.notice }), _jsx(LoginFlow, { auth: ctx.auth, store: ctx.store, host: ctx.host, exitWhenDone: false, phase: phase, onDone: (session) => { setOrgName(session.orgName); setOrgId(session.orgId); void loadApps(); }, onFail: (e) => fatal(e.message) })] })), state.kind === "busy" && _jsx(Thinking, { label: state.label, phase: phase }), state.kind === "pick-app" && (_jsx(PickApp, { apps: state.apps, orgName: orgName, baseUrl: ctx.host.baseUrl, currentAppId: state.current?.id, onSelect: (app) => void loadPlatforms(app), onCancel: () => finish(0) })), state.kind === "pick-platform" && (_jsx(PickPlatform, { appName: state.app.name, platforms: state.platforms, currentPlatformId: state.current?.id, onSelect: (platform) => chooseDevice(state.app, platform), onCancel: () => void loadApps(state.app) })), state.kind === "pick-device" && (_jsx(PickDevice, { platformType: state.platform.type, platformName: state.platform.name, currentDeviceId: state.current?.id, onSelect: (device) => { step("configure"); setState({ kind: "configure", app: state.app, platform: state.platform, device }); }, onCancel: () => void loadPlatforms(state.app, state.platform) })), state.kind === "configure" && (_jsx(ConfigureScreen, { host: ctx.host, appPlatformId: state.platform.id, device: state.device ? { platformType: state.platform.type, id: state.device.id } : undefined, phase: phase, verify: verify, configure: configure, onDone: (result) => {
140
238
  void ctx.config
141
239
  .setCurrent(selectionFrom(state.app, state.platform, state.device ? toSelection(state.device) : null), { host: ctx.host.name, session: { orgId, orgName } })
142
240
  .then(() => ctx.config.markOnboardingDone())
143
241
  .catch(() => { });
144
242
  setState({ kind: "home", app: state.app, platform: state.platform, device: state.device, result });
145
- }, onBack: () => chooseDevice(state.app, state.platform, state.device ?? undefined) })), state.kind === "home" && (_jsx(SuccessScreen, { app: state.app, platform: state.platform, device: state.device, result: state.result, host: ctx.host, canSwitchDevice: presetsFor(state.platform.type).length > 1, launchHint: state.launchHint })), state.kind === "fatal" && _jsx(Text, { color: palette.coral, children: state.message })] })] }));
243
+ }, onBack: () => chooseDevice(state.app, state.platform, state.device ?? undefined) })), state.kind === "home" && (_jsx(SuccessScreen, { app: state.app, platform: state.platform, device: state.device, result: state.result, host: ctx.host, canSwitchDevice: presetsFor(state.platform.type).length > 1, launchHint: state.launchHint })), state.kind === "switch" && (_jsx(SwitchScreen, { recent: state.recent, current: state.current, orgName: orgName, canSwitchDevice: presetsFor(state.home.platform.type).length > 1, canSwitchOrg: true, onChoose: (action) => onSwitchChoice(state.home, action), onCancel: () => setState(state.home) })), state.kind === "pick-org" && (_jsx(PickOrg, { orgs: state.orgs, currentOrgId: orgId, onSelect: (org) => void switchOrg(org), onCancel: () => setState(state.home) })), state.kind === "paste-id" && (_jsxs(Box, { flexDirection: "column", children: [state.notice && _jsx(Text, { color: palette.coral, children: state.notice }), _jsxs(Box, { children: [_jsx(Text, { children: "App Platform ID: " }), _jsx(TextInput, { value: pasted, onChange: setPasted, onSubmit: (v) => { setPasted(""); void usePastedId(state.home, v); } })] }), _jsx(Text, { dimColor: true, children: "nami platforms --app <app> lists them. Esc to go back." })] })), state.kind === "fatal" && _jsx(Text, { color: palette.coral, children: state.message })] })] }));
146
244
  }
@@ -0,0 +1,46 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Text } from "ink";
3
+ import { SelectList } from "../components/SelectList.js";
4
+ import { recentKey as selectionKey } from "../config/store.js";
5
+ /** `recent:` + `ConfigStore`'s own de-dup key, so the two can never drift apart. */
6
+ const recentKey = (s) => `recent:${selectionKey(s)}`;
7
+ const isCurrent = (s, current) => current !== null && s.appPlatformId === current.appPlatformId && (s.device?.id ?? null) === (current.device?.id ?? null);
8
+ export function switchItems({ recent, current, canSwitchDevice, canSwitchOrg, }) {
9
+ const recentItems = recent.map((s) => {
10
+ const hintParts = [s.device?.displayName, isCurrent(s, current) ? "current" : undefined].filter((v) => Boolean(v));
11
+ return {
12
+ key: recentKey(s),
13
+ label: `${s.appName} · ${s.platformName}`,
14
+ badge: s.platformType,
15
+ hint: hintParts.length > 0 ? hintParts.join(" · ") : undefined,
16
+ };
17
+ });
18
+ const actionItems = [
19
+ { key: "action:app", label: "Switch app" },
20
+ { key: "action:platform", label: "Switch platform" },
21
+ ...(canSwitchDevice ? [{ key: "action:device", label: "Change device" }] : []),
22
+ ...(canSwitchOrg ? [{ key: "action:org", label: "Change organization" }] : []),
23
+ { key: "action:paste", label: "Paste an App Platform ID" },
24
+ ];
25
+ return [...recentItems, ...actionItems];
26
+ }
27
+ /** The Switch hub: recent selections plus app/platform/device/org/paste actions. Pure — never fetches. */
28
+ export function SwitchScreen({ recent, current, orgName, canSwitchDevice, canSwitchOrg, onChoose, onCancel }) {
29
+ const items = switchItems({ recent, current, canSwitchDevice, canSwitchOrg });
30
+ const handleSelect = (key) => {
31
+ if (key === "action:app")
32
+ return onChoose({ kind: "app" });
33
+ if (key === "action:platform")
34
+ return onChoose({ kind: "platform" });
35
+ if (key === "action:device")
36
+ return onChoose({ kind: "device" });
37
+ if (key === "action:org")
38
+ return onChoose({ kind: "org" });
39
+ if (key === "action:paste")
40
+ return onChoose({ kind: "paste" });
41
+ const selection = recent.find((s) => recentKey(s) === key);
42
+ if (selection)
43
+ onChoose({ kind: "recent", selection });
44
+ };
45
+ return (_jsxs(Box, { flexDirection: "column", children: [orgName && _jsx(Text, { dimColor: true, children: orgName }), _jsx(SelectList, { title: "Switch", items: items, initialKey: "action:app", onSelect: handleSelect, onCancel: onCancel, footer: "Esc to go back" })] }));
46
+ }
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /** CLI package version. Stamped by scripts/version.sh from the repo VERSION file — do not hand-edit. */
2
- export const NAMI_CLI_VERSION = "3.4.11-dev.202609222238";
2
+ export const NAMI_CLI_VERSION = "3.4.11-dev.202609230009";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@namiml/cli",
3
- "version": "3.4.11-dev.202609222238",
3
+ "version": "3.4.11-dev.202609230009",
4
4
  "description": "Nami SDK developer CLI — terminal test app, implementation and flow checks",
5
5
  "keywords": [
6
6
  "nami",
@@ -35,7 +35,7 @@
35
35
  "access": "public"
36
36
  },
37
37
  "dependencies": {
38
- "@namiml/sdk-core": "3.4.11-dev.202609222238",
38
+ "@namiml/sdk-core": "3.4.11-dev.202609230009",
39
39
  "commander": "^15",
40
40
  "env-paths": "^4",
41
41
  "ink": "^6.0.0",