agent-timelines 0.2.0__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.
Files changed (25) hide show
  1. agent_timelines-0.2.0/LICENSE +24 -0
  2. agent_timelines-0.2.0/PKG-INFO +153 -0
  3. agent_timelines-0.2.0/README.md +126 -0
  4. agent_timelines-0.2.0/pyproject.toml +39 -0
  5. agent_timelines-0.2.0/setup.cfg +4 -0
  6. agent_timelines-0.2.0/src/agent_timelines/__init__.py +0 -0
  7. agent_timelines-0.2.0/src/agent_timelines/__main__.py +3 -0
  8. agent_timelines-0.2.0/src/agent_timelines/actors.js +202 -0
  9. agent_timelines-0.2.0/src/agent_timelines/assets/LICENSES.txt +98 -0
  10. agent_timelines-0.2.0/src/agent_timelines/assets/PressStart2P-Regular.ttf +0 -0
  11. agent_timelines-0.2.0/src/agent_timelines/assets/one-bit.png +0 -0
  12. agent_timelines-0.2.0/src/agent_timelines/assets/tiny-dungeon.png +0 -0
  13. agent_timelines-0.2.0/src/agent_timelines/cli.py +197 -0
  14. agent_timelines-0.2.0/src/agent_timelines/dungeon.js +211 -0
  15. agent_timelines-0.2.0/src/agent_timelines/gantt.js +63 -0
  16. agent_timelines-0.2.0/src/agent_timelines/lobby.js +46 -0
  17. agent_timelines-0.2.0/src/agent_timelines/timeline.py +579 -0
  18. agent_timelines-0.2.0/src/agent_timelines/viewer.html +474 -0
  19. agent_timelines-0.2.0/src/agent_timelines.egg-info/PKG-INFO +153 -0
  20. agent_timelines-0.2.0/src/agent_timelines.egg-info/SOURCES.txt +23 -0
  21. agent_timelines-0.2.0/src/agent_timelines.egg-info/dependency_links.txt +1 -0
  22. agent_timelines-0.2.0/src/agent_timelines.egg-info/entry_points.txt +2 -0
  23. agent_timelines-0.2.0/src/agent_timelines.egg-info/top_level.txt +1 -0
  24. agent_timelines-0.2.0/tests/test_cli.py +99 -0
  25. agent_timelines-0.2.0/tests/test_timeline.py +342 -0
