teamshift 0.1.1 → 0.1.3

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 CHANGED
@@ -11,9 +11,11 @@ npx teamshift add code-audit-swarm # adds it to your workspace
11
11
  npx teamshift run <team-id> "review services/api for auth mistakes"
12
12
  ```
13
13
 
14
- `teamshift teams` lists everything callable, including teams you built yourself
15
- in the portal. `add` is idempotent running it twice will not duplicate a team
16
- or overwrite edits you have made to it.
14
+ `teamshift teams` lists callable teams, including teams you built yourself in the
15
+ portal; `teamshift agents` lists callable individual agents. Keeping the two
16
+ inventories separate prevents a large internal agent library from burying the
17
+ teams a customer actually runs. `add` is idempotent — running it twice will not
18
+ duplicate a team or overwrite edits you have made to it.
17
19
 
18
20
  ## Parallel fan-out
19
21
 
@@ -36,7 +38,9 @@ completed $1.20 4.0s find dead code
36
38
  ```
37
39
 
38
40
  `--file prompts.txt` reads one prompt per line. Concurrency is bounded (default
39
- 5) so a large batch does not trip the API's write rate limit.
41
+ 5) so a large batch does not trip the API's write rate limit. Completed runs
42
+ print their scrubbed deliverable after the status table; `--json` includes it as
43
+ the outcome's `output` field.
40
44
 
41
45
  ## Already using Claude Code or Codex?
42
46
 
@@ -54,8 +58,8 @@ agent, with no second CLI to learn. Both install commands are in the portal unde
54
58
 
55
59
  | Code | Meaning |
56
60
  | --- | --- |
57
- | `0` | every run reached a terminal status |
58
- | `1` | usage error, auth failure, or at least one run failed to dispatch |
61
+ | `0` | every run completed and returned its deliverable |
62
+ | `1` | usage/auth error, timeout, failed run, or missing deliverable |
59
63
  | `2` | out of credit — add credits and rerun |
60
64
 
61
65
  ## Releasing
package/dist/api.js CHANGED
@@ -73,4 +73,7 @@ export class TeamShiftClient {
73
73
  const body = await this.request(`/v1/runs/${runId}`);
74
74
  return body.run;
75
75
  }
76
+ getRunResult(runId) {
77
+ return this.request(`/v1/runs/${runId}/result`);
78
+ }
76
79
  }
