@aiaiai-pt/martha-cli 0.30.0 → 0.31.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 (2) hide show
  1. package/dist/index.js +51 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3528,6 +3528,7 @@ var require_stringify = __commonJS((exports) => {
3528
3528
  nullStr: "null",
3529
3529
  simpleKeys: false,
3530
3530
  singleQuote: null,
3531
+ trailingComma: false,
3531
3532
  trueStr: "true",
3532
3533
  verifyAliasOrder: true
3533
3534
  }, doc.schema.toStringOptions, options);
@@ -4036,13 +4037,20 @@ ${indent}${line}` : `
4036
4037
  if (comment)
4037
4038
  reqNewline = true;
4038
4039
  let str = stringify.stringify(item, itemCtx, () => comment = null);
4039
- if (i < items.length - 1)
4040
+ reqNewline || (reqNewline = lines.length > linesAtValue || str.includes(`
4041
+ `));
4042
+ if (i < items.length - 1) {
4040
4043
  str += ",";
4044
+ } else if (ctx.options.trailingComma) {
4045
+ if (ctx.options.lineWidth > 0) {
4046
+ reqNewline || (reqNewline = lines.reduce((sum, line) => sum + line.length + 2, 2) + (str.length + 2) > ctx.options.lineWidth);
4047
+ }
4048
+ if (reqNewline) {
4049
+ str += ",";
4050
+ }
4051
+ }
4041
4052
  if (comment)
4042
4053
  str += stringifyComment.lineComment(str, itemIndent, commentString(comment));
4043
- if (!reqNewline && (lines.length > linesAtValue || str.includes(`
4044
- `)))
4045
- reqNewline = true;
4046
4054
  lines.push(str);
4047
4055
  linesAtValue = lines.length;
4048
4056
  }
@@ -6837,17 +6845,22 @@ var require_compose_node = __commonJS((exports) => {
6837
6845
  case "block-map":
6838
6846
  case "block-seq":
6839
6847
  case "flow-collection":
6840
- node = composeCollection.composeCollection(CN, ctx, token, props, onError);
6841
- if (anchor)
6842
- node.anchor = anchor.source.substring(1);
6848
+ try {
6849
+ node = composeCollection.composeCollection(CN, ctx, token, props, onError);
6850
+ if (anchor)
6851
+ node.anchor = anchor.source.substring(1);
6852
+ } catch (error) {
6853
+ const message = error instanceof Error ? error.message : String(error);
6854
+ onError(token, "RESOURCE_EXHAUSTION", message);
6855
+ }
6843
6856
  break;
6844
6857
  default: {
6845
6858
  const message = token.type === "error" ? token.message : `Unsupported token (type: ${token.type})`;
6846
6859
  onError(token, "UNEXPECTED_TOKEN", message);
6847
- node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError);
6848
6860
  isSrcToken = false;
6849
6861
  }
6850
6862
  }
6863
+ node ?? (node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError));
6851
6864
  if (anchor && node.anchor === "")
6852
6865
  onError(anchor, "BAD_ALIAS", "Anchor cannot be an empty string");