@@ -0,0 +1,24 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 jasondasuki
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ Bundled third-party assets (sprites and font) keep their own licenses:
24
+ see src/agent_timelines/assets/LICENSES.txt.
@@ -0,0 +1,153 @@
1
+ Metadata-Version: 2.4
2
+ Name: agent-timelines
3
+ Version: 0.2.0
4
+ Summary: Live delegation graph of Claude Code sessions and their subagents
5
+ Author: jasondasuki
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/jasondasuki/agent-timelines
8
+ Project-URL: Source, https://github.com/jasondasuki/agent-timelines
9
+ Project-URL: Issues, https://github.com/jasondasuki/agent-timelines/issues
10
+ Keywords: claude-code,claude,agents,subagents,dashboard,observability,pixel-art
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Operating System :: MacOS
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Environment :: Console
20
+ Classifier: Intended Audience :: Developers
21
+ Classifier: Topic :: Software Development :: Debuggers
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ License-File: src/agent_timelines/assets/LICENSES.txt
26
+ Dynamic: license-file
27
+
28
+ # agent-timelines
29
+
30
+ [![CI](https://github.com/jasondasuki/agent-timelines/actions/workflows/ci.yml/badge.svg)](https://github.com/jasondasuki/agent-timelines/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jasondasuki/agent-timelines/blob/main/LICENSE)
31
+
32
+ A pixel-art dashboard for Claude Code sessions. It shows which agent spawned which, the model and effort
33
+ requested vs. what actually ran, tool calls, weighted token cost and dollars, handoffs and Workflow runs, live while the
34
+ session works. Everything is read from your local transcripts; nothing leaves your machine.
35
+
36
+ ![Chart view: the delegation tree as a party of heroes, with one hero's detail panel open](https://raw.githubusercontent.com/jasondasuki/agent-timelines/main/docs/chart.jpg)
37
+
38
+ - **Lobby**: your 200 most recent sessions as a retro game-server list (live dungeons + hall of records), with search, a project filter and
39
+ paging (`/` focuses the search box, left/right change the page).
40
+ - **Chart view**: the delegation tree as a party of heroes, with flags for rule breaks (no model set,
41
+ model mismatch, ignored tool limit, unanswered handoff, …).
42
+ Each card shows the agent's top tools and the start of its final reply; the detail panel lists every tool and the full report
43
+ (a running agent shows what it is saying now).
44
+ - **Timeline view**: one bar per agent on a shared clock, rows in party-tree order, so you can see who ran when and what overlapped.
45
+ Running agents get a striped bar; zoom with + and -.
46
+ - **Map view**: the same session as a procedurally generated dungeon. The main session is the guild master
47
+ in the guild hall; each agent has its own room and fights an enemy while it works, then celebrates.
48
+
49
+ ![Lobby: live dungeons and the hall of records](https://raw.githubusercontent.com/jasondasuki/agent-timelines/main/docs/lobby.jpg)
50
+ ![Map view: a procedurally generated dungeon with one room per agent](https://raw.githubusercontent.com/jasondasuki/agent-timelines/main/docs/map.jpg)
51
+
52
+ (The screenshots show a synthetic demo session.)
53
+
54
+ ## Install
55
+
56
+ Needs Python 3.9+ on macOS or Linux (Windows is not supported). No other dependencies. Use one of the two options, not both.
57
+
58
+ **Option A: the command-line tool from PyPI** (needs [uv](https://docs.astral.sh/uv/) or pipx)
59
+
60
+ ```sh
61
+ uv tool install agent-timelines # or: pipx install agent-timelines
62
+ agent-timelines install # adds 6 hooks to ~/.claude/settings.json (writes a backup next to it first)
63
+ agent-timelines rebuild # optional: fills the lobby with your sessions from the last 30 days
64
+ agent-timelines serve # opens http://127.0.0.1:8765/index.html (localhost only)
65
+ ```
66
+
67
+ **Option B: the Claude Code plugin** (no pip, no settings.json edit; the hooks come with the plugin)
68
+
69
+ ```sh
70
+ claude plugin marketplace add jasondasuki/agent-timelines
71
+ claude plugin install agent-timelines@agent-timelines
72
+ ```
73
+
74
+ Then ask for the dashboard with `/agent-timelines:dashboard`. The plugin's hooks run `python3` from your PATH, so Python 3.9+ must be there.
75
+ If `agent-timelines install` hooks are also in settings.json, the plugin's hooks stay quiet so nothing is built twice.
76
+
77
+ Start or continue a Claude Code session; it appears in the lobby on its first hook event.
78
+
79
+ | Command | What it does |
80
+ |---|---|
81
+ | `install [--settings PATH]` | Add the hooks (replaces earlier agent-timelines hooks, keeps all others). |
82
+ | `uninstall [--settings PATH]` | Remove the hooks. Your data folder stays. |
83
+ | `serve [--port N] [--no-browser]` | Serve the dashboard on 127.0.0.1. |
84
+ | `open [SESSION-PREFIX]` | Build one session (newest by default) and open it from disk, no server. |
85
+ | `rebuild [--days N]` | Regenerate data for recent sessions from their transcripts. |
86
+ | `list` | Recent sessions with their subagent counts. |
87
+
88
+ `--settings` targets another Claude config dir, e.g. `--settings ~/.claude-work/settings.json`.
89
+ `CLAUDE_CONFIG_DIR` is respected for the default paths.
90
+
91
+ Data lives in `~/.claude/agent-timelines/` (one `<session>.data.js` and one `<session>.prompts.js` per session, removed after 30 days untouched).
92
+ The pages hold prompt text from your sessions, which is why `serve` binds to localhost only and refuses requests that come from other sites (wrong `Host`, or a cross-site script or fetch).
93
+
94
+ ## Config (optional)
95
+
96
+ `~/.config/agent-timelines/config.json` (or `$AGENT_TIMELINES_CONFIG`). Every key is optional:
97
+
98
+ ```json
99
+ {
100
+ "out_dir": "~/.claude/agent-timelines",
101
+ "ctx_limit": 200000,
102
+ "tool_limit": 50,
103
+ "brief_limit": 8000,
104
+ "retain_days": 30,
105
+ "lobby_limit": 200,
106
+ "handover_dir": "~/.claude/handovers",
107
+ "agents_dir": "~/.claude/agents",
108
+ "guard_text": "Main session does not execute",
109
+ "tiers": {"Explore": "scanner", "Plan": "plan", "general-purpose": "executor"},
110
+ "rules": {"no-model": true, "no-effort": true},
111
+ "prices": {"gpt-6": {"in": 1, "out": 2}}
112
+ }
113
+ ```
114
+
115
+ `tool_limit` is unset by default, so there are no hearts, only a tool count; set it to the number your hand-off hook uses.
116
+ `brief_limit`, `guard_text` and `handover_dir` match optional hand-off and guard hooks of your own;
117
+ without such hooks those flags never fire. `tiers` maps agent types to character classes.
118
+ `rules` turns single flags on or off by name; a flag you do not list keeps its default. `no-model` and `no-effort` are off by default;
119
+ turn them on if your setup requires every spawn to name a model and effort. The flag names are `no-model`, `no-effort`, `auto-filled`,
120
+ `frontmatter`, `model-mismatch`, `effort-mismatch`, `ctx` (the context-size flag), `handoff`, `tool-limit`, `ignored-limit`, `orphan`
121
+ and `handoff-not-continued`; an unknown name is an error.
122
+
123
+ `prices` adds or changes entries of the built-in price table (USD per million tokens; the table is dated, see `PRICES_ASOF` in `timeline.py`).
124
+ The key is a model id prefix without `claude-`, the longest matching key wins, and the columns are `in`, `cc5` (5-minute cache write),
125
+ `cc1` (1-hour cache write), `cr` (cache read), `out` and an optional `over` (`[prompt tokens, multiplier]`); a missing column counts as 0.
126
+ Entries are merged per model, so you only list what you add or change. A model with no price is shown as unpriced (`$0.00+` on its card),
127
+ never guessed.
128
+
129
+ ### Cost
130
+
131
+ Cost is computed per message from the full model id and the usage recorded in the transcript, at Anthropic first-party API list prices
132
+ ([pricing page](https://platform.claude.com/docs/en/about-claude/pricing), table dated 2026-11-10). It is what those tokens would cost through the
133
+ API; a subscription plan is not billed per token. Not modelled: the 1.1x US-only `inference_geo` surcharge (the transcript does not say whether it
134
+ applied), batch discounts, Bedrock and Vertex prices, web-search and other server-tool fees. Gold is the same tokens weighted by cost, as before.
135
+
136
+ ## Development
137
+
138
+ ```sh
139
+ python3 tests/test_timeline.py && python3 tests/test_cli.py # Python
140
+ node tests/test_dungeon.js && node tests/test_actors.js && node tests/test_lobby.js && node tests/test_gantt.js # viewer scripts (Node 18+)
141
+ open dev/dungeon-demo.html # dungeon playground: agents, working, reset
142
+ ```
143
+
144
+ ## Credits
145
+
146
+ - Sprites: [Kenney](https://www.kenney.nl) "Tiny Dungeon" and "1-Bit Pack", CC0.
147
+ - Font: Press Start 2P by CodeMan38, SIL Open Font License 1.1.
148
+
149
+ Details in `src/agent_timelines/assets/LICENSES.txt`.
150
+
151
+ ## License
152
+
153
+ MIT, see [LICENSE](https://github.com/jasondasuki/agent-timelines/blob/main/LICENSE). Contributions welcome: see [CONTRIBUTING.md](https://github.com/jasondasuki/agent-timelines/blob/main/CONTRIBUTING.md). Security reports: [SECURITY.md](https://github.com/jasondasuki/agent-timelines/blob/main/SECURITY.md).
@@ -0,0 +1,126 @@
1
+ # agent-timelines
2
+
3
+ [![CI](https://github.com/jasondasuki/agent-timelines/actions/workflows/ci.yml/badge.svg)](https://github.com/jasondasuki/agent-timelines/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jasondasuki/agent-timelines/blob/main/LICENSE)
4
+
5
+ A pixel-art dashboard for Claude Code sessions. It shows which agent spawned which, the model and effort
6
+ requested vs. what actually ran, tool calls, weighted token cost and dollars, handoffs and Workflow runs, live while the
7
+ session works. Everything is read from your local transcripts; nothing leaves your machine.
8
+
9
+ ![Chart view: the delegation tree as a party of heroes, with one hero's detail panel open](https://raw.githubusercontent.com/jasondasuki/agent-timelines/main/docs/chart.jpg)
10
+
11
+ - **Lobby**: your 200 most recent sessions as a retro game-server list (live dungeons + hall of records), with search, a project filter and
12
+ paging (`/` focuses the search box, left/right change the page).
13
+ - **Chart view**: the delegation tree as a party of heroes, with flags for rule breaks (no model set,
14
+ model mismatch, ignored tool limit, unanswered handoff, …).
15
+ Each card shows the agent's top tools and the start of its final reply; the detail panel lists every tool and the full report
16
+ (a running agent shows what it is saying now).
17
+ - **Timeline view**: one bar per agent on a shared clock, rows in party-tree order, so you can see who ran when and what overlapped.
18
+ Running agents get a striped bar; zoom with + and -.
19
+ - **Map view**: the same session as a procedurally generated dungeon. The main session is the guild master
20
+ in the guild hall; each agent has its own room and fights an enemy while it works, then celebrates.
21
+
22
+ ![Lobby: live dungeons and the hall of records](https://raw.githubusercontent.com/jasondasuki/agent-timelines/main/docs/lobby.jpg)
23
+ ![Map view: a procedurally generated dungeon with one room per agent](https://raw.githubusercontent.com/jasondasuki/agent-timelines/main/docs/map.jpg)
24
+
25
+ (The screenshots show a synthetic demo session.)
26
+
27
+ ## Install
28
+
29
+ Needs Python 3.9+ on macOS or Linux (Windows is not supported). No other dependencies. Use one of the two options, not both.
30
+
31
+ **Option A: the command-line tool from PyPI** (needs [uv](https://docs.astral.sh/uv/) or pipx)
32
+
33
+ ```sh
34
+ uv tool install agent-timelines # or: pipx install agent-timelines
35
+ agent-timelines install # adds 6 hooks to ~/.claude/settings.json (writes a backup next to it first)
36
+ agent-timelines rebuild # optional: fills the lobby with your sessions from the last 30 days
37
+ agent-timelines serve # opens http://127.0.0.1:8765/index.html (localhost only)
38
+ ```
39
+
40
+ **Option B: the Claude Code plugin** (no pip, no settings.json edit; the hooks come with the plugin)
41
+
42
+ ```sh
43
+ claude plugin marketplace add jasondasuki/agent-timelines
44
+ claude plugin install agent-timelines@agent-timelines
45
+ ```
46
+
47
+ Then ask for the dashboard with `/agent-timelines:dashboard`. The plugin's hooks run `python3` from your PATH, so Python 3.9+ must be there.
48
+ If `agent-timelines install` hooks are also in settings.json, the plugin's hooks stay quiet so nothing is built twice.
49
+
50
+ Start or continue a Claude Code session; it appears in the lobby on its first hook event.
51
+
52
+ | Command | What it does |
53
+ |---|---|
54
+ | `install [--settings PATH]` | Add the hooks (replaces earlier agent-timelines hooks, keeps all others). |
55
+ | `uninstall [--settings PATH]` | Remove the hooks. Your data folder stays. |
56
+ | `serve [--port N] [--no-browser]` | Serve the dashboard on 127.0.0.1. |
57
+ | `open [SESSION-PREFIX]` | Build one session (newest by default) and open it from disk, no server. |
58
+ | `rebuild [--days N]` | Regenerate data for recent sessions from their transcripts. |
59
+ | `list` | Recent sessions with their subagent counts. |
60
+
61
+ `--settings` targets another Claude config dir, e.g. `--settings ~/.claude-work/settings.json`.
62
+ `CLAUDE_CONFIG_DIR` is respected for the default paths.
63
+
64
+ Data lives in `~/.claude/agent-timelines/` (one `<session>.data.js` and one `<session>.prompts.js` per session, removed after 30 days untouched).
65
+ The pages hold prompt text from your sessions, which is why `serve` binds to localhost only and refuses requests that come from other sites (wrong `Host`, or a cross-site script or fetch).
66
+
67
+ ## Config (optional)
68
+
69
+ `~/.config/agent-timelines/config.json` (or `$AGENT_TIMELINES_CONFIG`). Every key is optional:
70
+
71
+ ```json
72
+ {
73
+ "out_dir": "~/.claude/agent-timelines",
74
+ "ctx_limit": 200000,
75
+ "tool_limit": 50,
76
+ "brief_limit": 8000,
77
+ "retain_days": 30,
78
+ "lobby_limit": 200,
79
+ "handover_dir": "~/.claude/handovers",
80
+ "agents_dir": "~/.claude/agents",
81
+ "guard_text": "Main session does not execute",
82
+ "tiers": {"Explore": "scanner", "Plan": "plan", "general-purpose": "executor"},
83
+ "rules": {"no-model": true, "no-effort": true},
84
+ "prices": {"gpt-6": {"in": 1, "out": 2}}
85
+ }
86
+ ```
87
+
88
+ `tool_limit` is unset by default, so there are no hearts, only a tool count; set it to the number your hand-off hook uses.
89
+ `brief_limit`, `guard_text` and `handover_dir` match optional hand-off and guard hooks of your own;
90
+ without such hooks those flags never fire. `tiers` maps agent types to character classes.
91
+ `rules` turns single flags on or off by name; a flag you do not list keeps its default. `no-model` and `no-effort` are off by default;
92
+ turn them on if your setup requires every spawn to name a model and effort. The flag names are `no-model`, `no-effort`, `auto-filled`,
93
+ `frontmatter`, `model-mismatch`, `effort-mismatch`, `ctx` (the context-size flag), `handoff`, `tool-limit`, `ignored-limit`, `orphan`
94
+ and `handoff-not-continued`; an unknown name is an error.
95
+
96
+ `prices` adds or changes entries of the built-in price table (USD per million tokens; the table is dated, see `PRICES_ASOF` in `timeline.py`).
97
+ The key is a model id prefix without `claude-`, the longest matching key wins, and the columns are `in`, `cc5` (5-minute cache write),
98
+ `cc1` (1-hour cache write), `cr` (cache read), `out` and an optional `over` (`[prompt tokens, multiplier]`); a missing column counts as 0.
99
+ Entries are merged per model, so you only list what you add or change. A model with no price is shown as unpriced (`$0.00+` on its card),
100
+ never guessed.
101
+
102
+ ### Cost
103
+
104
+ Cost is computed per message from the full model id and the usage recorded in the transcript, at Anthropic first-party API list prices
105
+ ([pricing page](https://platform.claude.com/docs/en/about-claude/pricing), table dated 2026-11-10). It is what those tokens would cost through the
106
+ API; a subscription plan is not billed per token. Not modelled: the 1.1x US-only `inference_geo` surcharge (the transcript does not say whether it
107
+ applied), batch discounts, Bedrock and Vertex prices, web-search and other server-tool fees. Gold is the same tokens weighted by cost, as before.
108
+
109
+ ## Development
110
+
111
+ ```sh
112
+ python3 tests/test_timeline.py && python3 tests/test_cli.py # Python
113
+ node tests/test_dungeon.js && node tests/test_actors.js && node tests/test_lobby.js && node tests/test_gantt.js # viewer scripts (Node 18+)
114
+ open dev/dungeon-demo.html # dungeon playground: agents, working, reset
115
+ ```
116
+
117
+ ## Credits
118
+
119
+ - Sprites: [Kenney](https://www.kenney.nl) "Tiny Dungeon" and "1-Bit Pack", CC0.
120
+ - Font: Press Start 2P by CodeMan38, SIL Open Font License 1.1.
121
+
122
+ Details in `src/agent_timelines/assets/LICENSES.txt`.
123
+
124
+ ## License
125
+
126
+ MIT, see [LICENSE](https://github.com/jasondasuki/agent-timelines/blob/main/LICENSE). Contributions welcome: see [CONTRIBUTING.md](https://github.com/jasondasuki/agent-timelines/blob/main/CONTRIBUTING.md). Security reports: [SECURITY.md](https://github.com/jasondasuki/agent-timelines/blob/main/SECURITY.md).
@@ -0,0 +1,39 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "agent-timelines"
7
+ version = "0.2.0"
8
+ description = "Live delegation graph of Claude Code sessions and their subagents"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE", "src/agent_timelines/assets/LICENSES.txt"]
12
+ authors = [{ name = "jasondasuki" }]
13
+ requires-python = ">=3.9"
14
+ dependencies = []
15
+ keywords = ["claude-code", "claude", "agents", "subagents", "dashboard", "observability", "pixel-art"]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.9",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Operating System :: MacOS",
24
+ "Operating System :: POSIX :: Linux",
25
+ "Environment :: Console",
26
+ "Intended Audience :: Developers",
27
+ "Topic :: Software Development :: Debuggers",
28
+ ]
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/jasondasuki/agent-timelines"
32
+ Source = "https://github.com/jasondasuki/agent-timelines"
33
+ Issues = "https://github.com/jasondasuki/agent-timelines/issues"
34
+
35
+ [project.scripts]
36
+ agent-timelines = "agent_timelines.cli:main"
37
+
38
+ [tool.setuptools.package-data]
39
+ agent_timelines = ["viewer.html", "*.js", "assets/*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ main()
@@ -0,0 +1,202 @@
1
+ /* Characters for the dungeon: the guild master in the hall, one hero + enemy per agent room, a chest per workflow.
2
+ * Sprites follow the timeline viewer exactly (same HERO map and rules; tests/test_actors.js compares them).
3
+ * place() is pure (seed + dungeon + nodes -> actors); stamp() remembers when each state began; draw() runs per frame.
4
+ * Actors not working (idle guild master, a hero after its victory) wander their room's free cells: never onto props,
5
+ * doors, corridors or the fallen enemy. walk() holds that motion and is canvas-free so it can be tested.
6
+ * Node fields are the viewer's: {id, tier, kind, running, flags, wf:{state}}. Plain ES5; window.Actors / module.exports. */
7
+ (function (root) {
8
+ 'use strict';
9
+ var D = root.Dungeon || (typeof require !== 'undefined' && require('./dungeon.js'));
10
+ // [sheet, col, row]: keep identical to HERO in viewer.html
11
+ var HERO = {main:["td",0,7],executor:["td",0,8],scanner:["td",1,7],plan:["td",4,8],writer:["td",3,8],runner:["td",4,7],other:["td",3,7],workflow:["td",5,7],wfrun:["td",8,7],ghost:["td",1,10]};
12
+ var FOES = [108, 109, 110, 111, 120, 122, 123, 124]; // td slime, cyclops, crab, hooded cultist, bat, spider, rat, grey rat
13
+ var OPEN_CHEST = 91; // td open chest: a finished workflow
14
+ var OB_BONES = 721; // ob bone pile under a fallen enemy
15
+ var RUG = { 629: 1, 630: 1, 631: 1 }; // ob carpet pieces: the only props that may be walked on
16
+ var STEP_MS = 220; // one cell of running
17
+ var OB_TROPHY = 808; // ob trophy raised on victory (tinted gold when drawn)
18
+
19
+ function cls(n) { return n.id === 'main' ? 'main' : n.kind === 'wf' ? 'workflow' : HERO[n.tier] ? n.tier : 'other'; }
20
+ function sprite(n) { // the viewer's sprite(): a berserk hero (ignored the tool limit) is a ghost, a running workflow a mimic
21
+ var berserk = n.id !== 'main' && n.kind !== 'wf' && !n.running && (n.flags || []).indexOf('ignored-limit') >= 0;
22
+ var s = berserk ? HERO.ghost : n.kind === 'wf' && n.running ? HERO.wfrun : HERO[cls(n)];
23
+ return s[2] * 12 + s[1];
24
+ }
25
+
26
+ function place(seed, d, nodes) {
27
+ var solid = {}, path = {}, rooms = {}, out = [];
28
+ d.deco.forEach(function (e) { if (!(e.sheet === 'ob' && RUG[e.idx])) solid[e.x + ',' + e.y] = 1; });
29
+ d.paths.forEach(function (p) { p.cells.forEach(function (c) { path[c[0] + ',' + c[1]] = 1; }); });
30
+ d.rooms.forEach(function (q) { rooms[q.id] = q; });
31
+ function free(q, x, y) { return x >= q.x && x < q.x + q.w && y >= q.y && y < q.y + q.h && !solid[x + ',' + y] && !path[x + ',' + y]; }
32
+ function near(q, x, y, two) { // closest free cell to (x, y) in rings outward; `two` also needs its right neighbour free
33
+ for (var r = 0; r < q.w + q.h; r++) for (var dy = -r; dy <= r; dy++) for (var dx = -r; dx <= r; dx++) {
34
+ if (Math.max(Math.abs(dx), Math.abs(dy)) === r && free(q, x + dx, y + dy) && (!two || free(q, x + dx + 1, y + dy))) return [x + dx, y + dy];
35
+ }
36
+ return [q.cx, q.cy];
37
+ }
38
+ function room(q, skip) { // free cells of q, minus `skip`, as {"x,y": 1}
39
+ var f = {}, x, y;
40
+ for (y = q.y; y < q.y + q.h; y++) for (x = q.x; x < q.x + q.w; x++) if (free(q, x, y) && x + ',' + y !== skip) f[x + ',' + y] = 1;
41
+ return f;
42
+ }
43
+ nodes.forEach(function (n) {
44
+ var q = rooms[n.id], a;
45
+ if (!q) return;
46
+ if (q.hall) { a = near(q, q.x + 2, q.y); out.push({ id: n.id, kind: 'gm', idx: sprite(n), x: a[0], y: a[1], state: n.running ? 'cast' : 'idle', free: room(q) }); return; }
47
+ if (n.kind === 'wf') {
48
+ a = near(q, q.cx, q.cy);
49
+ out.push({ id: n.id, kind: 'wf', idx: n.running ? sprite(n) : n.wf && n.wf.state === 'failed' ? sprite(n) : OPEN_CHEST, x: a[0], y: a[1],
50
+ state: n.running ? 'fight' : 'win', failed: !n.running && !!n.wf && n.wf.state === 'failed' });
51
+ return;
52
+ }
53
+ a = near(q, q.cx - 1, q.cy, true);
54
+ out.push({ id: n.id, kind: 'hero', idx: sprite(n), x: a[0], y: a[1], state: n.running ? 'fight' : 'win',
55
+ foe: FOES[D.prng(seed + '/foe/' + n.id)() * FOES.length | 0], fx: a[0] + 1, fy: a[1], free: room(q, (a[0] + 1) + ',' + a[1]) });
56
+ });
57
+ return out;
58
+ }
59
+
60
+ // mem: {id: {state, since}} kept by the caller. An actor first seen gets since = -Infinity, so a page opened on a
61
+ // finished session shows the resting pose instead of replaying every victory.
62
+ function stamp(actors, mem, now) {
63
+ actors.forEach(function (a) {
64
+ var m = mem[a.id];
65
+ // A hero's new state starts a fresh walk from its home cell; the guild master keeps walking through idle <-> cast.
66
+ if (!m || m.state !== a.state) mem[a.id] = { state: a.state, since: m ? now : -Infinity,
67
+ walk: m && a.kind === 'gm' ? m.walk : { r: D.prng('walk/' + a.id + '/' + now) } };
68
+ a.since = mem[a.id].since; a.walk = mem[a.id].walk;
69
+ });
70
+ }
71
+
72
+ function route(free, from, to) { // BFS over free cells; the cells after `from`, ending at `to` ([] if unreachable)
73
+ var prev = {}, q = [from], k = from + '', i, c;
74
+ prev[k] = null;
75
+ while (q.length) {
76
+ c = q.shift();
77
+ if (c[0] === to[0] && c[1] === to[1]) { var out = []; for (; prev[c + ''] !== null; c = prev[c + '']) out.unshift(c); return out; }
78
+ for (i = 0; i < 4; i++) {
79
+ var n = [c[0] + [1, -1, 0, 0][i], c[1] + [0, 0, 1, -1][i]];
80
+ if (free[n[0] + ',' + n[1]] && !(n + '' in prev)) { prev[n + ''] = c; q.push(n); }
81
+ }
82
+ }
83
+ return [];
84
+ }
85
+
86
+ // Position of a resting actor at `now`, in fractional cells: run to a random free cell, pause 1-3 s, repeat.
87
+ // The loop replays whole steps, so a late frame (hidden tab) catches up instead of skipping cells.
88
+ function walk(a, now) {
89
+ var w = a.walk, cells = Object.keys(a.free);
90
+ if (!w.at) { w.at = [a.x, a.y]; w.path = []; w.until = now + 400 + w.r() * 1500; w.face = 1; }
91
+ for (;;) {
92
+ if (!w.path.length) {
93
+ if (now < w.until || !cells.length) return { x: w.at[0], y: w.at[1], moving: false, face: w.face };
94
+ var t = cells[w.r() * cells.length | 0].split(',');
95
+ w.path = route(a.free, w.at, [+t[0], +t[1]]); w.t0 = w.until;
96
+ if (!w.path.length) { w.until += 1000; continue; }
97
+ }
98
+ var n = w.path[0], f = (now - w.t0) / STEP_MS;
99
+ if (n[0] !== w.at[0]) w.face = n[0] > w.at[0] ? 1 : -1;
100
+ if (f < 1) return { x: w.at[0] + (n[0] - w.at[0]) * f, y: w.at[1] + (n[1] - w.at[1]) * f, moving: true, face: w.face };
101
+ w.at = w.path.shift(); w.t0 += STEP_MS;
102
+ if (!w.path.length) w.until = w.t0 + 1000 + w.r() * 2000;
103
+ }
104
+ }
105
+
106
+ var tints = {};
107
+ function tinted(img, cols, idx, color, mix) { // cached recolour of one sprite: mix 1 = solid silhouette (hit flash), <1 keeps shading
108
+ var k = cols + '/' + idx + color + mix;
109
+ if (tints[k]) return tints[k];
110
+ var c = document.createElement('canvas'), x = c.getContext('2d');
111
+ c.width = c.height = 16;
112
+ x.drawImage(img, idx % cols * 16, (idx / cols | 0) * 16, 16, 16, 0, 0, 16, 16);
113
+ x.globalCompositeOperation = 'source-atop'; x.globalAlpha = mix; x.fillStyle = color; x.fillRect(0, 0, 16, 16);
114
+ return (tints[k] = c);
115
+ }
116
+
117
+ // Every offset is a whole number of sprite pixels and every animation steps (no tweening), so it stays pixel art.
118
+ // still = true (reduced motion) draws each state's resting pose.
119
+ function draw(ctx, d, actors, sheets, scale, now, still) {
120
+ var S = 16 * scale, p = scale, td = sheets.td, i;
121
+ ctx.imageSmoothingEnabled = false;
122
+ function spr(idx, x, y, o) {
123
+ o = o || {};
124
+ ctx.save(); ctx.globalAlpha = o.alpha == null ? 1 : o.alpha;
125
+ ctx.translate(x + S / 2, y + S / 2); if (o.flip) ctx.scale(-1, 1); if (o.rot) ctx.rotate(o.rot);
126
+ if (o.flash) ctx.drawImage(tinted(td, 12, idx, '#fff', 1), -S / 2, -S / 2, S, S);
127
+ else ctx.drawImage(td, idx % 12 * 16, (idx / 12 | 0) * 16, 16, 16, -S / 2, -S / 2, S, S);
128
+ ctx.restore();
129
+ }
130
+ function ob(idx, x, y, alpha, gold) {
131
+ ctx.save(); ctx.globalAlpha = alpha;
132
+ if (gold) ctx.drawImage(tinted(sheets.ob, 48, idx, '#ffc21a', 0.75), x, y, S, S);
133
+ else ctx.drawImage(sheets.ob, idx % 48 * 16, (idx / 48 | 0) * 16, 16, 16, x, y, S, S);
134
+ ctx.restore();
135
+ }
136
+ function dot(color, x, y, n) { ctx.fillStyle = color; ctx.fillRect(Math.round(x / p) * p, Math.round(y / p) * p, (n || 1) * p, (n || 1) * p); }
137
+ function step(period, n, off) { return still ? 0 : Math.floor((now + off) % period / period * n); }
138
+
139
+ actors.forEach(function (a) {
140
+ var X = (a.x - d.ox) * S, Y = (a.y - d.oy) * S, off = D.prng('t/' + a.id)() * 5000 | 0, k;
141
+ if (a.kind === 'gm') return rest(a, a.idx); // always roams the hall; casts at each stop while work is going on
142
+ if (a.kind === 'wf') return spr(a.idx, X + (a.state === 'fight' ? (step(300, 2, off) ? p : -p) : 0), Y, { alpha: a.failed ? 0.5 : 1 });
143
+
144
+ var FX = (a.fx - d.ox) * S, el = now - a.since;
145
+ if (a.state === 'fight') { // 6 beats: wind-up, lunge, hit (enemy flashes, slash, sparks), recoil, counter-attack, reset
146
+ k = step(900, 6, off);
147
+ var hx = [0, 2, 4, 1, 0, 0][k] * p, ex = [0, 0, 2, 1, -3, 0][k] * p;
148
+ spr(a.idx, X + hx, Y);
149
+ if (k === 4) spr(a.idx, X + hx, Y, { flash: true, alpha: 0.6 });
150
+ spr(a.foe, FX + ex, Y, { flip: true, flash: k === 2 });
151
+ if (k === 2) {
152
+ for (i = 0; i < 4; i++) dot('#ffffff', X + S + i * p, Y + (2 + i * 3) * p, 2);
153
+ dot('#ffd23f', FX + 2 * p, Y + 2 * p); dot('#ffd23f', FX + 12 * p, Y + 5 * p); dot('#ff5a5a', FX + 7 * p, Y);
154
+ }
155
+ return;
156
+ }
157
+ // Finished: for 1.6 s after the change the enemy blinks and falls, the hero hops twice under a raised trophy
158
+ // with a burst of gold; after that the hero rests and cheers (a hop and a sparkle) every few seconds.
159
+ var v = still ? 1 : Math.min(1, el / 1600), fell = v > 0.3;
160
+ if (fell) { ob(OB_BONES, FX, Y + 2 * p, 0.9); spr(a.foe, FX, Y + 3 * p, { flip: true, rot: Math.PI / 2, alpha: 0.55 }); }
161
+ else spr(a.foe, FX, Y, { flip: true, flash: step(200, 2, 0) === 1 });
162
+ if (v < 1) {
163
+ var hop = Math.round(Math.abs(Math.sin(v * 2 * Math.PI)) * 6) * p;
164
+ spr(a.idx, X, Y - hop);
165
+ ob(OB_TROPHY, X, Y - S - 3 * p - Math.round(v * 6) * p, v < 0.7 ? 1 : (1 - v) / 0.3, true); // above the hop's peak
166
+ for (i = 0; i < 8; i++) {
167
+ var g = i / 8 * 6.2832;
168
+ dot(i % 2 ? '#ffd23f' : '#fff3b0', X + S / 2 + Math.cos(g) * v * 14 * p, Y + S / 2 - hop + Math.sin(g) * v * 14 * p);
169
+ }
170
+ return;
171
+ }
172
+ rest(a, a.idx);
173
+ });
174
+ // Not working: wander (hop while running, face the way it runs); while paused, bob and now and then cheer.
175
+ function rest(a, idx) {
176
+ var o = still ? { x: a.x, y: a.y, moving: false, face: 1 } : walk(a, now), off = D.prng('t/' + a.id)() * 5000 | 0;
177
+ var X = Math.round((o.x - d.ox) * 16) * p, Y = Math.round((o.y - d.oy) * 16) * p;
178
+ if (o.moving) return spr(idx, X, Y - step(220, 2, off) * p, { flip: o.face < 0 });
179
+ if (a.state === 'cast') return cast(idx, X, Y, o.face, off);
180
+ var k = step(4000, 10, off);
181
+ spr(idx, X, Y - (k === 0 && a.kind === 'hero' ? 3 : step(1600, 2, off)) * p, { flip: o.face < 0 });
182
+ if (k === 0 && a.kind === 'hero') { dot('#ffd23f', X + 2 * p, Y - 2 * p); dot('#fff3b0', X + 13 * p, Y - p); }
183
+ }
184
+ function cast(idx, X, Y, face, off) { // magic circle on the floor, sparks round the hand, a rune rising off the staff
185
+ var k = step(800, 8, off), j;
186
+ for (j = 0; j < 4; j++) {
187
+ var c = (j / 4 + k / 8) * 6.2832;
188
+ dot(j % 2 ? '#b48cff' : '#5ab4ff', X + S / 2 + Math.cos(c) * 9 * p, Y + S - p + Math.sin(c) * 3 * p, 2);
189
+ }
190
+ for (j = 0; j < 3; j++) {
191
+ var b = (j / 3 + k / 8) * 6.2832;
192
+ dot(['#ffffff', '#ffd23f', '#b48cff'][j], X + S / 2 + Math.cos(b) * 7 * p, Y + 4 * p + Math.sin(b) * 4 * p, 2);
193
+ }
194
+ dot('#b48cff', face < 0 ? X + p : X + 13 * p, Y - (k % 4) * 3 * p, 2);
195
+ spr(idx, X, Y - (k % 2) * p, { flip: face < 0 });
196
+ }
197
+ }
198
+
199
+ var Actors = { place: place, stamp: stamp, draw: draw, walk: walk, sprite: sprite, HERO: HERO, FOES: FOES, OPEN_CHEST: OPEN_CHEST };
200
+ if (typeof module !== 'undefined' && module.exports) module.exports = Actors;
201
+ root.Actors = Actors;
202
+ })(typeof window !== 'undefined' ? window : this);