teamclaws 2.0.15 → 2.0.16

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
@@ -312,6 +312,23 @@ When supplied by the workspace, each entry includes its saved `sudo_enabled`
312
312
  status. An accepted invitation's selection is historical; the current member's
313
313
  status determines their current access.
314
314
 
315
+ ## Manage GitHub repository permissions for a server
316
+
317
+ These commands manage server access to repositories you have already connected to TeamClaws.
318
+
319
+ ```sh
320
+ teamclaws git repos
321
+ teamclaws git list <server-id>
322
+ teamclaws git set <server-id> <repository-id> --issues read --contents write --pull-requests read --workflows none
323
+ teamclaws git remove <server-id> <repository-id>
324
+ ```
325
+
326
+ Use `teamclaws servers list` to find the server ID and `teamclaws git repos` to find the repository ID. If you have no connected repositories or cannot find the repository you need, add it at [Connected GitHub](https://www.teamclaws.com/app/connected-github/).
327
+
328
+ Server owners can list, set, and remove permissions for their servers. `git set` requires all four flags. Issues, contents, and pull requests accept `none`, `read`, or `write`. Workflows accepts `none` or `write`. Setting all four to `none` removes the assignment. `git remove` also succeeds when the repository is already unassigned.
329
+
330
+ Each command supports `--json`. If a mutation returns an uncertain result, run `git list` to check the saved permissions before retrying.
331
+
315
332
  ## Read chat history without a browser
316
333
 
317
334
  ```text
package/dist/app.js CHANGED
@@ -170,6 +170,18 @@ export async function run(arguments_, dependencies = {}, signal) {
170
170
  output.serverMetadataUpdated(server);
171
171
  return 0;
172
172
  }
173
+ case "git_repos":
174
+ output.gitRepositories(await broker.gitRepositories(signal));
175
+ return 0;
176
+ case "git_list":
177
+ output.gitAssignments(await broker.gitAssignments(parsed.serverId, signal));
178
+ return 0;
179
+ case "git_set":
180
+ output.gitAssignmentResult(await broker.setGitAssignment(parsed.serverId, parsed.repositoryId, parsed.permissions, signal));
181
+ return 0;
182
+ case "git_remove":
183
+ output.gitAssignmentResult(await broker.removeGitAssignment(parsed.serverId, parsed.repositoryId, signal));
184
+ return 0;
173
185
  case "pair": {
174
186
  const target = parsed.target
175
187
  ? parsePairingTarget(parsed.target)
@@ -205,6 +217,55 @@ export async function run(arguments_, dependencies = {}, signal) {
205
217
  }
206
218
  }
207
219
  export function parseArguments(arguments_) {
220
+ if (arguments_[0] === "git") {
221
+ const operation = arguments_[1];
222
+ if (operation === "repos") {
223
+ const { flags } = parseNamedOptions(arguments_.slice(2), {
224
+ values: [],
225
+ booleans: ["--json"],
226
+ });
227
+ return { action: "git_repos", json: flags.has("--json") };
228
+ }
229
+ if (operation !== "list" && operation !== "set" && operation !== "remove")
230
+ throw usageError();
231
+ const serverId = normalizeUuid(requiredPositional(arguments_, 2));
232
+ if (operation === "list") {
233
+ const { flags } = parseNamedOptions(arguments_.slice(3), {
234
+ values: [],
235
+ booleans: ["--json"],
236
+ });
237
+ return { action: "git_list", serverId, json: flags.has("--json") };
238
+ }
239
+ const rawRepositoryId = requiredPositional(arguments_, 3);
240
+ const repositoryId = Number(rawRepositoryId);
241
+ if (!/^[1-9][0-9]*$/.test(rawRepositoryId) ||
242
+ !Number.isSafeInteger(repositoryId))
243
+ throw usageError();
244
+ const { values, flags } = parseNamedOptions(arguments_.slice(4), {
245
+ values: operation === "set"
246
+ ? ["--issues", "--contents", "--pull-requests", "--workflows"]
247
+ : [],
248
+ booleans: ["--json"],
249
+ });
250
+ const json = flags.has("--json");
251
+ if (operation === "remove")
252
+ return { action: "git_remove", serverId, repositoryId, json };
253
+ const workflows = values["--workflows"];
254
+ if (workflows !== "none" && workflows !== "write")
255
+ throw usageError();
256
+ return {
257
+ action: "git_set",
258
+ serverId,
259
+ repositoryId,
260
+ json,
261
+ permissions: {
262
+ issues: gitAccessLevel(values["--issues"]),
263
+ contents: gitAccessLevel(values["--contents"]),
264
+ pull_requests: gitAccessLevel(values["--pull-requests"]),
265
+ workflows,
266
+ },
267
+ };
268
+ }
208
269
  if (arguments_[0] === "servers" && arguments_[1] === "update") {
209
270
  const serverId = normalizeUuid(requiredPositional(arguments_, 2));
210
271
  const updates = {};
@@ -474,6 +535,11 @@ function parseNamedOptions(args, allowed) {
474
535
  }
475
536
  return { values, flags };
476
537
  }
538
+ function gitAccessLevel(value) {
539
+ if (value === "none" || value === "read" || value === "write")
540
+ return value;
541
+ throw usageError();
542
+ }
477
543
  function nonNegativeInteger(value) {
478
544
  if (value === undefined)
479
545
  return 0;
@@ -567,5 +633,5 @@ function usageError() {
567
633
  });
568
634
  }
569
635
  export function helpText() {
570
- return `TeamClaws ${PACKAGE_VERSION}\n\nUsage:\n teamclaws update [--json]\n teamclaws shell <target> --command <text> [--json]\n teamclaws users add <target> <email> [--sudo] [--json]\n teamclaws users remove <target> <email> [--json]\n teamclaws users list <target> [--json]\n teamclaws login <email> [--json]\n teamclaws auth status [--json]\n teamclaws logout [--revoke] [--json]\n teamclaws servers list [--json]\n teamclaws servers update <server-id> [--name <text>] [--description <text>] [--json]\n teamclaws pair status <server-identifier-or-canonical-workspace-address> [--json]\n teamclaws pair [server-identifier-or-canonical-workspace-address] [--no-open] [--json]\n teamclaws chat list <target> [--json]\n teamclaws chat history <target> [--json]\n teamclaws chat messages <target> --chat-id <uuid> [--after-message-id <n>] [--json]\n teamclaws chat capabilities <target> [--json]\n teamclaws chat start <target> --message <text> [selection options] [--json]\n teamclaws chat send <target> --session-id <uuid> --message <text> [--json]\n teamclaws chat watch <target> --session-id <uuid> --request-id <uuid> [resume cursors] [--json]\n\nPair status performs one bounded direct verification and stops. Pairing grants the standard host-issued credential. Chat commands use that credential directly against the selected workspace.\n`;
636
+ return `TeamClaws ${PACKAGE_VERSION}\n\nUsage:\n teamclaws update [--json]\n teamclaws shell <target> --command <text> [--json]\n teamclaws users add <target> <email> [--sudo] [--json]\n teamclaws users remove <target> <email> [--json]\n teamclaws users list <target> [--json]\n teamclaws login <email> [--json]\n teamclaws auth status [--json]\n teamclaws logout [--revoke] [--json]\n teamclaws servers list [--json]\n teamclaws servers update <server-id> [--name <text>] [--description <text>] [--json]\n teamclaws git repos [--json]\n teamclaws git list <server-id> [--json]\n teamclaws git set <server-id> <repository-id> --issues <none|read|write> --contents <none|read|write> --pull-requests <none|read|write> --workflows <none|write> [--json]\n teamclaws git remove <server-id> <repository-id> [--json]\n teamclaws pair status <server-identifier-or-canonical-workspace-address> [--json]\n teamclaws pair [server-identifier-or-canonical-workspace-address] [--no-open] [--json]\n teamclaws chat list <target> [--json]\n teamclaws chat history <target> [--json]\n teamclaws chat messages <target> --chat-id <uuid> [--after-message-id <n>] [--json]\n teamclaws chat capabilities <target> [--json]\n teamclaws chat start <target> --message <text> [selection options] [--json]\n teamclaws chat send <target> --session-id <uuid> --message <text> [--json]\n teamclaws chat watch <target> --session-id <uuid> --request-id <uuid> [resume cursors] [--json]\n\nPair status performs one bounded direct verification and stops. Pairing grants the standard host-issued credential. Chat commands use that credential directly against the selected workspace.\n`;
571
637
  }
package/dist/broker.js CHANGED
@@ -3,7 +3,14 @@ import { randomUUID } from "node:crypto";
3
3
  import { API_BASE, CLIENT_NAME, CONTRACT_VERSION, MAX_CLIENT_LABEL_LENGTH, MAX_DEVICE_NAME_LENGTH, PACKAGE_VERSION, } from "./constants.js";
4
4
  import { TeamClawsError } from "./errors.js";
5
5
  import { errorFromResponse, requestJson } from "./http.js";
6
- import { assertExactKeys, isObject, normalizeUuid, parsePendingPairing, parseWorkspaceInventory, requireString, } from "./validation.js";
6
+ import { assertExactKeys, isObject, normalizeUuid, parsePendingPairing, parseWorkspaceInventory, requireInteger, requireString, } from "./validation.js";
7
+ const CONNECTED_GITHUB_URL = "https://www.teamclaws.com/app/connected-github/";
8
+ const GIT_PERMISSION_KEYS = [
9
+ "issues",
10
+ "contents",
11
+ "pull_requests",
12
+ "workflows",
13
+ ];
7
14
  export class BrokerClient {
8
15
  fetcher;
9
16
  deviceName;
@@ -54,6 +61,94 @@ export class BrokerClient {
54
61
  assertExactKeys(response.body, ["server"], [], "server metadata response");
55
62
  return editableServer(response.body.server, id);
56
63
  }
64
+ async gitRepositories(signal) {
65
+ const body = await this.gitRequest("GET", `${API_BASE}github-repositories/`, signal);
66
+ assertExactKeys(body, ["repositories", "connect_url"], [], "repository list");
67
+ if (!Array.isArray(body.repositories) ||
68
+ body.connect_url !== CONNECTED_GITHUB_URL)
69
+ throw invalidGitResponse();
70
+ return {
71
+ repositories: body.repositories.map((row) => {
72
+ if (!isObject(row))
73
+ throw invalidGitResponse();
74
+ assertExactKeys(row, ["repository_id", "full_name"], [], "repository");
75
+ return gitRepository(row);
76
+ }),
77
+ connect_url: body.connect_url,
78
+ };
79
+ }
80
+ async gitAssignments(serverId, signal) {
81
+ const id = normalizeUuid(serverId);
82
+ const body = await this.gitRequest("GET", `${API_BASE}servers/${id}/github-repositories/`, signal);
83
+ assertExactKeys(body, ["server_id", "repositories"], [], "repository assignment list");
84
+ if (body.server_id !== id || !Array.isArray(body.repositories))
85
+ throw invalidGitResponse();
86
+ return {
87
+ server_id: id,
88
+ repositories: body.repositories.map((row) => {
89
+ if (!isObject(row))
90
+ throw invalidGitResponse();
91
+ assertExactKeys(row, ["repository_id", "full_name", "permissions"], [], "repository assignment");
92
+ return {
93
+ ...gitRepository(row),
94
+ permissions: gitPermissions(row.permissions),
95
+ };
96
+ }),
97
+ };
98
+ }
99
+ setGitAssignment(serverId, repositoryId, permissions, signal) {
100
+ return this.changeGitAssignment(serverId, repositoryId, signal, permissions);
101
+ }
102
+ removeGitAssignment(serverId, repositoryId, signal) {
103
+ return this.changeGitAssignment(serverId, repositoryId, signal);
104
+ }
105
+ async changeGitAssignment(serverId, repositoryId, signal, permissions) {
106
+ const id = normalizeUuid(serverId);
107
+ const url = `${API_BASE}servers/${id}/github-repositories/${repositoryId}/`;
108
+ const body = await this.gitRequest(permissions ? "POST" : "DELETE", url, signal, permissions ? { permissions } : undefined);
109
+ assertExactKeys(body, ["server_id", "repository_id", "full_name", "permissions", "code"], [], "repository assignment result");
110
+ if (body.server_id !== id || body.repository_id !== repositoryId)
111
+ throw invalidGitResponse();
112
+ const effective = gitPermissions(body.permissions);
113
+ if (!GIT_PERMISSION_KEYS.every((key) => effective[key] === (permissions?.[key] ?? "none")))
114
+ throw invalidGitResponse();
115
+ const assigned = GIT_PERMISSION_KEYS.some((key) => effective[key] !== "none");
116
+ const code = body.code;
117
+ if (assigned
118
+ ? code !== "permissions_set"
119
+ : code !== "removed" && code !== "already_unassigned")
120
+ throw invalidGitResponse();
121
+ return {
122
+ ...gitRepository(body),
123
+ server_id: id,
124
+ permissions: effective,
125
+ code: code,
126
+ };
127
+ }
128
+ async gitRequest(method, url, signal, body) {
129
+ const response = await requestJson(this.fetcher, url, {
130
+ method,
131
+ headers: await this.issuerHeaders(method, url),
132
+ ...(body === undefined ? {} : { body }),
133
+ ...(signal ? { signal } : {}),
134
+ });
135
+ if (response.status !== 200) {
136
+ const error = errorFromResponse(response, "git_permissions_failed");
137
+ if (error.code === "repository_unavailable" &&
138
+ isObject(response.body) &&
139
+ isObject(response.body.error) &&
140
+ response.body.error.connect_url === CONNECTED_GITHUB_URL) {
141
+ throw new TeamClawsError(error.code, error.message, {
142
+ exitCode: error.exitCode,
143
+ connectUrl: CONNECTED_GITHUB_URL,
144
+ });
145
+ }
146
+ throw error;
147
+ }
148
+ if (!isObject(response.body))
149
+ throw invalidGitResponse();
150
+ return response.body;
151
+ }
57
152
  async claimMetadataPrompt(serverId, signal) {
58
153
  const id = normalizeUuid(serverId);
59
154
  const url = `${API_BASE}servers/${id}/metadata-prompt/claim/`;
@@ -109,6 +204,38 @@ export class BrokerClient {
109
204
  };
110
205
  }
111
206
  }
207
+ function invalidGitResponse() {
208
+ return new TeamClawsError("invalid_response", "TeamClaws returned an invalid Git permissions response.", { exitCode: 9 });
209
+ }
210
+ function gitRepository(value) {
211
+ const fullName = requireString(value.full_name, "repository name");
212
+ if (!/^[a-z0-9_.-]+\/[a-z0-9_.-]+$/i.test(fullName))
213
+ throw invalidGitResponse();
214
+ return {
215
+ repository_id: requireInteger(value.repository_id, "repository ID", 1, Number.MAX_SAFE_INTEGER),
216
+ full_name: fullName,
217
+ };
218
+ }
219
+ function gitPermissions(value) {
220
+ if (!isObject(value))
221
+ throw invalidGitResponse();
222
+ assertExactKeys(value, GIT_PERMISSION_KEYS, [], "Git permission map");
223
+ const access = (key) => {
224
+ const level = value[key];
225
+ if (level === "none" || level === "read" || level === "write")
226
+ return level;
227
+ throw invalidGitResponse();
228
+ };
229
+ const workflows = value.workflows;
230
+ if (workflows !== "none" && workflows !== "write")
231
+ throw invalidGitResponse();
232
+ return {
233
+ issues: access("issues"),
234
+ contents: access("contents"),
235
+ pull_requests: access("pull_requests"),
236
+ workflows,
237
+ };
238
+ }
112
239
  function invalidMetadataResponse() {
113
240
  return new TeamClawsError("invalid_response", "TeamClaws returned invalid server metadata.", { exitCode: 9 });
114
241
  }
package/dist/constants.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export const PACKAGE_NAME = "teamclaws";
2
- export const PACKAGE_VERSION = "2.0.15";
2
+ export const PACKAGE_VERSION = "2.0.16";
3
3
  export const CLIENT_NAME = "teamclaws-cli";
4
4
  export const CONTRACT_VERSION = 1;
5
5
  export const OUTPUT_SCHEMA_VERSION = 1;
package/dist/errors.js CHANGED
@@ -3,6 +3,7 @@ export class TeamClawsError extends Error {
3
3
  retryable;
4
4
  retryAfterSeconds;
5
5
  exitCode;
6
+ connectUrl;
6
7
  constructor(code, message, details = {}) {
7
8
  super(message);
8
9
  this.name = "TeamClawsError";
@@ -10,6 +11,7 @@ export class TeamClawsError extends Error {
10
11
  this.retryable = details.retryable ?? false;
11
12
  this.retryAfterSeconds = details.retryAfterSeconds;
12
13
  this.exitCode = details.exitCode ?? 1;
14
+ this.connectUrl = details.connectUrl;
13
15
  }
14
16
  }
15
17
  export function safeError(error) {
package/dist/output.js CHANGED
@@ -413,6 +413,50 @@ export class Output {
413
413
  if (!this.json)
414
414
  this.stderr.write(`Error: ${detail}\n`);
415
415
  }
416
+ gitRepositories(result) {
417
+ this.event({
418
+ schema_version: OUTPUT_SCHEMA_VERSION,
419
+ event: "git_repositories",
420
+ ...result,
421
+ });
422
+ if (this.json)
423
+ return;
424
+ if (!result.repositories.length) {
425
+ this.stdout.write(`You don't have any repositories connected. Go to ${result.connect_url} to add them.\n`);
426
+ return;
427
+ }
428
+ for (const repo of result.repositories)
429
+ this.stdout.write(`${repo.repository_id} ${repo.full_name}\n`);
430
+ this.stdout.write(`Missing a repository? Go to ${result.connect_url} to add or enable it.\n`);
431
+ }
432
+ gitAssignments(result) {
433
+ this.event({
434
+ schema_version: OUTPUT_SCHEMA_VERSION,
435
+ event: "git_assignments",
436
+ ...result,
437
+ });
438
+ if (this.json)
439
+ return;
440
+ if (!result.repositories.length)
441
+ this.stdout.write(`No repositories assigned to ${result.server_id}.\n`);
442
+ for (const repo of result.repositories)
443
+ this.stdout.write(`${repo.repository_id} ${repo.full_name} ${gitPermissionsText(repo.permissions)}\n`);
444
+ }
445
+ gitAssignmentResult(result) {
446
+ this.event({
447
+ schema_version: OUTPUT_SCHEMA_VERSION,
448
+ event: "git_assignment_result",
449
+ ...result,
450
+ });
451
+ if (this.json)
452
+ return;
453
+ const messages = {
454
+ permissions_set: `Set permissions on ${result.server_id}: ${gitPermissionsText(result.permissions)}`,
455
+ removed: `Removed access from ${result.server_id}.`,
456
+ already_unassigned: `Already unassigned from ${result.server_id}.`,
457
+ };
458
+ this.stdout.write(`${result.full_name} (${result.repository_id}): ${messages[result.code]}\n`);
459
+ }
416
460
  error(error) {
417
461
  const event = {
418
462
  schema_version: OUTPUT_SCHEMA_VERSION,
@@ -425,10 +469,15 @@ export class Output {
425
469
  if (error.retryAfterSeconds !== undefined) {
426
470
  event.retry_after_seconds = error.retryAfterSeconds;
427
471
  }
472
+ if (error.connectUrl !== undefined)
473
+ event.connect_url = error.connectUrl;
428
474
  if (this.json)
429
475
  this.stdout.write(`${JSON.stringify(event)}\n`);
430
- else
476
+ else {
431
477
  this.stderr.write(`Error: ${error.message}\n`);
478
+ if (error.connectUrl !== undefined)
479
+ this.stderr.write(`Go to ${error.connectUrl} to add or enable the repository.\n`);
480
+ }
432
481
  }
433
482
  usersAddResult(result) {
434
483
  this.event({
@@ -488,3 +537,6 @@ export class Output {
488
537
  });
489
538
  }
490
539
  }
540
+ function gitPermissionsText(permissions) {
541
+ return `issues=${permissions.issues} contents=${permissions.contents} pull-requests=${permissions.pull_requests} workflows=${permissions.workflows}`;
542
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teamclaws",
3
- "version": "2.0.15",
3
+ "version": "2.0.16",
4
4
  "description": "Official TeamClaws command-line client and agent skills",
5
5
  "license": "PolyForm-Shield-1.0.0",
6
6
  "homepage": "https://teamclaws.com",