6853
6866
  if (atKey && ctx.options.stringKeys && (!identity.isScalar(node) || typeof node.value !== "string" || node.tag && node.tag !== "tag:yaml.org,2002:str")) {
@@ -11063,7 +11076,7 @@ init_config();
11063
11076
  init_errors();
11064
11077
 
11065
11078
  // src/version.ts
11066
- var CLI_VERSION = "0.30.0";
11079
+ var CLI_VERSION = "0.31.0";
11067
11080
 
11068
11081
  // src/commands/sessions.ts
11069
11082
  function relativeTime(iso) {
@@ -16959,7 +16972,7 @@ ${source_default.red("Error:")}`);
16959
16972
  }
16960
16973
  console.log(`Cancelled task ${id}`);
16961
16974
  });
16962
- cmd.command("poll").description("Poll for open tasks available for claiming").option("--agent <id>", "Filter by agent definition ID").option("--limit <n>", "Max results", "10").action(async (opts) => {
16975
+ cmd.command("poll").description("Poll for open tasks available for claiming").option("--agent <id>", "Filter by agent definition ID (human tokens only; ignored under agent auth)").option("--team <name>", "Poll a team's queue (name or UUID)").option("--limit <n>", "Max results", "10").action(async (opts) => {
16963
16976
  const ctx = getCtx();
16964
16977
  const limitN = parseInt(opts.limit, 10);
16965
16978
  if (isNaN(limitN) || limitN < 1) {
@@ -16968,6 +16981,8 @@ ${source_default.red("Error:")}`);
16968
16981
  const params = { limit: String(limitN) };
16969
16982
  if (opts.agent)
16970
16983
  params.agent_id = opts.agent;
16984
+ if (opts.team)
16985
+ params.team_id = opts.team;
16971
16986
  const items = await ctx.api.get("/api/tasks/poll", { params });
16972
16987
  if (isJson()) {
16973
16988
  console.log(JSON.stringify(items, null, 2));
@@ -17226,16 +17241,18 @@ function heartbeatIntervalMs(leaseTimeoutS) {
17226
17241
  return Math.min(lease / 3, 60) * 1000;
17227
17242
  }
17228
17243
  async function runOnce(ctx, opts, handled) {
17229
- const tasks = await ctx.api.get("/api/tasks/poll", {
17230
- params: { agent_id: opts.agent, limit: String(opts.pollLimit ?? 5) }
17231
- });
17244
+ const params = { limit: String(opts.pollLimit ?? 5) };
17245
+ if (opts.team)
17246
+ params.team_id = opts.team;
17247
+ const tasks = await ctx.api.get("/api/tasks/poll", { params });
17232
17248
  const candidates = Array.isArray(tasks) ? tasks : [];
17233
- const task = candidates.find((t) => (t.status ?? "open") === "open" && !handled?.has(t.id));
17249
+ const matchesAgent = (t) => !opts.agent || t.assigned_agent_id === opts.agent || t.agent_definition_id === opts.agent;
17250
+ const task = candidates.find((t) => (t.status ?? "open") === "open" && !handled?.has(t.id) && matchesAgent(t));
17234
17251
  if (!task)
17235
17252
  return { ran: false };
17236
- if (!opts.autoYes) {
17253
+ if (!opts.allowHostExec) {
17237
17254
  process.stderr.write(source_default.yellow(`
17238
- [runner] refused task ${task.id} — re-run with --yes to allow host execution
17255
+ [runner] refused task ${task.id} — re-run with --allow-host-exec to allow host execution
17239
17256
  `));
17240
17257
  return { ran: false, taskId: task.id, status: "refused" };
17241
17258
  }
@@ -17297,8 +17314,14 @@ async function runOnce(ctx, opts, handled) {
17297
17314
  `));
17298
17315
  return { ran: true, taskId: task.id, status, exitCode: exit_code };
17299
17316
  }
17317
+ function startupEchoLine(who, opts) {
17318
+ const identity2 = who ? who.kind === "agent" ? `agent ${who.agent_name ?? "?"} (${(who.agent_id ?? "").slice(0, 8)}…)` : `${who.kind} ${who.sub ?? ""}`.trim() : "identity unknown (whoami unavailable)";
17319
+ const scope = opts.team ? `team:${opts.team}` : "direct";
17320
+ const exec = opts.allowHostExec ? "host exec allowed" : "host exec refused (pass --allow-host-exec)";
17321
+ return `[runner] authenticated as ${identity2}, scope ${scope}, cwd ${opts.cwd}, ${exec}${opts.once ? " — once" : ""}`;
17322
+ }
17300
17323
  function registerRunnerCommand(program2) {
17301
- program2.command("runner").description("Run as an external agent's executor: claim tasks and run them on this host.").requiredOption("--agent <id>", "Agent definition id this runner serves").option("--once", "Claim + run a single task, then exit").option("--poll-interval <ms>", "Poll interval when idle (ms)", "3000").option("--cwd <dir>", "Scoped workspace for task execution", process.cwd()).option("--yes", "Consent to run host commands (required to execute)").action(async (opts) => {
17324
+ program2.command("runner").description("Run as an external agent's executor: claim tasks and run them on this host.").option("--agent <id>", "Deprecated: identity comes from the API token; applied as a client-side filter only").option("--team <name>", "Poll this team's queue (name or UUID) instead of direct-only").option("--once", "Claim + run a single task, then exit").option("--poll-interval <ms>", "Poll interval when idle (ms)", "3000").option("--cwd <dir>", "Scoped workspace for task execution", process.cwd()).option("--allow-host-exec", "Consent to run host commands (required to execute)").option("--yes", "Deprecated alias for --allow-host-exec").action(async (opts) => {
17302
17325
  const ctx = createContext({
17303
17326
  profileOverride: program2.opts().profile,
17304
17327
  verbose: program2.opts().verbose
@@ -17309,12 +17332,21 @@ function registerRunnerCommand(program2) {
17309
17332
  if (isNaN(pollInterval) || pollInterval < 250) {
17310
17333
  throw new CLIError("--poll-interval must be >= 250 (ms)", 4 /* Validation */);
17311
17334
  }
17335
+ if (opts.agent) {
17336
+ process.stderr.write(source_default.yellow(`[runner] --agent is deprecated — identity comes from the API token; the value is applied as a client-side filter only
17337
+ `));
17338
+ }
17312
17339
  const runOpts = {
17313
17340
  agent: opts.agent,
17341
+ team: opts.team,
17314
17342
  cwd: opts.cwd,
17315
- autoYes: !!opts.yes
17343
+ allowHostExec: !!(opts.allowHostExec || opts.yes)
17316
17344
  };
17317
- process.stderr.write(source_default.dim(`[runner] serving agent ${opts.agent} (cwd ${opts.cwd})${opts.once ? " — once" : ""}
17345
+ let who;
17346
+ try {
17347
+ who = await ctx.api.get("/api/tasks/whoami");
17348
+ } catch {}
17349
+ process.stderr.write(source_default.dim(`${startupEchoLine(who, { team: opts.team, cwd: opts.cwd, allowHostExec: runOpts.allowHostExec, once: !!opts.once })}
17318
17350
  `));
17319
17351
  if (opts.once) {
17320
17352
  await runOnce(ctx, runOpts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiaiai-pt/martha-cli",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
4
4
  "description": "Terminal-first client for the Martha AI platform",
5
5
  "homepage": "https://docs.martha.nomadriver.co",
6
6
  "repository": {