package/dist/cli.js CHANGED
@@ -10,7 +10,8 @@ const USAGE = `teamshift — run agent teams from your terminal
10
10
  teamshift whoami Show the active key and endpoint
11
11
  teamshift catalog Browse prebuilt teams you can add
12
12
  teamshift add <catalog-id> Add a prebuilt team to your workspace
13
- teamshift teams List callable teams and agents
13
+ teamshift teams List callable teams
14
+ teamshift agents List callable agents
14
15
  teamshift run <id> "<prompt>" Run one team, wait, print status and charge
15
16
  teamshift run <id> -p "a" -p "b" Fan out prompts in parallel
16
17
  teamshift run <id> --file prompts.txt One prompt per line, run in parallel
@@ -71,18 +72,16 @@ async function login() {
71
72
  rl.close();
72
73
  }
73
74
  }
74
- async function listCallable(json) {
75
+ async function listCallable(kind, json) {
75
76
  const payload = await requireClient().interop();
77
+ const items = kind === 'team' ? payload.teams : payload.agents;
76
78
  if (json) {
77
- console.log(JSON.stringify(payload, null, 2));
79
+ console.log(JSON.stringify(items, null, 2));
78
80
  return;
79
81
  }
80
- const rows = [
81
- ...payload.teams.map((item) => ['team', item.id, item.name]),
82
- ...payload.agents.map((item) => ['agent', item.id, item.name]),
83
- ];
82
+ const rows = items.map((item) => [kind, item.id, item.name]);
84
83
  if (rows.length === 0) {
85
- console.log('Nothing callable yet — create a team in the portal first.');
84
+ console.log(`No callable ${kind}s yet${kind === 'team' ? ' add one with `teamshift add <id>`.' : '.'}`);
86
85
  return;
87
86
  }
88
87
  console.log(table(['KIND', 'ID', 'NAME'], rows));
@@ -152,9 +151,20 @@ async function run(args) {
152
151
  const serial = outcomes.reduce((sum, outcome) => sum + outcome.elapsedMs, 0);
153
152
  console.log(`\n${outcomes.length} run(s) · ${money(total)} total · ${duration(Date.now() - startedAt)} wall clock ` +
154
153
  `(${duration(serial)} if run one at a time)`);
154
+ for (const outcome of outcomes) {
155
+ if (!outcome.error)
156
+ continue;
157
+ console.error(`\n${outcome.status} · ${outcome.runId ?? 'not dispatched'}\n${outcome.error}`);
158
+ }
159
+ for (const outcome of outcomes) {
160
+ if (outcome.output === null || outcome.output === undefined)
161
+ continue;
162
+ const output = typeof outcome.output === 'string' ? outcome.output : JSON.stringify(outcome.output, null, 2);
163
+ console.log(`\n${outcomes.length > 1 ? `[${outcome.prompt}]\n` : ''}${output}`);
164
+ }
155
165
  const failed = outcomes.filter((outcome) => outcome.error).length;
156
166
  if (failed > 0) {
157
- console.log(`${failed} run(s) failed to dispatch rerun just those prompts.`);
167
+ console.log(`${failed} run(s) need attentioninspect the status above before retrying.`);
158
168
  process.exitCode = 1;
159
169
  }
160
170
  }
@@ -186,7 +196,9 @@ export async function main(argv = process.argv.slice(2)) {
186
196
  case 'add':
187
197
  return await addFromCatalog(args);
188
198
  case 'teams':
189
- return await listCallable(args.json);
199
+ return await listCallable('team', args.json);
200
+ case 'agents':
201
+ return await listCallable('agent', args.json);
190
202
  case 'run':
191
203
  return await run(args);
192
204
  default:
package/dist/run.js CHANGED
@@ -1,5 +1,33 @@
1
+ import { ApiError } from './api.js';
1
2
  import { isTerminal } from './format.js';
2
3
  const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
4
+ export class RunPollingTimeoutError extends Error {
5
+ runId;
6
+ latest;
7
+ constructor(runId, latest) {
8
+ super(`run ${runId} did not finish before the polling timeout (last status: ${latest.status ?? 'unknown'})`);
9
+ this.runId = runId;
10
+ this.latest = latest;
11
+ }
12
+ }
13
+ const RETRYABLE_RESULT_STATUSES = new Set([404, 409, 502, 503]);
14
+ /** Wait for terminal reconciliation and object-storage visibility to converge. */
15
+ export async function waitForRunResult(client, runId, options = {}) {
16
+ const { intervalMs = 1000, timeoutMs = 30_000, now = Date.now, sleep = defaultSleep } = options;
17
+ const startedAt = now();
18
+ for (;;) {
19
+ try {
20
+ return await client.getRunResult(runId);
21
+ }
22
+ catch (error) {
23
+ if (!(error instanceof ApiError) || !RETRYABLE_RESULT_STATUSES.has(error.status))
24
+ throw error;
25
+ if (now() - startedAt >= timeoutMs)
26
+ throw error;
27
+ await sleep(intervalMs);
28
+ }
29
+ }
30
+ }
3
31
  /** Poll one run to a terminal status, or give up at the timeout. */
4
32
  export async function waitForRun(client, runId, options = {}) {
5
33
  const { intervalMs = 2000, timeoutMs = 900_000, now = Date.now, sleep = defaultSleep } = options;
@@ -7,7 +35,7 @@ export async function waitForRun(client, runId, options = {}) {
7
35
  let latest = await client.getRun(runId);
8
36
  while (!isTerminal(latest.status)) {
9
37
  if (now() - startedAt >= timeoutMs)
10
- return latest;
38
+ throw new RunPollingTimeoutError(runId, latest);
11
39
  await sleep(intervalMs);
12
40
  latest = await client.getRun(runId);
13
41
  }
@@ -34,22 +62,43 @@ export async function runBatch(client, kind, id, prompts, options = {}) {
34
62
  if (prompt === undefined)
35
63
  return;
36
64
  const startedAt = now();
65
+ let runId = null;
37
66
  try {
38
- const runId = await client.startRun(kind, id, prompt);
39
- const summary = await waitForRun(client, runId, { ...pollOptions, now });
67
+ runId = await client.startRun(kind, id, prompt);
68
+ let summary = await waitForRun(client, runId, { ...pollOptions, now });
69
+ let output = null;
70
+ let resultError;
71
+ if (summary.status === 'completed') {
72
+ try {
73
+ const result = await waitForRunResult(client, runId);
74
+ output = result.text ?? result.document;
75
+ // The result endpoint opens only after terminal reconciliation has
76
+ // settled; refresh so the printed charge is the reconciled cost,
77
+ // not the dispatch-time estimate that briefly shares its status.
78
+ summary = await client.getRun(runId);
79
+ }
80
+ catch (error) {
81
+ resultError = `result unavailable: ${error instanceof Error ? error.message : String(error)}`;
82
+ }
83
+ }
84
+ else {
85
+ resultError = `run ended with status ${summary.status ?? 'unknown'}`;
86
+ }
40
87
  results[index] = {
41
88
  prompt,
42
89
  runId,
43
90
  status: String(summary.status ?? 'unknown'),
44
91
  costUsd: summary.cost_estimate_usd ?? null,
45
92
  elapsedMs: now() - startedAt,
93
+ output,
94
+ ...(resultError ? { error: resultError } : {}),
46
95
  };
47
96
  }
48
97
  catch (error) {
49
98
  results[index] = {
50
99
  prompt,
51
- runId: null,
52
- status: 'dispatch_failed',
100
+ runId,
101
+ status: error instanceof RunPollingTimeoutError ? 'poll_timeout' : 'dispatch_failed',
53
102
  costUsd: null,
54
103
  elapsedMs: now() - startedAt,
55
104
  error: error instanceof Error ? error.message : String(error),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "teamshift",
3
3
  "private": false,
4
- "version": "0.1.1",
4
+ "version": "0.1.3",
5
5
  "description": "Run TeamShift agent teams from your terminal. Metered by usage \u2014 no model key of your own required.",
6
6
  "type": "module",
7
7
  "bin": {