aiset-cli 0.3.0__tar.gz → 0.3.2__tar.gz
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.
- {aiset_cli-0.3.0/src/aiset_cli.egg-info → aiset_cli-0.3.2}/PKG-INFO +23 -2
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/README.md +22 -1
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/pyproject.toml +1 -1
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/__init__.py +1 -1
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/registry.py +9 -2
- aiset_cli-0.3.2/src/aiset/run/cost.py +100 -0
- aiset_cli-0.3.2/src/aiset/run/names.py +37 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/pr_body.py +1 -1
- aiset_cli-0.3.2/src/aiset/run/sanitize.py +40 -0
- aiset_cli-0.3.2/src/aiset/running.py +165 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/server.py +69 -10
- {aiset_cli-0.3.0 → aiset_cli-0.3.2/src/aiset_cli.egg-info}/PKG-INFO +23 -2
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset_cli.egg-info/SOURCES.txt +2 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_run_cli.py +8 -0
- aiset_cli-0.3.2/tests/test_run_cost.py +144 -0
- aiset_cli-0.3.2/tests/test_run_names.py +82 -0
- aiset_cli-0.3.2/tests/test_run_sanitize.py +85 -0
- aiset_cli-0.3.2/tests/test_running.py +289 -0
- aiset_cli-0.3.0/src/aiset/run/cost.py +0 -21
- aiset_cli-0.3.0/src/aiset/run/names.py +0 -32
- aiset_cli-0.3.0/src/aiset/run/sanitize.py +0 -14
- aiset_cli-0.3.0/tests/test_run_cost.py +0 -26
- aiset_cli-0.3.0/tests/test_run_names.py +0 -39
- aiset_cli-0.3.0/tests/test_run_sanitize.py +0 -26
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/LICENSE +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/setup.cfg +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/archmap.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/atomic.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/brain.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/brief_index.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/cli.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/core.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/init_team.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/nudge.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/research.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/roster.json +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/__init__.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/__main__.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/ac.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/board.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/claims.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/cli.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/datatypes.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/fetch.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/gate.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/gitops.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/issue_md.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/launch.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/publish.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/refs.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/run/verdicts.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/settings.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/static/aiset-icon.png +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/static/apple-touch-icon.png +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/static/architecture.html +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/static/brain.html +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/static/favicon-16.png +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/static/favicon-32.png +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/static/favicon-48.png +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/static/favicon.ico +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/static/icon-192.png +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/static/icon-512.png +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/static/index.html +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/static/settings.html +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/static/site.webmanifest +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/sync_names.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/teammap.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/teammap_ts.js +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/templates/engineer.md +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/templates/integration-checker.md +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/templates/pm.md +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/templates/run_prompt.md +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/templates/tester.md +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset/workspace.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset_cli.egg-info/dependency_links.txt +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset_cli.egg-info/entry_points.txt +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/src/aiset_cli.egg-info/top_level.txt +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_archmap_cli.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_archmap_go.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_archmap_pyproject.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_atomic.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_brain_graph_files.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_brain_live_link.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_claude_home.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_core.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_encodings.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_file_imports.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_init_team.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_nudge.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_registry.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_repository_paths.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_research.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_run_ac.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_run_board.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_run_claims.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_run_gate.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_run_issue_md.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_run_launch.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_run_pr_body.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_run_refs.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_run_verdicts.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_security.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_settings.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_single_repo.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_task_ids.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_teammap_cli_inputs.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_teammap_lookup.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_teammap_outline.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_teammap_route_frames.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_usage_cost.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_version.py +0 -0
- {aiset_cli-0.3.0 → aiset_cli-0.3.2}/tests/test_workspace_slug.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aiset-cli
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Turn your repos into a team of Claude Code agents with persistent memory, coordinated tasks, and a live dashboard.
|
|
5
5
|
Author: Jamshid Sadik
|
|
6
6
|
License-Expression: MIT
|
|
@@ -83,6 +83,27 @@ Give the PM its first task:
|
|
|
83
83
|
|
|
84
84
|
<br>
|
|
85
85
|
|
|
86
|
+
## Working on two projects at once
|
|
87
|
+
|
|
88
|
+
Each project gets its own team and PM launcher. Open one terminal per project:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
aiset-init ~/work/shop --team shop
|
|
92
|
+
aiset-init ~/work/blog --team blog
|
|
93
|
+
# terminal 1 # terminal 2
|
|
94
|
+
shop-pm blog-pm
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Each office runs on its own port: the first `aiset` takes **http://127.0.0.1:8765**, the next
|
|
98
|
+
one the first free port after it (8766, 8767, ...). It prints its URL, and `aiset --list` shows
|
|
99
|
+
every running office with its team, workspace and URL. Starting `aiset` again for a workspace
|
|
100
|
+
that already has one running opens that office instead of a second copy. An explicit `--port`
|
|
101
|
+
is used as given and fails if it is busy.
|
|
102
|
+
|
|
103
|
+
### Tab titles
|
|
104
|
+
|
|
105
|
+
`<team>-pm` puts the team name in the terminal tab title and sets `CLAUDE_CODE_DISABLE_TERMINAL_TITLE=1`, so Claude Code doesn't replace it with "pm". Launchers made by an older aiset don't do this yet: run `aiset-init <folder> --team <team>` again to rewrite yours (the roster, knowledge briefs and settings are kept).
|
|
106
|
+
|
|
86
107
|
## Why aiset
|
|
87
108
|
|
|
88
109
|
Coding agents start every session from zero. They re-read the same files, rediscover the same conventions and repeat the same investigations, and you can't see what they're doing until they're done.
|
|
@@ -177,7 +198,7 @@ Services, databases and the calls between them, each backed by a file and line.
|
|
|
177
198
|
| `aiset-init <folder> [--team NAME]` | Detect stacks, generate the roster, agents and brief stubs in `<folder>/.claude/`. Safe to re-run: keeps your names, adds new repos. |
|
|
178
199
|
| `<team>-pm` | Start the PM in its workspace from anywhere. The office footer suggests this command when its launcher is on `PATH`. Extra arguments go to Claude Code, e.g. `shop-pm --model sonnet`. |
|
|
179
200
|
| `aiset [--workspace FOLDER\|TEAM]` | Open the office. Without `--workspace`: the workspace you're in, else the team you set up most recently. |
|
|
180
|
-
| `aiset run <issue>` (preview) | Accepts `123`, `#123`, `owner/name#123` or a github.com issue URL. Work a GitHub issue with the team; opens a **draft** PR only after you approve at gate 2. `aiset run --help` for options; `python -m aiset.run <issue>` does the same if an older `aiset` on `PATH` opens the office instead. See the [user guide](docs/USER-GUIDE.md#work-a-github-issue-aiset-run-preview). |
|
|
201
|
+
| `aiset run <issue>` (preview) | Accepts `123`, `#123`, `owner/name#123` or a github.com issue URL. Work a GitHub issue with the team; opens a **draft** PR only after you approve at gate 2. The PR preview and body show the task's estimated API cost, tokens, runs and agents. `aiset run --help` for options; `python -m aiset.run <issue>` does the same if an older `aiset` on `PATH` opens the office instead. See the [user guide](docs/USER-GUIDE.md#work-a-github-issue-aiset-run-preview). |
|
|
181
202
|
| `teammap relevant "<task>"` | Files, symbols, endpoints, brief sections and past episodes to read first. |
|
|
182
203
|
| `teammap impact <path\|symbol\|Model> [METHOD]` | What a change can reach: consumers, models, importers, tests. Exact vs inferred. |
|
|
183
204
|
| `teammap failures <log>` | Failed tests, messages and in-repo frames from a saved test run, grouped. |
|
|
@@ -53,6 +53,27 @@ Give the PM its first task:
|
|
|
53
53
|
|
|
54
54
|
<br>
|
|
55
55
|
|
|
56
|
+
## Working on two projects at once
|
|
57
|
+
|
|
58
|
+
Each project gets its own team and PM launcher. Open one terminal per project:
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
aiset-init ~/work/shop --team shop
|
|
62
|
+
aiset-init ~/work/blog --team blog
|
|
63
|
+
# terminal 1 # terminal 2
|
|
64
|
+
shop-pm blog-pm
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Each office runs on its own port: the first `aiset` takes **http://127.0.0.1:8765**, the next
|
|
68
|
+
one the first free port after it (8766, 8767, ...). It prints its URL, and `aiset --list` shows
|
|
69
|
+
every running office with its team, workspace and URL. Starting `aiset` again for a workspace
|
|
70
|
+
that already has one running opens that office instead of a second copy. An explicit `--port`
|
|
71
|
+
is used as given and fails if it is busy.
|
|
72
|
+
|
|
73
|
+
### Tab titles
|
|
74
|
+
|
|
75
|
+
`<team>-pm` puts the team name in the terminal tab title and sets `CLAUDE_CODE_DISABLE_TERMINAL_TITLE=1`, so Claude Code doesn't replace it with "pm". Launchers made by an older aiset don't do this yet: run `aiset-init <folder> --team <team>` again to rewrite yours (the roster, knowledge briefs and settings are kept).
|
|
76
|
+
|
|
56
77
|
## Why aiset
|
|
57
78
|
|
|
58
79
|
Coding agents start every session from zero. They re-read the same files, rediscover the same conventions and repeat the same investigations, and you can't see what they're doing until they're done.
|
|
@@ -147,7 +168,7 @@ Services, databases and the calls between them, each backed by a file and line.
|
|
|
147
168
|
| `aiset-init <folder> [--team NAME]` | Detect stacks, generate the roster, agents and brief stubs in `<folder>/.claude/`. Safe to re-run: keeps your names, adds new repos. |
|
|
148
169
|
| `<team>-pm` | Start the PM in its workspace from anywhere. The office footer suggests this command when its launcher is on `PATH`. Extra arguments go to Claude Code, e.g. `shop-pm --model sonnet`. |
|
|
149
170
|
| `aiset [--workspace FOLDER\|TEAM]` | Open the office. Without `--workspace`: the workspace you're in, else the team you set up most recently. |
|
|
150
|
-
| `aiset run <issue>` (preview) | Accepts `123`, `#123`, `owner/name#123` or a github.com issue URL. Work a GitHub issue with the team; opens a **draft** PR only after you approve at gate 2. `aiset run --help` for options; `python -m aiset.run <issue>` does the same if an older `aiset` on `PATH` opens the office instead. See the [user guide](docs/USER-GUIDE.md#work-a-github-issue-aiset-run-preview). |
|
|
171
|
+
| `aiset run <issue>` (preview) | Accepts `123`, `#123`, `owner/name#123` or a github.com issue URL. Work a GitHub issue with the team; opens a **draft** PR only after you approve at gate 2. The PR preview and body show the task's estimated API cost, tokens, runs and agents. `aiset run --help` for options; `python -m aiset.run <issue>` does the same if an older `aiset` on `PATH` opens the office instead. See the [user guide](docs/USER-GUIDE.md#work-a-github-issue-aiset-run-preview). |
|
|
151
172
|
| `teammap relevant "<task>"` | Files, symbols, endpoints, brief sections and past episodes to read first. |
|
|
152
173
|
| `teammap impact <path\|symbol\|Model> [METHOD]` | What a change can reach: consumers, models, importers, tests. Exact vs inferred. |
|
|
153
174
|
| `teammap failures <log>` | Failed tests, messages and in-repo frames from a saved test run, grouped. |
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "aiset-cli"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.2"
|
|
8
8
|
description = "Turn your repos into a team of Claude Code agents with persistent memory, coordinated tasks, and a live dashboard."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -95,12 +95,19 @@ def write_launcher(team, path, bin_dir):
|
|
|
95
95
|
target = os.path.join(bin_dir, name + ".cmd")
|
|
96
96
|
# cmd.exe runs claude.cmd here, so PowerShell's script execution policy doesn't apply;
|
|
97
97
|
# setlocal gives the folder back to an interactive cmd.exe when the session ends
|
|
98
|
+
# the tab shows the team name: `title` sets it, and Claude Code is told not to overwrite it
|
|
99
|
+
shown = re.sub(r'[&|<>^"%\x00-\x1f\x7f]', "", team).strip() or "aiset"
|
|
98
100
|
text = (f"@echo off\r\nrem {MARKER} for the {team} team's PM (made by aiset-init)\r\nsetlocal\r\n"
|
|
99
|
-
f'cd /d "{path.replace("%", "%%")}" || exit /b 1\r\
|
|
101
|
+
f'cd /d "{path.replace("%", "%%")}" || exit /b 1\r\n'
|
|
102
|
+
f"title {shown}\r\nset CLAUDE_CODE_DISABLE_TERMINAL_TITLE=1\r\nclaude --agent pm %*\r\n")
|
|
100
103
|
else:
|
|
101
104
|
target = os.path.join(bin_dir, name)
|
|
105
|
+
# control characters in the team name (ESC, BEL, C1 codes) would end or hijack the title sequence
|
|
106
|
+
shown = re.sub(r"[\x00-\x1f\x7f-\x9f]", "", team).strip() or "aiset"
|
|
102
107
|
text = (f"#!/bin/sh\n# {MARKER} for the {team} team's PM (made by aiset-init)\n"
|
|
103
|
-
f"cd {shlex.quote(path)} || exit 1\
|
|
108
|
+
f"cd {shlex.quote(path)} || exit 1\n"
|
|
109
|
+
f"printf '\\033]0;%s\\007' {shlex.quote(shown)}\nexport CLAUDE_CODE_DISABLE_TERMINAL_TITLE=1\n"
|
|
110
|
+
"exec claude --agent pm \"$@\"\n")
|
|
104
111
|
if os.path.exists(target):
|
|
105
112
|
try:
|
|
106
113
|
with open(target, encoding="utf-8", errors="replace") as f:
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""Format one task's usage from `Office.tasks_usage` as text or Markdown."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import math
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _num(value) -> Optional[float]:
|
|
9
|
+
"""A finite int/float (not bool), else None."""
|
|
10
|
+
if isinstance(value, bool) or not isinstance(value, (int, float)) or not math.isfinite(value):
|
|
11
|
+
return None
|
|
12
|
+
return value
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _agents(usage: dict) -> list:
|
|
16
|
+
agents = usage.get("agents") or []
|
|
17
|
+
return [agent for agent in agents if isinstance(agent, dict)] if isinstance(agents, list) else []
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _runs(agent: dict) -> int:
|
|
21
|
+
runs = agent.get("runs")
|
|
22
|
+
return runs if isinstance(runs, int) and not isinstance(runs, bool) and runs > 0 else 0
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _task_tokens(usage: dict) -> Optional[dict]:
|
|
26
|
+
tokens = usage.get("tokens") or {}
|
|
27
|
+
if not isinstance(tokens, dict) or not _num(tokens.get("total")):
|
|
28
|
+
return None
|
|
29
|
+
return tokens if sum(_runs(agent) for agent in _agents(usage)) else None
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _format_tokens(total) -> str:
|
|
33
|
+
total = int(round(_num(total) or 0))
|
|
34
|
+
if total < 1_000:
|
|
35
|
+
return str(total)
|
|
36
|
+
thousands = (total + 500) // 1_000
|
|
37
|
+
if thousands < 1_000:
|
|
38
|
+
return f"{thousands}k"
|
|
39
|
+
return f"{total / 1_000_000:.2f}M"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _format_cost(tokens: dict) -> str:
|
|
43
|
+
cost = _num(tokens.get("cost")) or 0
|
|
44
|
+
if _num(tokens.get("total")):
|
|
45
|
+
if cost == 0:
|
|
46
|
+
return "cost unknown"
|
|
47
|
+
if 0 < cost < 0.01:
|
|
48
|
+
return "<$0.01"
|
|
49
|
+
return f"${cost:.2f}"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _agent_name(agent: dict) -> str:
|
|
53
|
+
return " ".join(str(agent.get("agent") or "").splitlines()).strip() or "unknown"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def cost_line(usage: Optional[dict]) -> str:
|
|
57
|
+
if not isinstance(usage, dict):
|
|
58
|
+
usage = {}
|
|
59
|
+
tokens = _task_tokens(usage)
|
|
60
|
+
if tokens is None:
|
|
61
|
+
return "cost not available (no transcripts found for this task)"
|
|
62
|
+
|
|
63
|
+
agents = _agents(usage)
|
|
64
|
+
runs = sum(_runs(agent) for agent in agents)
|
|
65
|
+
run_label = "run" if runs == 1 else "runs"
|
|
66
|
+
names = []
|
|
67
|
+
for agent in agents:
|
|
68
|
+
name = _agent_name(agent)
|
|
69
|
+
if _runs(agent) > 1:
|
|
70
|
+
name += f" ×{_runs(agent)}"
|
|
71
|
+
names.append(name)
|
|
72
|
+
return (f"{_format_cost(tokens)} · {_format_tokens(tokens.get('total'))} tokens · {runs} {run_label}: "
|
|
73
|
+
f"{', '.join(names)} (estimated at API list prices)")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _table_row(name: str, runs: int, tokens: Optional[dict]) -> str:
|
|
77
|
+
if tokens is None: # agent reported no token data: don't claim $0.00
|
|
78
|
+
return f"| {name} | {runs} | | - | - |"
|
|
79
|
+
by_model = tokens.get("byModel") or {}
|
|
80
|
+
by_model = by_model if isinstance(by_model, dict) else {}
|
|
81
|
+
models = "+".join(sorted(by_model, key=lambda m: _num(by_model[m]) or 0, reverse=True))
|
|
82
|
+
return f"| {name} | {runs} | {models} | {_format_tokens(tokens.get('total'))} | {_format_cost(tokens)} |"
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def cost_table(usage: Optional[dict]) -> str:
|
|
86
|
+
if not isinstance(usage, dict):
|
|
87
|
+
usage = {}
|
|
88
|
+
tokens = _task_tokens(usage)
|
|
89
|
+
if tokens is None:
|
|
90
|
+
return ""
|
|
91
|
+
|
|
92
|
+
rows = ["| Agent | Runs | Model | Tokens | Cost |", "|---|---:|---|---:|---:|"]
|
|
93
|
+
runs = 0
|
|
94
|
+
for agent in _agents(usage):
|
|
95
|
+
name = _agent_name(agent).replace("\\", "\\\\").replace("|", "\\|")
|
|
96
|
+
agent_tokens = agent.get("tokens")
|
|
97
|
+
rows.append(_table_row(name, _runs(agent), agent_tokens if isinstance(agent_tokens, dict) else None))
|
|
98
|
+
runs += _runs(agent)
|
|
99
|
+
rows.append(_table_row("**Total**", runs, tokens))
|
|
100
|
+
return "\n".join(rows)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Board slug and branch name from an issue number and title."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import re
|
|
5
|
+
import unicodedata
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Letters NFKD does not decompose; without this they would be dropped, not folded.
|
|
9
|
+
_FOLD = str.maketrans({
|
|
10
|
+
"ı": "i", "ß": "ss", "ø": "o", "æ": "ae", "đ": "d",
|
|
11
|
+
"Ø": "O", "Æ": "AE", "Đ": "D",
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _slug_words(title: str) -> str:
|
|
16
|
+
normalized = unicodedata.normalize("NFKD", (title or "").translate(_FOLD))
|
|
17
|
+
ascii_title = normalized.encode("ascii", "ignore").decode("ascii")
|
|
18
|
+
return re.sub(r"[^a-z0-9]+", "-", ascii_title.lower()).strip("-")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _cut(head: str, words: str, max_len: int) -> str:
|
|
22
|
+
room = max_len - len(head) - 1
|
|
23
|
+
if room < 1:
|
|
24
|
+
words = "" # `issue-<n>` alone is longer than max_len: it is never cut
|
|
25
|
+
elif len(words) > room:
|
|
26
|
+
words = words[:room + 1]
|
|
27
|
+
words = words[:words.rfind("-")] if "-" in words else ""
|
|
28
|
+
words = words.strip("-")
|
|
29
|
+
return f"{head}-{words}" if words else head
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def board_slug(number: int, title: str, *, max_len: int = 40) -> str:
|
|
33
|
+
return _cut(f"issue-{number}", _slug_words(title), max_len)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def branch_name(number: int, title: str, *, prefix: str = "aiset/", max_len: int = 60) -> str:
|
|
37
|
+
return prefix + _cut(f"issue-{number}", _slug_words(title), max_len - len(prefix))
|
|
@@ -124,7 +124,7 @@ def render_pr_body(pr: PrInput) -> str:
|
|
|
124
124
|
parts += [f"- [{c.label}] {neutralize(c.text)}" for c in pr.open_claims]
|
|
125
125
|
counts = pr.claim_counts
|
|
126
126
|
parts += ["", f"Claims: {counts.get('V', 0)} verified · {counts.get('S', 0)} assumed · {counts.get('?', 0)} open",
|
|
127
|
-
"", "## Cost", pr.cost, "",
|
|
127
|
+
"", "## Cost", neutralize(pr.cost), "",
|
|
128
128
|
f"<sub>Board `{pr.board}` · branch `{pr.branch}`</sub>"]
|
|
129
129
|
body = "\n".join(parts)
|
|
130
130
|
room = MAX_CHARS - len(closes) - 2
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Make hidden characters in issue text visible and count HTML comments."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import re
|
|
5
|
+
import unicodedata
|
|
6
|
+
|
|
7
|
+
from .datatypes import Visible
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
_HIDDEN_CATEGORIES = {"Cf": "format", "Cc": "control", "Co": "private"}
|
|
11
|
+
_HTML_COMMENT = re.compile(r"<!--.*?(?:-->|\Z)", re.DOTALL)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def visible_text(text: str) -> Visible:
|
|
15
|
+
text = (text or "").replace("\r\n", "\n").replace("\r", "\n")
|
|
16
|
+
comments = sum(1 for _ in _HTML_COMMENT.finditer(text))
|
|
17
|
+
counts = {}
|
|
18
|
+
fragments = []
|
|
19
|
+
for index, char in enumerate(text):
|
|
20
|
+
codepoint = ord(char)
|
|
21
|
+
if 0xE0000 <= codepoint <= 0xE007F:
|
|
22
|
+
kind = "tag"
|
|
23
|
+
elif char in "\n\t":
|
|
24
|
+
kind = None
|
|
25
|
+
elif (char == "\u200d" and 0 < index < len(text) - 1
|
|
26
|
+
and unicodedata.category(text[index - 1]) == "So"
|
|
27
|
+
and unicodedata.category(text[index + 1]) == "So"):
|
|
28
|
+
kind = None
|
|
29
|
+
else:
|
|
30
|
+
kind = _HIDDEN_CATEGORIES.get(unicodedata.category(char))
|
|
31
|
+
|
|
32
|
+
if kind is None:
|
|
33
|
+
fragments.append(char)
|
|
34
|
+
else:
|
|
35
|
+
fragments.append(f"<U+{codepoint:04X}>")
|
|
36
|
+
counts[kind] = counts.get(kind, 0) + 1
|
|
37
|
+
|
|
38
|
+
if comments:
|
|
39
|
+
counts["html_comment"] = comments
|
|
40
|
+
return Visible("".join(fragments), counts)
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""The offices running right now, so a second office can find the first and `aiset --list` can show them.
|
|
2
|
+
|
|
3
|
+
<home>/running/<pid>.json {"pid": 1234, "workspace": "C:/work/shop", "team": "shop",
|
|
4
|
+
"port": 8765, "url": "http://127.0.0.1:8765", "started": "..."}
|
|
5
|
+
|
|
6
|
+
An office writes its entry when it starts and removes it on exit. A crash (or, on Windows, closing the
|
|
7
|
+
terminal tab) leaves the file behind, so reading skips entries whose pid is dead and deletes them. A
|
|
8
|
+
pid can be reused by an unrelated process, so find() also asks the office itself over HTTP before it
|
|
9
|
+
trusts an entry. No side effects on import.
|
|
10
|
+
"""
|
|
11
|
+
import ctypes
|
|
12
|
+
import datetime
|
|
13
|
+
import functools
|
|
14
|
+
import glob
|
|
15
|
+
import http.client
|
|
16
|
+
import json
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
from . import registry
|
|
20
|
+
from .atomic import write_text_atomic
|
|
21
|
+
|
|
22
|
+
_STILL_ACTIVE = 259
|
|
23
|
+
_ERROR_ACCESS_DENIED = 5
|
|
24
|
+
_PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
|
|
25
|
+
PROBE_TIMEOUT = 1.5 # seconds an office gets to answer find()'s check
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _dir():
|
|
29
|
+
return os.path.join(registry.home(), "running")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _key(path):
|
|
33
|
+
return os.path.normcase(os.path.realpath(path))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@functools.lru_cache(maxsize=None)
|
|
37
|
+
def _kernel32():
|
|
38
|
+
"""A private kernel32 handle (Windows only) with typed functions, so no other code's settings on the
|
|
39
|
+
shared ctypes.windll leak in, and with use_last_error so ctypes.get_last_error() is reliable."""
|
|
40
|
+
from ctypes import wintypes
|
|
41
|
+
k = ctypes.WinDLL("kernel32", use_last_error=True)
|
|
42
|
+
k.OpenProcess.argtypes = (wintypes.DWORD, wintypes.BOOL, wintypes.DWORD)
|
|
43
|
+
k.OpenProcess.restype = wintypes.HANDLE
|
|
44
|
+
k.GetExitCodeProcess.argtypes = (wintypes.HANDLE, ctypes.POINTER(wintypes.DWORD))
|
|
45
|
+
k.GetExitCodeProcess.restype = wintypes.BOOL
|
|
46
|
+
k.CloseHandle.argtypes = (wintypes.HANDLE,)
|
|
47
|
+
k.CloseHandle.restype = wintypes.BOOL
|
|
48
|
+
return k
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def pid_alive(pid):
|
|
52
|
+
"""True if a process with this pid exists. Works on Windows, where os.kill(pid, 0) would kill it."""
|
|
53
|
+
if pid <= 0:
|
|
54
|
+
return False
|
|
55
|
+
if os.name == "nt":
|
|
56
|
+
if pid > 0xFFFFFFFF: # not a Windows pid (a DWORD)
|
|
57
|
+
return False
|
|
58
|
+
from ctypes import wintypes
|
|
59
|
+
kernel32 = _kernel32()
|
|
60
|
+
handle = kernel32.OpenProcess(_PROCESS_QUERY_LIMITED_INFORMATION, False, pid)
|
|
61
|
+
if not handle:
|
|
62
|
+
return ctypes.get_last_error() == _ERROR_ACCESS_DENIED # exists, but not ours
|
|
63
|
+
try:
|
|
64
|
+
code = wintypes.DWORD()
|
|
65
|
+
if not kernel32.GetExitCodeProcess(handle, ctypes.byref(code)):
|
|
66
|
+
return True
|
|
67
|
+
return code.value == _STILL_ACTIVE
|
|
68
|
+
finally:
|
|
69
|
+
kernel32.CloseHandle(handle)
|
|
70
|
+
try:
|
|
71
|
+
os.kill(pid, 0)
|
|
72
|
+
except ProcessLookupError:
|
|
73
|
+
return False
|
|
74
|
+
except PermissionError:
|
|
75
|
+
return True
|
|
76
|
+
except OSError:
|
|
77
|
+
return False
|
|
78
|
+
return True
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def register(workspace, team, port):
|
|
82
|
+
"""Record this office. Returns the entry's path, to pass to unregister()."""
|
|
83
|
+
url = f"http://127.0.0.1:{port}"
|
|
84
|
+
entry = {
|
|
85
|
+
"pid": os.getpid(),
|
|
86
|
+
"workspace": os.path.abspath(workspace) if workspace else "",
|
|
87
|
+
"team": team,
|
|
88
|
+
"port": port,
|
|
89
|
+
"url": url,
|
|
90
|
+
"started": datetime.datetime.now().isoformat(timespec="seconds"),
|
|
91
|
+
}
|
|
92
|
+
os.makedirs(_dir(), exist_ok=True)
|
|
93
|
+
path = os.path.join(_dir(), f"{os.getpid()}.json")
|
|
94
|
+
write_text_atomic(path, json.dumps(entry, indent=2, ensure_ascii=False) + "\n", newline="\n")
|
|
95
|
+
return path
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def unregister(path):
|
|
99
|
+
try:
|
|
100
|
+
os.remove(path)
|
|
101
|
+
except OSError:
|
|
102
|
+
pass # already gone (another office cleaned it up) or not ours to delete: nothing to do
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def running(check=False):
|
|
106
|
+
"""The offices that are still alive, oldest first. Entries of dead processes are deleted, and with
|
|
107
|
+
check=True so are entries whose office doesn't answer on its port (see answers())."""
|
|
108
|
+
found = []
|
|
109
|
+
for path in glob.glob(os.path.join(_dir(), "*.json")):
|
|
110
|
+
try:
|
|
111
|
+
with open(path, encoding="utf-8-sig") as f:
|
|
112
|
+
entry = json.load(f)
|
|
113
|
+
except (OSError, ValueError):
|
|
114
|
+
continue
|
|
115
|
+
if not isinstance(entry, dict):
|
|
116
|
+
continue
|
|
117
|
+
pid = entry.get("pid")
|
|
118
|
+
if not isinstance(pid, int) or not pid_alive(pid) or (check and not answers(entry)):
|
|
119
|
+
unregister(path)
|
|
120
|
+
continue
|
|
121
|
+
entry["_file"] = path
|
|
122
|
+
found.append(entry)
|
|
123
|
+
return sorted(found, key=lambda e: str(e.get("started", "")))
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def answers(entry, timeout=PROBE_TIMEOUT):
|
|
127
|
+
"""True if the office in this entry answers on its port: GET /api/settings with the Host header the
|
|
128
|
+
office accepts, a 200 with JSON, and (when the entry names one) the same workspace. A pid that was
|
|
129
|
+
reused by an unrelated process, or a port now held by another office, fails this check."""
|
|
130
|
+
port = entry.get("port")
|
|
131
|
+
if not isinstance(port, int) or not 0 < port < 65536:
|
|
132
|
+
return False
|
|
133
|
+
conn = http.client.HTTPConnection("127.0.0.1", port, timeout=timeout)
|
|
134
|
+
try:
|
|
135
|
+
conn.request("GET", "/api/settings", headers={"Host": f"127.0.0.1:{port}", "Accept": "application/json"})
|
|
136
|
+
resp = conn.getresponse()
|
|
137
|
+
if resp.status != 200:
|
|
138
|
+
return False
|
|
139
|
+
data = json.loads(resp.read().decode("utf-8", "replace"))
|
|
140
|
+
except (OSError, ValueError, http.client.HTTPException):
|
|
141
|
+
return False
|
|
142
|
+
finally:
|
|
143
|
+
conn.close()
|
|
144
|
+
if not isinstance(data, dict):
|
|
145
|
+
return False
|
|
146
|
+
paths = data.get("paths") if isinstance(data.get("paths"), dict) else {}
|
|
147
|
+
want, got = entry.get("workspace") or "", paths.get("workspace") or ""
|
|
148
|
+
if want or got:
|
|
149
|
+
return bool(want and got) and _key(want) == _key(got)
|
|
150
|
+
return True
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def find(workspace):
|
|
154
|
+
"""The running office for this workspace folder (normalised compare), or None.
|
|
155
|
+
|
|
156
|
+
An entry whose office doesn't answer (see answers()) is stale: it is deleted and the search goes on."""
|
|
157
|
+
if not workspace:
|
|
158
|
+
return None
|
|
159
|
+
key = _key(workspace)
|
|
160
|
+
for entry in running():
|
|
161
|
+
if entry.get("workspace") and _key(entry["workspace"]) == key:
|
|
162
|
+
if answers(entry):
|
|
163
|
+
return entry
|
|
164
|
+
unregister(entry["_file"])
|
|
165
|
+
return None
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""aiset: a live office view of your Claude Code agent team, in the browser.
|
|
3
3
|
|
|
4
|
-
aiset start on http://127.0.0.1:8765 and open the browser
|
|
5
|
-
|
|
4
|
+
aiset start on http://127.0.0.1:8765 and open the browser; if 8765 is busy,
|
|
5
|
+
the first free port from 8766 to 8784 (or any free port). If this
|
|
6
|
+
workspace already has an office running, its URL is shown and
|
|
7
|
+
opened instead of starting a second one
|
|
8
|
+
aiset --port 9000 use this port exactly (an error if it is busy)
|
|
9
|
+
aiset --list list the offices running now (team, workspace, URL) and exit
|
|
6
10
|
aiset --hours 24 include agents active in the last 24 hours (default 12)
|
|
7
11
|
aiset --no-browser don't open a browser tab
|
|
8
12
|
aiset --brain-days 60 how far back the Brain page looks (default 30)
|
|
@@ -10,7 +14,8 @@
|
|
|
10
14
|
(default: the workspace you're in, else the team aiset-init set up most
|
|
11
15
|
recently, else the original ~/.claude team)
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
Two projects at once: open a terminal per project (<team>-pm) and run aiset in each; the offices
|
|
18
|
+
get their own ports. Settings (/settings) edits the roster (names, roles, colours, duties, models) and the office's
|
|
14
19
|
own options (<team>/settings.json); --hours and --brain-days override the stored windows.
|
|
15
20
|
"""
|
|
16
21
|
import argparse
|
|
@@ -29,7 +34,7 @@ if __name__ == "__main__" and not __package__: # run as a file: python src/aise
|
|
|
29
34
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
|
|
30
35
|
__package__ = "aiset"
|
|
31
36
|
HERE = os.path.dirname(os.path.realpath(__file__))
|
|
32
|
-
from . import registry # noqa: E402
|
|
37
|
+
from . import registry, running # noqa: E402
|
|
33
38
|
from .atomic import write_text_atomic # noqa: E402
|
|
34
39
|
|
|
35
40
|
# every module reads its paths from workspace.py on import, so settle the workspace first:
|
|
@@ -295,18 +300,55 @@ class Handler(BaseHTTPRequestHandler):
|
|
|
295
300
|
return self._send(200, json.dumps(self.settings_payload()).encode(), "application/json")
|
|
296
301
|
|
|
297
302
|
|
|
303
|
+
DEFAULT_PORT = 8765
|
|
304
|
+
PORT_TRIES = 20 # 8765..8784, then the system picks a free port (port 0)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
class OfficeServer(ThreadingHTTPServer):
|
|
308
|
+
# on Windows SO_REUSEADDR lets a second office bind a port another office is already using,
|
|
309
|
+
# so a busy port has to fail there; elsewhere it stays on, so a quick restart isn't blocked
|
|
310
|
+
allow_reuse_address = os.name != "nt"
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def bind_office(port):
|
|
314
|
+
"""An OfficeServer on 127.0.0.1. With port None (not given), a busy DEFAULT_PORT moves on."""
|
|
315
|
+
if port is not None:
|
|
316
|
+
return OfficeServer(("127.0.0.1", port), Handler)
|
|
317
|
+
for candidate in range(DEFAULT_PORT, DEFAULT_PORT + PORT_TRIES):
|
|
318
|
+
try:
|
|
319
|
+
return OfficeServer(("127.0.0.1", candidate), Handler)
|
|
320
|
+
except OSError as e:
|
|
321
|
+
if not (e.errno == errno.EADDRINUSE or isinstance(e, PermissionError)):
|
|
322
|
+
raise
|
|
323
|
+
return OfficeServer(("127.0.0.1", 0), Handler) # all of them busy: the system picks a free port
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def print_running():
|
|
327
|
+
offices = running.running(check=True) # a record left by a closed tab whose pid was reused is dropped
|
|
328
|
+
if not offices:
|
|
329
|
+
print("No aiset office is running.")
|
|
330
|
+
return
|
|
331
|
+
print("Running aiset offices:")
|
|
332
|
+
for office in offices:
|
|
333
|
+
print(f" {office.get('team', '?')} {office.get('workspace') or '(the original ~/.claude team)'} {office.get('url', '')}")
|
|
334
|
+
|
|
335
|
+
|
|
298
336
|
def main():
|
|
299
337
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace") # Windows consoles default to cp1252
|
|
300
338
|
ap = argparse.ArgumentParser(description="Live office view of your Claude Code agents.",
|
|
301
339
|
epilog="Also: aiset run <issue> works a GitHub issue with the team and opens a draft PR after your approval (aiset run --help).")
|
|
302
340
|
from . import __version__
|
|
303
341
|
ap.add_argument("--version", action="version", version="aiset " + __version__)
|
|
304
|
-
ap.add_argument("--port", type=int, default=
|
|
342
|
+
ap.add_argument("--port", type=int, default=None, help=f"exact port (default: {DEFAULT_PORT}, or the next free one)")
|
|
305
343
|
ap.add_argument("--hours", type=float, help="show agents active within this many hours (default: Settings, 12)")
|
|
306
344
|
ap.add_argument("--brain-days", type=float, help="how far back the Brain page looks (default: Settings, 30)")
|
|
307
345
|
ap.add_argument("--no-browser", action="store_true")
|
|
346
|
+
ap.add_argument("--list", action="store_true", help="list the offices running now and exit")
|
|
308
347
|
ap.add_argument("--workspace", help="folder made by init_team.py, or its team name (read before argparse, see top of file)")
|
|
309
348
|
args = ap.parse_args()
|
|
349
|
+
if args.list:
|
|
350
|
+
print_running()
|
|
351
|
+
return
|
|
310
352
|
if args.workspace and not os.path.isfile(workspace.ROSTER):
|
|
311
353
|
sys.exit(f"no team in {workspace.WORKSPACE} (expected {workspace.ROSTER}).\n"
|
|
312
354
|
"Run init_team.py on it first. In Git Bash write the path with / (C:/Users/... or /c/Users/...), not \\.")
|
|
@@ -320,32 +362,49 @@ def main():
|
|
|
320
362
|
elif not workspace.WORKSPACE:
|
|
321
363
|
print("No workspace found and no team set up with aiset-init: showing the original ~/.claude team.\n"
|
|
322
364
|
" Run aiset-init <folder> first, or use --workspace <folder>.")
|
|
365
|
+
ws, team = workspace.WORKSPACE or "", roster.get("team", "Agent")
|
|
366
|
+
existing = running.find(ws)
|
|
367
|
+
if existing:
|
|
368
|
+
print(f"aiset: the {existing.get('team', team)} office is already running at {existing['url']}")
|
|
369
|
+
if not args.no_browser:
|
|
370
|
+
webbrowser.open(existing["url"])
|
|
371
|
+
return
|
|
323
372
|
stored = settings.load()
|
|
324
|
-
Handler.fixed_hours, Handler.fixed_days, Handler.port = args.hours is not None, args.brain_days is not None, args.port
|
|
373
|
+
Handler.fixed_hours, Handler.fixed_days, Handler.port = args.hours is not None, args.brain_days is not None, DEFAULT_PORT if args.port is None else args.port
|
|
325
374
|
Handler.office = Office(roster, args.hours if Handler.fixed_hours else stored["hours"])
|
|
326
375
|
Handler.brain_office = Office(roster, (args.brain_days if Handler.fixed_days else stored["brainDays"]) * 24)
|
|
327
376
|
Handler.office.history = Handler.brain_office
|
|
328
377
|
try:
|
|
329
|
-
server =
|
|
378
|
+
server = bind_office(args.port)
|
|
330
379
|
except OSError as e:
|
|
380
|
+
shown = DEFAULT_PORT if args.port is None else args.port
|
|
331
381
|
if e.errno == errno.EADDRINUSE or isinstance(e, PermissionError):
|
|
332
382
|
detail = " (port in use or unavailable; another aiset office may be running)"
|
|
333
383
|
else:
|
|
334
384
|
detail = f": {e.strerror or e}"
|
|
335
385
|
sys.exit(
|
|
336
|
-
f"aiset: can't listen on 127.0.0.1:{
|
|
337
|
-
f"Open http://127.0.0.1:{
|
|
386
|
+
f"aiset: can't listen on 127.0.0.1:{shown}{detail}. "
|
|
387
|
+
f"Open http://127.0.0.1:{shown}, or start with --port 0 for a free port."
|
|
338
388
|
)
|
|
339
|
-
Handler.port = server.server_address[1] # the real port, also when --port 0 picked one
|
|
389
|
+
Handler.port = server.server_address[1] # the real port, also when --port 0 or a fallback picked one
|
|
340
390
|
url = f"http://127.0.0.1:{Handler.port}"
|
|
341
391
|
print(f"🏢 {roster.get('team', 'Agent')} office running at {url} (Ctrl+C to stop)")
|
|
342
392
|
print(f" team: {workspace.TEAM}")
|
|
393
|
+
try:
|
|
394
|
+
entry = running.register(ws, team, Handler.port)
|
|
395
|
+
except OSError as e:
|
|
396
|
+
entry = None
|
|
397
|
+
print(f" (not listed in aiset --list: {e})")
|
|
343
398
|
if not args.no_browser:
|
|
344
399
|
threading.Timer(0.5, lambda: webbrowser.open(url)).start()
|
|
345
400
|
try:
|
|
346
401
|
server.serve_forever()
|
|
347
402
|
except KeyboardInterrupt:
|
|
348
403
|
print("\nbye")
|
|
404
|
+
finally:
|
|
405
|
+
if entry:
|
|
406
|
+
running.unregister(entry)
|
|
407
|
+
server.server_close()
|
|
349
408
|
|
|
350
409
|
|
|
351
410
|
if __name__ == "__main__":
|