@stamn/stamn-plugin 0.1.0-alpha.6 → 0.1.0-alpha.7

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/index.js CHANGED
@@ -4816,31 +4816,32 @@ var StamnClient = class {
4816
4816
  }
4817
4817
  };
4818
4818
 
4819
- // ../stamn-cli/dist/chunk-7DSOXMQ6.js
4819
+ // ../stamn-cli/dist/chunk-ECKKSWUQ.js
4820
4820
  import { execSync } from "child_process";
4821
4821
  import { mkdirSync, readFileSync, writeFileSync, unlinkSync } from "fs";
4822
4822
  import { join } from "path";
4823
4823
  import { tmpdir } from "os";
4824
4824
  import { existsSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, rmSync, writeFileSync as writeFileSync2 } from "fs";
4825
4825
  import { dirname, join as join2 } from "path";
4826
- async function handleLogin(opts, adapter) {
4827
- const client = new StamnClient();
4828
- We("Stamn Device Login");
4829
- let name = opts.name;
4830
- if (!name) {
4831
- const input = await Ze({
4832
- message: "What should we call this agent?",
4833
- placeholder: "my-agent",
4834
- validate: (value) => {
4835
- if (!value?.trim()) return "Name is required.";
4836
- }
4837
- });
4838
- if (typeof input === "symbol") {
4839
- Ne("Login cancelled.");
4826
+ async function handleLogin(_opts, adapter) {
4827
+ We("Stamn Login");
4828
+ const existing = adapter.readConfig();
4829
+ if (existing?.apiKey) {
4830
+ const s2 = bt2();
4831
+ s2.start("Checking existing session...");
4832
+ try {
4833
+ const client2 = new StamnClient({ apiKey: existing.apiKey });
4834
+ await client2.participants.list();
4835
+ s2.stop("Session valid.");
4836
+ R2.info("Already logged in.");
4837
+ Le("Run `stamn agent register` to create an agent, or `stamn agent list` to see existing ones.");
4840
4838
  return;
4839
+ } catch {
4840
+ s2.stop("Session expired.");
4841
+ R2.warn("Existing session is invalid. Re-authenticating...");
4841
4842
  }
4842
- name = input;
4843
4843
  }
4844
+ const client = new StamnClient();
4844
4845
  const s = bt2();
4845
4846
  try {
4846
4847
  s.start("Initiating device flow...");
@@ -4855,24 +4856,140 @@ ${label("Code:")} ${flow.userCode}`,
4855
4856
  s.start("Waiting for approval...");
4856
4857
  const apiKey = await client.auth.pollForApproval(flow.deviceCode);
4857
4858
  s.stop("Approved!");
4858
- client.setApiKey(apiKey);
4859
+ adapter.writeConfig({ apiKey });
4860
+ R2.success("Logged in successfully.");
4861
+ R2.info(`Config written to ${adapter.getConfigPath()}`);
4862
+ Le("Now run `stamn agent register` to create or reconnect an agent.");
4863
+ } catch (err) {
4864
+ s.stop("Failed.");
4865
+ Ne(`Login failed: ${err.message}`);
4866
+ process.exitCode = 1;
4867
+ }
4868
+ }
4869
+ async function handleAgentRegister(opts, adapter) {
4870
+ We("Stamn Agent Register");
4871
+ const config = adapter.readConfig();
4872
+ if (!config?.apiKey) {
4873
+ Ne("Not logged in. Run `stamn login` first.");
4874
+ process.exitCode = 1;
4875
+ return;
4876
+ }
4877
+ let name = opts.name;
4878
+ if (!name) {
4879
+ const input = await Ze({
4880
+ message: "What should we call this agent?",
4881
+ placeholder: "my-agent",
4882
+ validate: (value) => {
4883
+ if (!value?.trim()) return "Name is required.";
4884
+ }
4885
+ });
4886
+ if (typeof input === "symbol") {
4887
+ Ne("Cancelled.");
4888
+ return;
4889
+ }
4890
+ name = input;
4891
+ }
4892
+ const client = new StamnClient({ apiKey: config.apiKey });
4893
+ const s = bt2();
4894
+ try {
4895
+ s.start("Checking existing agents...");
4896
+ const agents = await client.participants.list();
4897
+ const match = agents.find((a) => a.name === name);
4898
+ if (match) {
4899
+ s.stop("Agent found.");
4900
+ adapter.writeConfig({ agentId: match.id, agentName: match.name });
4901
+ R2.success(`Agent "${match.name}" (${match.id}) already exists. Selected as active.`);
4902
+ Le("Done!");
4903
+ return;
4904
+ }
4859
4905
  s.start("Registering agent...");
4860
4906
  const participant = await client.participants.create({ name });
4861
4907
  s.stop("Agent registered.");
4862
- adapter.writeConfig({
4863
- apiKey,
4864
- agentId: participant.id,
4865
- agentName: participant.name
4866
- });
4908
+ adapter.writeConfig({ agentId: participant.id, agentName: participant.name });
4867
4909
  R2.success(`Agent "${participant.name}" (${participant.id})`);
4868
- R2.info(`Config written to ${adapter.getConfigPath()}`);
4869
- Le("Done! You can now use stamn commands.");
4910
+ Le("Done!");
4870
4911
  } catch (err) {
4871
4912
  s.stop("Failed.");
4872
- Ne(`Login failed: ${err.message}`);
4913
+ Ne(`Registration failed: ${err.message}`);
4873
4914
  process.exitCode = 1;
4874
4915
  }
4875
4916
  }
4917
+ async function handleAgentList(_opts, adapter) {
4918
+ We("Stamn Agents");
4919
+ const config = adapter.readConfig();
4920
+ if (!config?.apiKey) {
4921
+ Ne("Not logged in. Run `stamn login` first.");
4922
+ process.exitCode = 1;
4923
+ return;
4924
+ }
4925
+ const client = new StamnClient({ apiKey: config.apiKey });
4926
+ const s = bt2();
4927
+ try {
4928
+ s.start("Fetching agents...");
4929
+ const agents = await client.participants.list();
4930
+ s.stop(`${agents.length} agent${agents.length === 1 ? "" : "s"} found.`);
4931
+ if (agents.length === 0) {
4932
+ R2.info("No agents found. Run `stamn agent register` to create one.");
4933
+ return;
4934
+ }
4935
+ for (const agent of agents) {
4936
+ const active = agent.id === config.agentId ? " (active)" : "";
4937
+ R2.info(` ${agent.name} \u2014 ${agent.id}${active}`);
4938
+ }
4939
+ } catch (err) {
4940
+ s.stop("Failed.");
4941
+ Ne(`Failed to list agents: ${err.message}`);
4942
+ process.exitCode = 1;
4943
+ }
4944
+ }
4945
+ async function handleAgentSelect(opts, adapter) {
4946
+ We("Stamn Agent Select");
4947
+ const config = adapter.readConfig();
4948
+ if (!config?.apiKey) {
4949
+ Ne("Not logged in. Run `stamn login` first.");
4950
+ process.exitCode = 1;
4951
+ return;
4952
+ }
4953
+ const client = new StamnClient({ apiKey: config.apiKey });
4954
+ const s = bt2();
4955
+ try {
4956
+ s.start("Fetching agents...");
4957
+ const agents = await client.participants.list();
4958
+ s.stop(`${agents.length} agent${agents.length === 1 ? "" : "s"} found.`);
4959
+ const match = agents.find((a) => a.id === opts.nameOrId || a.name === opts.nameOrId);
4960
+ if (!match) {
4961
+ Ne(`Agent "${opts.nameOrId}" not found. Run \`stamn agent list\` to see available agents.`);
4962
+ process.exitCode = 1;
4963
+ return;
4964
+ }
4965
+ adapter.writeConfig({ agentId: match.id, agentName: match.name });
4966
+ R2.success(`Active agent set to "${match.name}" (${match.id})`);
4967
+ Le("Done!");
4968
+ } catch (err) {
4969
+ s.stop("Failed.");
4970
+ Ne(`Failed to select agent: ${err.message}`);
4971
+ process.exitCode = 1;
4972
+ }
4973
+ }
4974
+ async function handleLogout(_opts, adapter) {
4975
+ We("Stamn Logout");
4976
+ const config = adapter.readConfig();
4977
+ if (!config?.apiKey) {
4978
+ R2.info("Not logged in.");
4979
+ Le("Nothing to do.");
4980
+ return;
4981
+ }
4982
+ const shouldContinue = await Re({
4983
+ message: "This will clear your auth session. Your agents will not be deleted. Continue?"
4984
+ });
4985
+ if (!shouldContinue || typeof shouldContinue === "symbol") {
4986
+ Ne("Cancelled.");
4987
+ return;
4988
+ }
4989
+ adapter.writeConfig({ apiKey: "", agentId: "", agentName: "" });
4990
+ R2.success("Logged out.");
4991
+ Le("Run `stamn login` to authenticate again.");
4992
+ }
4876
4993
  function openEditor(initial) {
4877
4994
  const editor = process.env.EDITOR || process.env.VISUAL || "vi";
4878
4995
  const tmpFile = join(tmpdir(), `stamn-personality-${Date.now()}.md`);
@@ -4895,7 +5012,7 @@ function handleConfig(opts, adapter) {
4895
5012
  if (!opts.name && !opts.personality) {
4896
5013
  const config = adapter.readConfig();
4897
5014
  if (!config) {
4898
- R2.warn("No config found. Run `stamn agent login` first.");
5015
+ R2.warn("No config found. Run `stamn login` first.");
4899
5016
  return;
4900
5017
  }
4901
5018
  R2.info(`Name: ${config.agentName ?? "(not set)"}`);
@@ -5039,8 +5156,12 @@ function registerCli(api) {
5039
5156
  api.registerCli(
5040
5157
  ({ program }) => {
5041
5158
  const stamn = program.command("stamn").description("Stamn commands");
5159
+ stamn.command("login").description("Authenticate with Stamn").action(() => handleLogin({}, adapter));
5160
+ stamn.command("logout").description("Clear auth session").action(() => handleLogout({}, adapter));
5042
5161
  const agent = stamn.command("agent").description("Agent management");
5043
- agent.command("login").description("Authenticate and register an agent").option("--name <name>", "Agent name").action((opts) => handleLogin(opts, adapter));
5162
+ agent.command("register").description("Register a new agent or reconnect to an existing one").option("--name <name>", "Agent name").action((opts) => handleAgentRegister(opts, adapter));
5163
+ agent.command("list").description("List agents under your account").action(() => handleAgentList({}, adapter));
5164
+ agent.command("select").description("Set active agent").argument("<nameOrId>", "Agent name or ID").action((nameOrId) => handleAgentSelect({ nameOrId }, adapter));
5044
5165
  agent.command("config").description("View or update agent configuration").option("--name <name>", "Agent display name").option("--personality", "Open editor to set agent personality").action((opts) => handleConfig(opts, adapter));
5045
5166
  stamn.command("status").description("Show connection status and server health").action(() => handleStatus(adapter));
5046
5167
  stamn.command("uninstall").description("Remove all Stamn config and data").action(() => handleUninstall(adapter));
@@ -5562,7 +5683,7 @@ var index_default = {
5562
5683
  const config = adapter.readConfig();
5563
5684
  registerCli(api);
5564
5685
  if (!config?.apiKey || !config?.agentId) {
5565
- api.logger.warn('Stamn not configured. Run "stamn agent login" first.');
5686
+ api.logger.warn('Stamn not configured. Run "stamn login" then "stamn agent register" first.');
5566
5687
  return;
5567
5688
  }
5568
5689
  const agentId = config.agentId;