@nanocollective/roster 0.1.0-alpha.9 → 0.1.0-beta.10

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 (151) hide show
  1. package/README.md +6 -0
  2. package/dist/cli.js +4189 -1971
  3. package/dist/worker/assets/assets/css/base.css +327 -0
  4. package/dist/worker/assets/assets/css/brain.css +116 -0
  5. package/dist/worker/assets/assets/css/diff.css +33 -0
  6. package/dist/worker/assets/assets/css/graph.css +39 -0
  7. package/dist/worker/assets/assets/css/health.css +75 -0
  8. package/dist/worker/assets/assets/css/home.css +114 -0
  9. package/dist/worker/assets/assets/css/inbox.css +199 -0
  10. package/dist/worker/assets/assets/css/layout.css +181 -0
  11. package/dist/worker/assets/assets/css/markdown.css +96 -0
  12. package/dist/worker/assets/assets/css/runs.css +13 -0
  13. package/dist/worker/assets/assets/css/search.css +48 -0
  14. package/dist/worker/assets/assets/css/setup.css +194 -0
  15. package/dist/worker/assets/assets/js/api.js +191 -0
  16. package/dist/worker/assets/assets/js/app.js +500 -0
  17. package/dist/worker/assets/assets/js/dialog.js +196 -0
  18. package/dist/worker/assets/assets/js/dom.js +131 -0
  19. package/dist/worker/assets/assets/js/homesort.js +174 -0
  20. package/dist/worker/assets/assets/js/icons.js +142 -0
  21. package/dist/worker/assets/assets/js/inflight.js +18 -0
  22. package/dist/worker/assets/assets/js/lightbox.js +273 -0
  23. package/dist/worker/assets/assets/js/md.js +406 -0
  24. package/dist/worker/assets/assets/js/mdedit.js +84 -0
  25. package/dist/worker/assets/assets/js/mention.js +264 -0
  26. package/dist/worker/assets/assets/js/readiness.js +70 -0
  27. package/dist/worker/assets/assets/js/refresh.js +197 -0
  28. package/dist/worker/assets/assets/js/router.js +20 -0
  29. package/dist/worker/assets/assets/js/search.js +366 -0
  30. package/dist/worker/assets/assets/js/state.js +213 -0
  31. package/dist/worker/assets/assets/js/textdiff.js +96 -0
  32. package/dist/worker/assets/assets/js/views/app.js +145 -0
  33. package/dist/worker/assets/assets/js/views/brain.js +260 -0
  34. package/dist/worker/assets/assets/js/views/changed.js +157 -0
  35. package/dist/worker/assets/assets/js/views/checklist.js +115 -0
  36. package/dist/worker/assets/assets/js/views/credential.js +84 -0
  37. package/dist/worker/assets/assets/js/views/docs.js +174 -0
  38. package/dist/worker/assets/assets/js/views/files.js +139 -0
  39. package/dist/worker/assets/assets/js/views/graph.js +436 -0
  40. package/dist/worker/assets/assets/js/views/health.js +304 -0
  41. package/dist/worker/assets/assets/js/views/hire.js +593 -0
  42. package/dist/worker/assets/assets/js/views/home.js +621 -0
  43. package/dist/worker/assets/assets/js/views/inbox.js +1558 -0
  44. package/dist/worker/assets/assets/js/views/memory.js +150 -0
  45. package/dist/worker/assets/assets/js/views/org.js +195 -0
  46. package/dist/worker/assets/assets/js/views/orgedit.js +240 -0
  47. package/dist/worker/assets/assets/js/views/paste.js +216 -0
  48. package/dist/worker/assets/assets/js/views/prompt.js +457 -0
  49. package/dist/worker/assets/assets/js/views/repos.js +97 -0
  50. package/dist/worker/assets/assets/js/views/runonce.js +94 -0
  51. package/dist/worker/assets/assets/js/views/runs.js +182 -0
  52. package/dist/worker/assets/assets/js/views/setup.js +557 -0
  53. package/dist/worker/assets/assets/js/views/staff.js +291 -0
  54. package/dist/worker/assets/assets/js/views/todo.js +62 -0
  55. package/dist/worker/assets/assets/js/yaml.js +134 -0
  56. package/dist/worker/assets/docs-images/brain.jpg +0 -0
  57. package/dist/worker/assets/docs-images/home.jpg +0 -0
  58. package/dist/worker/assets/docs-images/org.jpg +0 -0
  59. package/dist/worker/assets/docs-images/prompt.jpg +0 -0
  60. package/dist/worker/assets/docs-images/setup-org.jpg +0 -0
  61. package/dist/worker/assets/docs-images/setup-plan.jpg +0 -0
  62. package/dist/worker/assets/docs-images/staff.jpg +0 -0
  63. package/dist/worker/assets/index.html +82 -0
  64. package/dist/worker/index.js +5143 -0
  65. package/docs/README.md +2 -2
  66. package/docs/architecture.md +23 -4
  67. package/docs/charters/analyst.md +65 -0
  68. package/docs/charters/community.md +63 -0
  69. package/docs/charters/designer.md +65 -0
  70. package/docs/charters/devops.md +65 -0
  71. package/docs/charters/pm.md +70 -0
  72. package/docs/charters/qa.md +65 -0
  73. package/docs/charters/writer.md +63 -0
  74. package/docs/commands.md +36 -9
  75. package/docs/concepts.md +34 -21
  76. package/docs/cost.md +3 -3
  77. package/docs/developing.md +28 -10
  78. package/docs/doctor-codes.md +3 -1
  79. package/docs/export.md +2 -0
  80. package/docs/getting-started.md +49 -29
  81. package/docs/hosting.md +114 -43
  82. package/docs/images/brain.jpg +0 -0
  83. package/docs/images/home.jpg +0 -0
  84. package/docs/images/org.jpg +0 -0
  85. package/docs/images/prompt.jpg +0 -0
  86. package/docs/images/staff.jpg +0 -0
  87. package/docs/manual-steps.md +3 -2
  88. package/docs/memory.md +2 -1
  89. package/docs/org-yaml.md +3 -0
  90. package/docs/portal.md +144 -45
  91. package/docs/prompts.md +6 -0
  92. package/docs/security.md +70 -11
  93. package/docs/session-workflow.md +24 -6
  94. package/docs/staff-yaml.md +21 -2
  95. package/docs/upgrading.md +3 -3
  96. package/docs/writing-a-charter.md +19 -6
  97. package/package.json +4 -3
  98. package/templates/brain/.github/workflows/%%STAFF%%-daily.yaml +20 -1
  99. package/templates/brain/.github/workflows/%%STAFF%%-mention.yaml +53 -13
  100. package/templates/brain/CHARTER.md +2 -2
  101. package/templates/brain/STATE.md +16 -0
  102. package/templates/brain/memory/INDEX.md +1 -1
  103. package/templates/brain/staff.yaml +4 -1
  104. package/templates/briefs/amend.md +4 -3
  105. package/templates/briefs/priorities.md +46 -0
  106. package/templates/ops/.github/workflows/session.yaml +150 -3
  107. package/templates/ops/compose.mjs +35 -8
  108. package/templates/ops/org/operating.md +29 -10
  109. package/templates/ops/org/voice.md +2 -1
  110. package/templates/ops/prompts/daily.md +51 -14
  111. package/templates/ops/prompts/mention.md +24 -2
  112. package/templates/ops/run-record.mjs +5 -3
  113. package/templates/ops/status-week.mjs +169 -0
  114. package/templates/portal/css/base.css +49 -0
  115. package/templates/portal/css/health.css +14 -1
  116. package/templates/portal/css/home.css +114 -0
  117. package/templates/portal/css/inbox.css +21 -4
  118. package/templates/portal/css/layout.css +35 -3
  119. package/templates/portal/css/markdown.css +19 -0
  120. package/templates/portal/css/search.css +48 -0
  121. package/templates/portal/css/setup.css +79 -4
  122. package/templates/portal/index.html +15 -9
  123. package/templates/portal/js/api.js +60 -4
  124. package/templates/portal/js/app.js +125 -7
  125. package/templates/portal/js/dialog.js +36 -0
  126. package/templates/portal/js/homesort.js +174 -0
  127. package/templates/portal/js/icons.js +41 -0
  128. package/templates/portal/js/inflight.js +18 -0
  129. package/templates/portal/js/md.js +5 -2
  130. package/templates/portal/js/mdedit.js +84 -0
  131. package/templates/portal/js/readiness.js +70 -0
  132. package/templates/portal/js/refresh.js +10 -2
  133. package/templates/portal/js/search.js +366 -0
  134. package/templates/portal/js/state.js +11 -5
  135. package/templates/portal/js/views/app.js +1 -2
  136. package/templates/portal/js/views/brain.js +1 -1
  137. package/templates/portal/js/views/checklist.js +19 -4
  138. package/templates/portal/js/views/credential.js +42 -51
  139. package/templates/portal/js/views/health.js +11 -6
  140. package/templates/portal/js/views/hire.js +593 -0
  141. package/templates/portal/js/views/home.js +621 -0
  142. package/templates/portal/js/views/inbox.js +237 -68
  143. package/templates/portal/js/views/org.js +31 -111
  144. package/templates/portal/js/views/orgedit.js +240 -0
  145. package/templates/portal/js/views/paste.js +111 -66
  146. package/templates/portal/js/views/prompt.js +94 -40
  147. package/templates/portal/js/views/repos.js +10 -10
  148. package/templates/portal/js/views/runs.js +21 -4
  149. package/templates/portal/js/views/setup.js +130 -163
  150. package/templates/portal/js/views/staff.js +181 -301
  151. package/templates/portal/js/views/todo.js +62 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nanocollective/roster",
3
- "version": "0.1.0-alpha.9",
3
+ "version": "0.1.0-beta.10",
4
4
  "description": "An agent-run org, powered by GitHub. Scaffold AI staff members whose brain is a repo.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -17,7 +17,7 @@
17
17
  "node": ">=20"
18
18
  },
19
19
  "scripts": {
20
- "build": "tsup src/cli.ts --format esm --target node20 --clean",
20
+ "build": "tsup src/cli.ts --format esm --target node20 --clean && node scripts/build-worker.mjs",
21
21
  "dev": "tsx src/cli.ts",
22
22
  "test": "tsx --test test/*.test.ts",
23
23
  "test:all": "pnpm test:format && pnpm test:lint && pnpm test:types && pnpm test:knip && pnpm test",
@@ -31,7 +31,8 @@
31
31
  "test:security": "semgrep scan --config auto --error",
32
32
  "typecheck": "tsc --noEmit",
33
33
  "format": "biome check --write .",
34
- "prepublishOnly": "pnpm test:all && pnpm build"
34
+ "prepublishOnly": "pnpm test:all && pnpm build",
35
+ "build:worker": "node scripts/build-worker.mjs"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@biomejs/biome": "^2.5.12",
@@ -6,12 +6,25 @@ name: %%STAFF_UPPER%% daily run
6
6
  #
7
7
  # NOTE: %%TOKENS%% are filled by `roster hire`; GitHub's own ${{ }} are left alone.
8
8
 
9
+ # The trigger and the date, as the Actions list shows it. The daily limit counts follow-on runs
10
+ # by this name.
11
+ run-name: "%%STAFF%% ${{ github.event_name == 'schedule' && 'daily' || inputs.trigger || 'manual' }}"
12
+
9
13
  on:
10
14
  schedule:
11
15
  - cron: "%%SCHEDULE%%"
16
+ # By hand, from Run once now, or as a follow-on: a daily run that ended with the next step
17
+ # ready starts one more, up to max_runs_per_day.
12
18
  workflow_dispatch:
19
+ inputs:
20
+ trigger:
21
+ description: "manual | follow-on"
22
+ required: false
23
+ default: manual
24
+ type: string
13
25
 
14
- # A second run while one is in flight would fight it over the tracker and the branch state.
26
+ # A second run while one is in flight would fight it over the tracker and the branch state. A
27
+ # follow-on is started from inside the run before it, so it waits here until that one ends.
15
28
  concurrency:
16
29
  group: %%STAFF%%-session
17
30
  cancel-in-progress: false
@@ -21,13 +34,19 @@ jobs:
21
34
  # The ceiling on what session.yaml's job token may do: reading the checkout, and the one
22
35
  # comment that says a run failed when the App that would normally say so is what broke.
23
36
  # A called workflow cannot raise these, so they have to be granted here.
37
+ #
38
+ # `actions` is for the daily limit, which reads this repo's runs, and for starting a
39
+ # follow-on run, which the job token may do: a workflow_dispatch it sends still starts a run.
24
40
  permissions:
25
41
  contents: read
26
42
  issues: write
43
+ actions: write
27
44
  uses: %%OPS_REPO%%/.github/workflows/session.yaml@main
28
45
  with:
29
46
  staff: %%STAFF%%
30
47
  kind: daily
48
+ trigger: ${{ github.event_name == 'schedule' && 'daily' || inputs.trigger || 'manual' }}
49
+ max_runs_per_day: %%MAX_RUNS%%
31
50
  ops_repo: %%OPS_REPO%%
32
51
  model: %%MODEL%%
33
52
  timeout_minutes: %%TIMEOUT%%
@@ -3,11 +3,28 @@ name: %%STAFF_UPPER%% on a mention
3
3
  # Generated by roster. The body lives in %%OPS_REPO%%/.github/workflows/session.yaml.
4
4
  #
5
5
  # "%%MENTION%% ..." in a comment on this tracker, or in the body of a new issue, wakes a focused
6
- # run in about 30 seconds. It is a task, not a session: no boot ritual, no handoff, and the reply
6
+ # run in about 30 seconds. So does another staff member filing an issue here with their
7
+ # `from-<handle>` label. It is a task, not a session: no boot ritual, no handoff, and the reply
7
8
  # goes in the thread.
8
9
  #
9
10
  # NOTE: %%TOKENS%% are filled by `roster hire`. GitHub's own ${{ }} expressions are left alone.
10
11
 
12
+ # What the run is and what started it, as the Actions list shows it. The portal reads this back
13
+ # to link a live run to the request behind it, and the daily limit counts peer runs by it.
14
+ # Most events here are nobody asking (a comment without the mention, this staff member's own
15
+ # reply), and those are named `ignored`, so nothing reads one as work while it waits to be
16
+ # skipped.
17
+ run-name: >-
18
+ %%STAFF%% ${{
19
+ (contains(fromJSON('%%HUMAN_LOGINS%%'), github.event.sender.login) &&
20
+ (contains(github.event.comment.body, '%%MENTION%%') ||
21
+ (github.event_name == 'issues' && contains(github.event.issue.body, '%%MENTION%%'))))
22
+ && 'mention'
23
+ || ((github.event_name == 'issues' && github.event.action == 'opened' &&
24
+ endsWith(github.event.sender.login, '[bot]') &&
25
+ github.event.sender.login != '%%APP%%[bot]') && 'peer' || 'ignored')
26
+ }} #${{ github.event.issue.number }}
27
+
11
28
  on:
12
29
  # A mention in the body of a brand new issue, which is often the faster route: one box, rather
13
30
  # than a "create, then comment" round trip. `edited` doubles as the way to re-ask without
@@ -22,12 +39,6 @@ on:
22
39
  issue_comment:
23
40
  types: [created, edited]
24
41
 
25
- # Per issue, not global. Several comments in a row are the normal case and a shared group would
26
- # silently drop all but one of them.
27
- concurrency:
28
- group: %%STAFF%%-mention-${{ github.event.issue.number }}
29
- cancel-in-progress: false
30
-
31
42
  jobs:
32
43
  answer:
33
44
  # Only a human this org answers to, only on a real mention. A bot quoting the phrase must
@@ -44,25 +55,54 @@ jobs:
44
55
  #
45
56
  # One spelling of the mention is enough: GitHub's `contains` is documented as not case
46
57
  # sensitive, so this already matches an uppercase mention at the start of a sentence.
58
+ #
59
+ # The second route is a peer's ask: a new issue opened by an App, never this staff member's
60
+ # own, carrying a `from-<handle>` label. Only `opened`, so the peer editing its own issue
61
+ # later wakes nobody. It names no peer, so a later hire needs no regenerated caller: the only
62
+ # accounts that can open an issue on a private tracker are the people and Apps it is
63
+ # installed for. A peer run may not file on another peer, and session.yaml holds peer runs
64
+ # to the day's limit, so two staff cannot wake each other forever.
65
+ # Per issue, not global: several comments in a row are the normal case, and a shared group
66
+ # would silently drop all but one of them. On the job rather than the workflow, so the
67
+ # condition below is decided first. At workflow level every event queued here, including
68
+ # this staff member's own replies, and GitHub keeps one waiting run per group, so a reply
69
+ # waiting to be skipped could knock out a real mention waiting behind a run.
70
+ concurrency:
71
+ group: %%STAFF%%-mention-${{ github.event.issue.number }}
72
+ cancel-in-progress: false
47
73
  if: >-
48
- contains(fromJSON('%%HUMAN_LOGINS%%'), github.event.sender.login) &&
49
74
  (
50
- (github.event_name == 'issue_comment' &&
51
- contains(fromJSON('%%HUMAN_LOGINS%%'), github.event.comment.user.login) &&
52
- contains(github.event.comment.body, '%%MENTION%%')) ||
53
- (github.event_name == 'issues' &&
54
- contains(github.event.issue.body, '%%MENTION%%'))
75
+ contains(fromJSON('%%HUMAN_LOGINS%%'), github.event.sender.login) &&
76
+ (
77
+ (github.event_name == 'issue_comment' &&
78
+ contains(fromJSON('%%HUMAN_LOGINS%%'), github.event.comment.user.login) &&
79
+ contains(github.event.comment.body, '%%MENTION%%')) ||
80
+ (github.event_name == 'issues' &&
81
+ contains(github.event.issue.body, '%%MENTION%%'))
82
+ )
83
+ ) || (
84
+ github.event_name == 'issues' && github.event.action == 'opened' &&
85
+ endsWith(github.event.sender.login, '[bot]') &&
86
+ github.event.sender.login != '%%APP%%[bot]' &&
87
+ contains(join(github.event.issue.labels.*.name, ','), 'from-')
55
88
  )
56
89
  # The ceiling on what session.yaml's job token may do: reading the checkout, and the one
57
90
  # comment that says a run failed when the App that would normally say so is what broke.
58
91
  # A called workflow cannot raise these, so they have to be granted here.
92
+ #
93
+ # `actions` is for the daily limit, which counts this repo's runs today. It is `write`
94
+ # because session.yaml's job asks for that (a daily run starts its follow-on with it), and a
95
+ # called job asking for more than its caller granted fails before it starts.
59
96
  permissions:
60
97
  contents: read
61
98
  issues: write
99
+ actions: write
62
100
  uses: %%OPS_REPO%%/.github/workflows/session.yaml@main
63
101
  with:
64
102
  staff: %%STAFF%%
65
103
  kind: mention
104
+ trigger: ${{ contains(fromJSON('%%HUMAN_LOGINS%%'), github.event.sender.login) && 'mention' || 'peer' }}
105
+ max_runs_per_day: %%MAX_RUNS%%
66
106
  ops_repo: %%OPS_REPO%%
67
107
  model: %%MODEL%%
68
108
  timeout_minutes: %%MENTION_TIMEOUT%%
@@ -45,5 +45,5 @@ Only the additions. `org/guardrails.md` is already binding on everyone.
45
45
 
46
46
  ## Where the rest of it lives
47
47
 
48
- Point at `memory/INDEX.md`, `log/decisions.md`, the pinned status issue, and whatever
49
- surfaces this role declares in `staff.yaml`.
48
+ Point at `memory/INDEX.md`, `log/decisions.md`, `STATE.md`, the pinned status issue, and
49
+ whatever surfaces this role declares in `staff.yaml`.
@@ -0,0 +1,16 @@
1
+ # Where I am
2
+
3
+ %%NAME%%'s handover between runs. Every daily run reads it first and rewrites it last. What
4
+ people read is the pinned status issue.
5
+
6
+ ## Situation
7
+
8
+ Just hired. Nothing done yet.
9
+
10
+ ## Next, in order
11
+
12
+ 1. Read the charter and the org's priorities, and pick the first piece of work.
13
+
14
+ ## Parked
15
+
16
+ Nothing.
@@ -18,7 +18,7 @@ The grammar, which `roster lint` enforces:
18
18
 
19
19
  - **`<slug>`** · [<%%HUMAN_MARKER%%|measured|derived>] <the fact, one line>. **So:** <what it changes>. · [note](notes/<slug>.md)
20
20
 
21
- `log/decisions.md` = why things were decided. The pinned status issue = what is outstanding.
21
+ `log/decisions.md` = why things were decided. `STATE.md` = what is outstanding.
22
22
  **Nothing is copied between them.**
23
23
 
24
24
  ---
@@ -13,6 +13,9 @@ schedule: "%%SCHEDULE%%"
13
13
  model: %%MODEL%%
14
14
  timeout_minutes: %%TIMEOUT%%
15
15
  mention_timeout_minutes: %%MENTION_TIMEOUT%%
16
+ # Runs a day that start without a person asking: a peer's ask, or a follow-on to a daily run.
17
+ # Mentions never count against it.
18
+ max_runs_per_day: %%MAX_RUNS%%
16
19
 
17
20
  bot: %%APP%%[bot]
18
21
  public_bot: %%PUBLIC_APP%%[bot]
@@ -40,4 +43,4 @@ surfaces:
40
43
 
41
44
  labels:
42
45
  owner: [%%HUMAN_MARKER%%, %%STAFF%%]
43
- kind: [decision, setup, build, blocked]
46
+ kind: [decision, review, chore, keep-open, build, blocked]
@@ -44,7 +44,8 @@ If what is wanted needs one of these, say so and stop. Do not work around it.
44
44
 
45
45
  1. **Say which file, and why that one.** Prefer the narrowest file that achieves it. If the
46
46
  change is about %%NAME%% specifically, it does not belong in `org/`.
47
- 2. **Show a diff, not a rewritten file.** %%HUMAN%% has to be able to see exactly what moved.
47
+ 2. **Hand back the whole file you changed**, in the block described at the end. The tool
48
+ %%HUMAN%% pastes your answer into shows them the diff, so they see exactly what moved.
48
49
  3. **Do not restate.** Every layer is already in the composed text below. A rule added to
49
50
  `org/voice.md` that `org/operating.md` already states makes the prompt longer and no
50
51
  clearer.
@@ -56,5 +57,5 @@ If what is wanted needs one of these, say so and stop. Do not work around it.
56
57
 
57
58
  ## Then
58
59
 
59
- Give %%HUMAN%% the diff, the one-line reason for the file you chose, and what you cut. They
60
- apply it: in the portal's Prompt screen, or by editing the file and committing it.
60
+ Outside the block: the one-line reason for the file you chose, and what you cut. Inside it:
61
+ the whole changed file. Nothing is saved until %%HUMAN%% has seen the diff and pressed Save.
@@ -0,0 +1,46 @@
1
+ Write `org/priorities.md` for %%ORG_NAME%%.
2
+
3
+ You are helping %%HUMAN%% decide what their AI staff should work on this month. Every staff
4
+ member reads this file at the start of every run and picks work that serves it, so a vague
5
+ priority produces scattered work.
6
+
7
+ ## Where you are
8
+
9
+ - `%%OPS_REPO_DIR%%/org/business.md`: what the business is. **Read it first**, and don't ask
10
+ anything it already answers.
11
+ - `%%OPS_REPO_DIR%%/org/priorities.md`: the current file, which you are replacing.
12
+
13
+ If you cannot read files where you are running, ask %%HUMAN%% to paste `org/business.md`.
14
+
15
+ ## Interview
16
+
17
+ Ask one question at a time. You are after:
18
+
19
+ - **The one outcome that matters most this month**, and how they will know it happened.
20
+ - **At most two more**, in order. Push back on a fourth: past three it is a wish list.
21
+ - **What is out of scope this month**: work that is tempting but not now. Naming it is what
22
+ stops the staff doing it.
23
+
24
+ Prefer outcomes ("a stranger pays for it") to activities ("improve the landing page"). If an
25
+ answer is an activity, ask what it is for.
26
+
27
+ ## Write it
28
+
29
+ Use exactly this shape:
30
+
31
+ ```
32
+ ## What matters this month
33
+
34
+ ### Priorities, in order
35
+
36
+ 1. The first outcome, and how you will know it happened.
37
+ 2. The second.
38
+ 3. The third.
39
+
40
+ ### Out of scope this month
41
+
42
+ - One thing per line.
43
+ ```
44
+
45
+ Keep each priority to a sentence or two. Don't add anything %%HUMAN%% didn't say without
46
+ listing it after the file so they can check it.
@@ -19,6 +19,16 @@ on:
19
19
  required: false
20
20
  default: daily
21
21
  type: string
22
+ # What started the run: daily | manual | follow-on | mention | peer. Peer and follow-on
23
+ # runs start without a person asking, so they are the ones held to max_runs_per_day.
24
+ trigger:
25
+ required: false
26
+ default: ""
27
+ type: string
28
+ max_runs_per_day:
29
+ required: false
30
+ default: 6
31
+ type: number
22
32
  ops_repo:
23
33
  description: "owner/name of the ops repo holding org.yaml and the prompts"
24
34
  required: true
@@ -65,20 +75,81 @@ permissions:
65
75
  contents: read
66
76
 
67
77
  jobs:
78
+ # Two staff can ask each other things, and a daily run can start a follow-on, so runs can start
79
+ # runs. This is what stops that at max_runs_per_day. A mention is a person asking and is never
80
+ # held back, so only peer and follow-on runs are counted, and only the ones that ran: a caller
81
+ # whose condition did not match leaves a skipped run behind under the same name.
82
+ budget:
83
+ runs-on: ubuntu-latest
84
+ permissions:
85
+ actions: read
86
+ issues: write
87
+ outputs:
88
+ go: ${{ steps.count.outputs.go }}
89
+ steps:
90
+ - name: Count today's runs nobody asked for
91
+ id: count
92
+ env:
93
+ GH_TOKEN: ${{ github.token }}
94
+ TRIGGER: ${{ inputs.trigger }}
95
+ STAFF: ${{ inputs.staff }}
96
+ LIMIT: ${{ inputs.max_runs_per_day }}
97
+ ISSUE: ${{ inputs.issue_number }}
98
+ run: |
99
+ set -uo pipefail
100
+ case "$TRIGGER" in
101
+ peer|follow-on) ;;
102
+ *) echo "go=true" >> "$GITHUB_OUTPUT"; exit 0 ;;
103
+ esac
104
+ today=$(date -u +%F)
105
+ # Includes this run, which is in progress and named like the rest.
106
+ filter="[.workflow_runs[]
107
+ | select(.display_title | test(\"^$STAFF (peer|follow-on)( |\$)\"))
108
+ | select(.conclusion != \"skipped\")] | length"
109
+ # One count per page, summed. pipefail makes a failed read fail the whole line.
110
+ if ! n=$(gh api --paginate "repos/${{ github.repository }}/actions/runs?created=>=$today&per_page=100" \
111
+ --jq "$filter" | awk '{s += $1} END {print s + 0}'); then
112
+ # Unknown is not under the limit. A run held back costs a day; a loop costs a bill.
113
+ echo "::warning::could not count today's runs, so this one does not start"
114
+ n=999999
115
+ fi
116
+ echo "$n of $LIMIT runs today that nobody asked for, this one included"
117
+ if [ "$n" -le "$LIMIT" ]; then
118
+ echo "go=true" >> "$GITHUB_OUTPUT"
119
+ exit 0
120
+ fi
121
+ echo "go=false" >> "$GITHUB_OUTPUT"
122
+ msg="Not started: $STAFF has had $LIMIT runs today that nobody asked for, which is max_runs_per_day. The next daily run picks this up, or mention them to start one now."
123
+ echo "$msg" >> "$GITHUB_STEP_SUMMARY"
124
+ if [ -n "$ISSUE" ]; then
125
+ gh issue comment "$ISSUE" --repo "${{ github.repository }}" --body "$msg" || true
126
+ fi
127
+
68
128
  session:
129
+ needs: budget
130
+ if: needs.budget.outputs.go == 'true'
69
131
  runs-on: ubuntu-latest
70
132
  timeout-minutes: ${{ inputs.timeout_minutes }}
71
133
 
72
134
  # `issues: write` is for the failure notice alone, which falls back to this job's own token
73
- # when the App's cannot be minted. A called workflow cannot raise what its caller granted, so
74
- # the callers ask for the same.
135
+ # when the App's cannot be minted. `actions: write` starts a follow-on run. A called workflow
136
+ # cannot raise what its caller granted, so the callers ask for the same.
75
137
  permissions:
76
138
  contents: read
77
139
  issues: write
140
+ actions: write
78
141
 
79
142
  # secrets are not usable in a step-level `if`, so the presence check is hoisted here.
80
143
  env:
81
144
  HAS_PUBLIC_APP: ${{ secrets.PUBLIC_APP_ID != '' }}
145
+ # Nothing is listening once the agent ends its turn: the session is over and a background
146
+ # job dies with the runner. Claude Code moves any command past its timeout (ten minutes by
147
+ # default) into the background, and an agent told "you will be notified" ends its turn to
148
+ # wait, so a slow test suite cost the whole run, unpushed, reported as a success. With
149
+ # background tasks off a slow command stays in the foreground, and the higher cap lets a
150
+ # long gate finish inside the turn. timeout-minutes is still the real bound.
151
+ CLAUDE_CODE_DISABLE_BACKGROUND_TASKS: "1"
152
+ BASH_MAX_TIMEOUT_MS: "2700000"
82
153
 
83
154
  steps:
84
155
  # For the run record at the end. A job has no start time of its own to read back.
@@ -239,6 +310,18 @@ jobs:
239
310
  cache: pnpm
240
311
  cache-dependency-path: ${{ steps.plan.outputs.package_json }}
241
312
 
313
+ # A status issue lasts a week. The first daily run of a week opens the new one, pins it and
314
+ # moves staff.yaml on, before the prompt is composed from staff.yaml; the prompt is told
315
+ # which earlier week still needs its summary. `daily` only: a mention is not a session.
316
+ # Never fatal: without it the run writes to last week's issue.
317
+ - name: Open this week's status issue
318
+ id: week
319
+ if: inputs.kind == 'daily'
320
+ continue-on-error: true
321
+ env:
322
+ GH_TOKEN: ${{ steps.private.outputs.token }}
323
+ run: node roster-ops/status-week.mjs --staff "${{ inputs.staff }}" --ops roster-ops --brains . >> "$GITHUB_OUTPUT"
324
+
242
325
  # Composed at run time rather than baked in, so editing org/voice.md reaches every staff
243
326
  # member on their next run without regenerating anything.
244
327
  - name: Compose the prompt
@@ -248,7 +331,9 @@ jobs:
248
331
  {"issue_number":"${{ inputs.issue_number }}",
249
332
  "comment_id":"${{ inputs.comment_id }}",
250
333
  "repo":"${{ github.repository }}",
251
- "actor":"${{ github.actor }}"}
334
+ "actor":"${{ github.actor }}",
335
+ "trigger":"${{ inputs.trigger }}",
336
+ "previous_status_issue":"${{ steps.week.outputs.previous }}"}
252
337
  run: |
253
338
  node roster-ops/compose.mjs --staff "${{ inputs.staff }}" --kind "${{ inputs.kind }}" --ops roster-ops --brains . > .roster-prompt.txt
254
339
  {
@@ -285,6 +370,13 @@ jobs:
285
370
  PUBLIC_TOKEN: ${{ steps.public.outputs.token }}
286
371
  with:
287
372
  claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN || secrets.AGENT_TOKEN }}
373
+ # The action refuses to run for a bot unless it is named here. A peer's ask is opened
374
+ # by that peer's App, so on a peer run, and only then, the one bot that opened it is
375
+ # allowed. The caller has already checked it is an App, not this staff member's own,
376
+ # and that the issue carries a from- label. A follow-on run is dispatched by the job token
377
+ # of the run before it, so its actor is github-actions[bot], and only that bot is allowed.
378
+ # Every other run allows no bots.
379
+ allowed_bots: ${{ inputs.trigger == 'peer' && github.actor || inputs.trigger == 'follow-on' && 'github-actions[bot]' || '' }}
288
380
  # These repos are private and single-user, so the usual reason to hide a run's output does
289
381
  # not apply, and hiding it turns any failure into "is_error: true" with no message.
290
382
  # Registered secrets are still masked by the runner.
@@ -341,6 +433,56 @@ jobs:
341
433
  fi
342
434
  eval "$RUN"
343
435
 
436
+ # A session can exit cleanly without doing what it was asked: the success above only means
437
+ # the agent stopped. A mention is answered by a reply in its thread, or by the issue being
438
+ # closed when the request said to answer somewhere else. When neither happened the job
439
+ # fails, so the notice below tells the human instead of leaving them waiting.
440
+ #
441
+ # Never fails on its own account: if the issue cannot be read, nothing is claimed.
442
+ - name: Check the request was answered
443
+ id: answered
444
+ if: >-
445
+ inputs.kind == 'mention' && inputs.issue_number != ''
446
+ && (steps.session_action.outcome == 'success' || steps.session_cli.outcome == 'success')
447
+ env:
448
+ GH_TOKEN: ${{ steps.private.outputs.token }}
449
+ BOT: ${{ steps.private.outputs.app-slug }}[bot]
450
+ ISSUE: ${{ inputs.issue_number }}
451
+ run: |
452
+ set -uo pipefail
453
+ since=$(date -u -d "@$ROSTER_STARTED" +%Y-%m-%dT%H:%M:%SZ)
454
+ if ! state=$(gh api "repos/${{ github.repository }}/issues/$ISSUE" --jq .state) ||
455
+ ! replies=$(gh api --paginate "repos/${{ github.repository }}/issues/$ISSUE/comments?since=$since" \
456
+ --jq ".[] | select(.user.login == \"$BOT\" and .created_at >= \"$since\") | .id"); then
457
+ echo "::warning::could not read #$ISSUE, so whether it was answered is unknown"
458
+ exit 0
459
+ fi
460
+ if [ "$state" = "closed" ] || [ -n "$replies" ]; then
461
+ exit 0
462
+ fi
463
+ echo "unanswered=true" >> "$GITHUB_OUTPUT"
464
+ echo "::error::the session ended without replying on #$ISSUE or closing it"
465
+ exit 1
466
+
467
+ # A daily run that ended with the next step ready says so in .roster-run/continue, and one
468
+ # more run starts once this one ends: it waits on the caller's concurrency group. Only
469
+ # after a run that finished, and the budget job above holds the chain to the day's limit.
470
+ # The job token can do this: a workflow_dispatch it sends still starts a run.
471
+ - name: Start a follow-on run
472
+ if: >-
473
+ inputs.kind == 'daily' && success()
474
+ && (steps.session_action.outcome == 'success' || steps.session_cli.outcome == 'success')
475
+ && hashFiles('.roster-run/continue') != ''
476
+ continue-on-error: true
477
+ env:
478
+ GH_TOKEN: ${{ github.token }}
479
+ CALLER: ${{ github.workflow_ref }}
480
+ run: |
481
+ set -uo pipefail
482
+ file=$(basename "${CALLER%@*}")
483
+ gh workflow run "$file" --repo "${{ github.repository }}" -f trigger=follow-on
484
+ { echo "Started a follow-on run:"; head -c 300 .roster-run/continue; echo; } >> "$GITHUB_STEP_SUMMARY"
485
+
344
486
  # What this run was and what it cost, in the job summary and as an artifact with a stable
345
487
  # name, which is what the portal's Runs screen and `roster doctor` read back. Never fatal:
346
488
  # a missing record costs a row in a table, and failing the job over it would cost the run.
@@ -354,6 +496,7 @@ jobs:
354
496
  MODEL: ${{ steps.agent.outputs.model || inputs.model }}
355
497
  AGENT_OUTCOME: ${{ steps.session_action.outcome != 'skipped' && steps.session_action.outcome || steps.session_cli.outcome }}
356
498
  JOB_STATUS: ${{ job.status }}
499
+ UNANSWERED: ${{ steps.answered.outputs.unanswered }}
357
500
  RESULT_FILE: ${{ steps.session_action.outputs.execution_file || format('{0}/.roster-run/agent-result.json', github.workspace) }}
358
501
  run: node roster-ops/run-record.mjs --out .roster-run/run.json
359
502
 
@@ -383,6 +526,7 @@ jobs:
383
526
  BRAIN_DIR: ${{ steps.plan.outputs.brain_dir }}
384
527
  BRAIN_REPO: ${{ steps.plan.outputs.brain_repo || github.repository }}
385
528
  ISSUE: ${{ inputs.issue_number }}
529
+ UNANSWERED: ${{ steps.answered.outputs.unanswered }}
386
530
  RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
387
531
  run: |
388
532
  set -uo pipefail
@@ -402,6 +546,9 @@ jobs:
402
546
  fi
403
547
 
404
548
  body="This run did not finish, so there is no answer coming. [Run ${GITHUB_RUN_ID}]($RUN_URL) has the error."
549
+ if [ "$UNANSWERED" = "true" ]; then
550
+ body="This run stopped without replying here or closing the issue, so there is no answer coming. [Run ${GITHUB_RUN_ID}]($RUN_URL) shows where it stopped."
551
+ fi
405
552
  if [ -n "$APP_TOKEN" ] && GH_TOKEN="$APP_TOKEN" gh issue comment "$issue" --repo "$BRAIN_REPO" --body "$body"; then
406
553
  exit 0
407
554
  fi
@@ -11,12 +11,10 @@
11
11
  //
12
12
  // Usage: node compose.mjs --staff cmo --kind daily [--ops .] [--brains ..]
13
13
 
14
- import { readFileSync, existsSync } from "node:fs";
14
+ import * as nodeFs from "node:fs";
15
15
  import { join, dirname, resolve } from "node:path";
16
16
  import { fileURLToPath } from "node:url";
17
17
 
18
- const HERE = dirname(fileURLToPath(import.meta.url));
19
-
20
18
  // ---------------------------------------------------------------------------
21
19
  // A strict, tiny YAML subset: nested maps, lists of scalars, lists of inline
22
20
  // maps ({a: 1, b: 2}), and scalars. Anything else is an error rather than a
@@ -288,7 +286,18 @@ function defaultMarker(name) {
288
286
  // Composition
289
287
  // ---------------------------------------------------------------------------
290
288
 
291
- export function compose({ opsDir, brainsDir, staff, kind, runDir }) {
289
+ // `fs` and `context` are for the portal, which composes from a copy of the repos held in memory
290
+ // rather than from a checkout, for a preview rather than a run. A workflow passes neither.
291
+ export function compose({
292
+ opsDir,
293
+ brainsDir,
294
+ staff,
295
+ kind,
296
+ runDir,
297
+ fs = nodeFs,
298
+ context = process.env.ROSTER_CONTEXT,
299
+ }) {
300
+ const { readFileSync, existsSync } = fs;
292
301
  const org = parseYaml(readFileSync(join(opsDir, "org.yaml"), "utf8"), "org.yaml");
293
302
 
294
303
  const entry = (org.staff ?? []).find((s) => s.handle === staff);
@@ -310,9 +319,9 @@ export function compose({ opsDir, brainsDir, staff, kind, runDir }) {
310
319
  // JSON in the environment rather than as arguments, so a workflow never has to quote a
311
320
  // comment body onto a command line.
312
321
  let event = {};
313
- if (process.env.ROSTER_CONTEXT) {
322
+ if (context) {
314
323
  try {
315
- event = JSON.parse(process.env.ROSTER_CONTEXT);
324
+ event = JSON.parse(context);
316
325
  } catch (err) {
317
326
  throw new Error(`ROSTER_CONTEXT is not valid JSON: ${err.message}`);
318
327
  }
@@ -323,6 +332,16 @@ export function compose({ opsDir, brainsDir, staff, kind, runDir }) {
323
332
  // sends it to a 404 before it has read anything. So the absence is a value of its own.
324
333
  if (Object.keys(event).length) event = { ...event, no_comment: !event.comment_id };
325
334
 
335
+ // Who started this run, as flags: the prompt language has `{{#if}}` and nothing to compare
336
+ // with. A peer's ask reads differently from a person's, and a follow-on picks up mid-task.
337
+ const trigger = String(event.trigger ?? "");
338
+ event = {
339
+ ...event,
340
+ from_peer: trigger === "peer",
341
+ from_human: trigger !== "peer",
342
+ follow_on: trigger === "follow-on",
343
+ };
344
+
326
345
  // What people have open on the product repos, gathered by inflight.mjs just before this runs.
327
346
  // Read as a value and never rendered as a template: it is PR titles, which are a person's
328
347
  // words, and a `{{` in one must not be able to break composition.
@@ -345,6 +364,11 @@ export function compose({ opsDir, brainsDir, staff, kind, runDir }) {
345
364
  // The repo this role contributes to but does not own. Named explicitly in the
346
365
  // prompt because "a repo you do not own" is vaguer than an agent needs.
347
366
  product: (self.works_in ?? [])[0] ?? null,
367
+ // Absent from manifests written before it existed; the callers fall back to the same.
368
+ max_runs_per_day: self.max_runs_per_day ?? 6,
369
+ // One staff member drafts next month's org/priorities.md, so there is one draft rather
370
+ // than one per person: whoever org.yaml lists first.
371
+ drafts_priorities: (org.staff ?? [])[0]?.handle === staff,
348
372
  },
349
373
  peers,
350
374
  peer: peers[0] ?? null,
@@ -388,12 +412,15 @@ function main(argv) {
388
412
  console.error("usage: node compose.mjs --staff <handle> --kind <daily|mention> [--ops DIR] [--brains DIR]");
389
413
  process.exit(2);
390
414
  }
391
- const opsDir = resolve(args.ops ?? HERE);
415
+ const opsDir = resolve(args.ops ?? dirname(fileURLToPath(import.meta.url)));
392
416
  const brainsDir = resolve(args.brains ?? join(opsDir, ".."));
393
417
  process.stdout.write(compose({ opsDir, brainsDir, staff: args.staff, kind: args.kind }));
394
418
  }
395
419
 
396
- if (process.argv[1] && resolve(process.argv[1]) === resolve(fileURLToPath(import.meta.url))) {
420
+ // Run as a script, and only as itself: bundled into another program (the portal's), this file's
421
+ // URL is that program's, and `node <program>` must not be taken for `node compose.mjs`.
422
+ const self = import.meta.url ? fileURLToPath(import.meta.url) : "";
423
+ if (process.argv[1] && self.endsWith("compose.mjs") && resolve(process.argv[1]) === resolve(self)) {
397
424
  try {
398
425
  main(process.argv.slice(2));
399
426
  } catch (err) {