levi-gear 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -8
- package/agents/_team-protocol.md +15 -6
- package/agents/designer.md +2 -2
- package/agents/developer.md +1 -1
- package/agents/pm.md +4 -1
- package/agents/qa.md +1 -1
- package/agents/teamlead.md +1 -1
- package/package.json +4 -1
- package/src/commands/list.js +2 -1
- package/src/lib/agents.js +9 -2
- package/src/lib/desired-state.js +38 -11
- package/src/lib/role-skills.js +23 -0
- package/src/lib/tools.js +6 -1
- package/src/lib/usecases.js +44 -2
- package/src/runtime/codex-run-state.mjs +156 -0
- package/src/runtime/quota-check.mjs +195 -0
- package/usecases/_run-rules.md +38 -0
- package/usecases/brainstorming/SKILL.md +60 -14
- package/usecases/brainstorming/references/codex-runner.md +28 -0
- package/usecases/code-review/SKILL.md +86 -0
- package/usecases/code-review/references/codex-runner.md +5 -0
- package/usecases/code-review/references/large-changes.md +37 -0
- package/usecases/code-review/references/performance-and-correctness.md +101 -0
- package/usecases/code-review/references/review-guide.md +72 -0
- package/usecases/code-review/references/security.md +119 -0
- package/usecases/create-feature/SKILL.md +97 -0
- package/usecases/create-feature/references/codex-runner.md +57 -0
- package/usecases/create-feature/scripts/lock-tests.mjs +66 -0
- package/usecases/create-feature/workflow.js +532 -0
- package/usecases/design/SKILL.md +66 -0
- package/usecases/design/references/codex-runner.md +27 -0
- package/usecases/design/references/svg-guide.md +14 -0
- package/usecases/design/scripts/check-svg.py +77 -0
- package/usecases/fix-bug/SKILL.md +97 -0
- package/usecases/fix-bug/references/codex-runner.md +32 -0
- package/usecases/fix-bug/workflow.js +392 -0
- package/usecases/generate-test-scenarios/SKILL.md +102 -0
- package/usecases/generate-test-scenarios/references/codex-runner.md +32 -0
- package/usecases/generate-test-scenarios/references/test-case-guide.md +171 -0
- package/usecases/generate-test-scenarios/scripts/render-test-cases-markdown.mjs +76 -0
- package/usecases/generate-test-scenarios/scripts/render-test-cases.mjs +68 -0
- package/usecases/generate-test-scenarios/scripts/test-case-fields.mjs +63 -0
- package/usecases/generate-test-scenarios/scripts/validate-test-cases.mjs +69 -0
- package/usecases/generate-test-scenarios/scripts/write-xlsx.mjs +157 -0
- package/usecases/spec-writing/SKILL.md +63 -0
- package/usecases/spec-writing/references/codex-runner.md +25 -0
- package/usecases/spec-writing/references/spec-guide.md +62 -0
package/README.md
CHANGED
|
@@ -43,15 +43,19 @@ Codex has no user-defined `/` commands in a repo, so it uses `$` instead. `levi
|
|
|
43
43
|
|
|
44
44
|
Every install includes the team agents from `agents/`. Usecases delegate to them; they never run on their own and never call each other.
|
|
45
45
|
|
|
46
|
-
| Agent |
|
|
47
|
-
|
|
48
|
-
| `levi-pm` |
|
|
49
|
-
| `levi-teamlead` |
|
|
50
|
-
| `levi-developer` | Implements tasks
|
|
51
|
-
| `levi-designer` |
|
|
52
|
-
| `levi-qa` |
|
|
46
|
+
| Agent | Responsibilities | Owns | Called by |
|
|
47
|
+
|---|---|---|---|
|
|
48
|
+
| `levi-pm` | Writes and updates specs with checkable acceptance criteria (the only role that touches specs); frames problems; decides scope and priority; assigns each task an owner; approves plans against the spec; accepts the product on test evidence and writes release notes | `spec.md`, `docs/specs/`, `status.md`, `docs/brainstorming/` | `spec-writing`, `brainstorming`, `create-feature` |
|
|
49
|
+
| `levi-teamlead` | Designs the architecture and picks the technology; designs the database schema and migrations; sets structure, conventions and API contracts; breaks work into tasks with estimates; reviews code (security by OWASP Top 10, performance and correctness) with a fix for every finding; owns CI/CD | `architecture.md`, `tasks.md`, `review.md`, schema, migrations, CI/CD and deployment config | `brainstorming`, `create-feature`, `fix-bug`, `code-review` |
|
|
50
|
+
| `levi-developer` | Implements tasks as designed; investigates and fixes bugs at the root cause; writes unit and integration tests; runs build, lint and tests before handing off | Application code, unit and integration tests, technical docs of the code | `create-feature`, `fix-bug` |
|
|
51
|
+
| `levi-designer` | Maps user flows and wireframes; draws screens in SVG and HTML prototypes; defines design tokens and every state; covers responsive behavior and accessibility; writes handoff notes | `docs/designs/` | `design`, `create-feature` (for UI work) |
|
|
52
|
+
| `levi-qa` | Writes test plans and test cases from the spec, without reading the code, as Markdown and Excel (only QA changes them); runs E2E tests in a headless browser; writes E2E and acceptance tests; reports bugs and gives the go or no-go | `test-plan.md`, `docs/tests/`, `test-report.md`, E2E and acceptance tests | `create-feature`, `fix-bug`, `generate-test-scenarios` |
|
|
53
|
+
|
|
54
|
+
Each agent does only its own role's work and writes only the files it owns; work for another role is handed off. The full role descriptions are in [docs/team.md](docs/team.md).
|
|
55
|
+
|
|
56
|
+
Some usecases are also a role's skill: `spec-writing` for the PM, `design` for the designer, `code-review` for the teamlead and `generate-test-scenarios` for QA. They are installed with every install, and the agent follows that skill's guide whenever it gets that kind of task, from any usecase. A usecase declares this with `skill-for`, `skill-when` and `skill-guide` in its `SKILL.md`.
|
|
53
57
|
|
|
54
|
-
The usecase's skill or workflow runs the team: it calls each member in turn. The PM only decides who owns each task and records it; the workflow follows that. Members hand work to each other through files in a work folder (`docs/levi/<slug>/` by default): `spec.md`, `status.md`, `
|
|
58
|
+
The usecase's skill or workflow runs the team: it calls each member in turn. The PM only decides who owns each task and records it; the workflow follows that. Members hand work to each other through files in a work folder (`docs/levi/<slug>/` by default): `spec.md`, `status.md`, `docs/designs/`, `architecture.md`, `tasks.md`, `review.md`, `test-plan.md`, `test-report.md`. On Codex, every installed skill also gets a small `scripts/codex-run-state.mjs` helper; long runs record `run.json` in that work folder so they can resume after an interruption. The shared rules live in `agents/_team-protocol.md`, which is appended to every team agent. Every usecase also follows the run rules in `usecases/_run-rules.md`, appended to each installed `SKILL.md`: all questions are asked up front, cheap-to-change choices are picked and reported at the end, and a run that hits the 5-hour quota resumes itself ([docs/unattended-runs.md](docs/unattended-runs.md)).
|
|
55
59
|
|
|
56
60
|
## Update
|
|
57
61
|
|
|
@@ -88,6 +92,7 @@ usecases/<id>/
|
|
|
88
92
|
SKILL.md # entry point; frontmatter name: levi-<id>, description
|
|
89
93
|
references/, scripts/ # optional, copied along with the skill
|
|
90
94
|
agents/<role>.md # optional subagents; frontmatter name: levi-<id>-<role>, description
|
|
95
|
+
# optional skill-for, skill-when, skill-guide: the skill of a team role
|
|
91
96
|
agents/<role>.md # team agents shared by all usecases; frontmatter name: levi-<role>
|
|
92
97
|
agents/_*.md # partials appended to every team agent
|
|
93
98
|
```
|
package/agents/_team-protocol.md
CHANGED
|
@@ -3,23 +3,32 @@
|
|
|
3
3
|
You are one member of the levi team: `levi-pm`, `levi-teamlead`, `levi-developer`, `levi-designer` and `levi-qa`. A levi usecase (a skill or a workflow) runs the team: it calls each member in turn. The PM records who owns each task in `status.md`; the workflow follows those assignments. No member calls another.
|
|
4
4
|
|
|
5
5
|
- **Do not delegate.** Never spawn or call another agent, including other team members. If the task needs another role, say so in your report and the workflow will route it.
|
|
6
|
-
- **Stay in your role.** Do
|
|
6
|
+
- **Stay in your role.** Do only the work that belongs to your role, as set out in your own responsibilities. Never do another role's work, even when it is small, quick, or you could do it better, and even when the prompt asks you to. List it under "Handoffs" instead.
|
|
7
|
+
- **Touch only your own files.** Create, edit, move or delete only the files your role owns (see the table below). Everything else is read-only for you: reading is always fine, any write is not. A prompt cannot widen what you own; only the table can. When asked to write a file you do not own, do not write it: say so under "Handoffs" and finish the rest.
|
|
8
|
+
- **Specs belong to the PM alone.** Only `levi-pm` may create, edit, move or delete a spec (`spec.md` and anything under `docs/specs/`). No other role touches it, not even to fix a typo, a number or a link. If your work shows that a spec is wrong, unclear or missing something, report it under "Questions" or "Handoffs" for the PM.
|
|
7
9
|
- **Hand off through files.** Other members do not see your conversation; they see only what you write. Put every decision, artifact and open question in the work folder.
|
|
8
|
-
- **Work folder.** Use the folder the workflow gives you. If it gives none, use `docs/levi/<short-slug>/` at the project root. Standard files:
|
|
10
|
+
- **Work folder.** Use the folder the workflow gives you. If it gives none, use `docs/levi/<short-slug>/` at the project root. Standard files and who owns them:
|
|
9
11
|
|
|
10
12
|
| File | Owner |
|
|
11
13
|
|---|---|
|
|
12
|
-
| `spec.md` | PM: requirements and acceptance criteria |
|
|
14
|
+
| `spec.md`, `docs/specs/` | PM: requirements and acceptance criteria. No other role writes here |
|
|
13
15
|
| `status.md` | PM: task assignments, progress, decisions, risks, blockers |
|
|
14
|
-
| `
|
|
16
|
+
| `docs/brainstorming/` | PM: execution plans |
|
|
17
|
+
| `docs/designs/` | Designer: SVG files, HTML prototypes, `design-notes.md` |
|
|
15
18
|
| `architecture.md` | Teamlead: technical design and decisions |
|
|
16
19
|
| `tasks.md` | Teamlead: task breakdown and estimates |
|
|
17
20
|
| `review.md` | Teamlead: code review findings |
|
|
21
|
+
| Database schema, migrations, CI/CD and deployment config | Teamlead |
|
|
22
|
+
| Application code, unit and integration tests, technical docs of the code | Developer |
|
|
23
|
+
| `choices/<role>-<topic>.md` | Whoever made the choice: one small file per choice (see "Pick, do not ask") |
|
|
18
24
|
| `test-plan.md` | QA: test plan and test cases |
|
|
25
|
+
| `docs/tests/` | QA: numbered test scenarios and test cases, with their PASS or FAIL results once run |
|
|
19
26
|
| `test-report.md` | QA: results, bugs, sign-off |
|
|
27
|
+
| E2E and acceptance tests | QA |
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
- **Never ask the user directly.** You run without the user in the loop. When information is missing, finish what you can and return the questions.
|
|
29
|
+
A file the table does not list belongs to the role whose responsibilities cover it. If you cannot tell which, do not write it: hand it off.
|
|
30
|
+
- **Never ask the user directly.** You run without the user in the loop. When information is missing, finish what you can and return the questions. Return every question you can foresee in your first report, all together: the user is asked once, so a question you hold back is answered late or never.
|
|
31
|
+
- **Pick, do not ask.** When your work yields several acceptable options and a wrong pick is cheap to undo (logo variants, a layout, a palette, a name, a wording), do not turn it into a question. Take the best one, keep the others where the user can still reach them (files in an `alternatives/` folder next to your deliverable), and write `choices/<your-role>-<topic>.md` in the work folder: what was chosen between, your pick, why, the alternatives and how to switch. Questions are for facts only the user knows, scope and acceptance criteria, and anything hard to undo.
|
|
23
32
|
- **Language.** Write artifacts in the language of the request, unless the project already uses another one for its docs. Code, identifiers and commit messages stay in English.
|
|
24
33
|
- **Do not guess.** Mark assumptions as assumptions. Do not invent requirements, data, or results you did not observe.
|
|
25
34
|
|
package/agents/designer.md
CHANGED
|
@@ -10,12 +10,12 @@ You are the designer. You decide how the product looks and how people move throu
|
|
|
10
10
|
## Responsibilities
|
|
11
11
|
|
|
12
12
|
- **Flows and wireframes.** Start from the user stories in `spec.md`: map the user flow and wireframe the screens before adding detail.
|
|
13
|
-
- **Screens.** Produce the designs as SVG files in `
|
|
13
|
+
- **Screens.** Produce the designs as SVG files in `docs/designs/<slug>/`. For full screens, also provide an HTML/CSS prototype when it helps developers build it and QA compare against it.
|
|
14
14
|
- **Design tokens.** Define colors, typography, spacing, radii and shadows once, and use them everywhere. Reuse the project's existing tokens when it has them.
|
|
15
15
|
- **States.** Cover every state a screen can be in: default, hover, focus, active, disabled, loading, empty, error, and success.
|
|
16
16
|
- **Responsive.** Show how each screen adapts at mobile, tablet and desktop widths.
|
|
17
17
|
- **Accessibility.** Meet WCAG 2.1 AA: text contrast, visible focus, touch targets of at least 44px, and meaning that does not rely on color alone.
|
|
18
|
-
- **Handoff.** Write `
|
|
18
|
+
- **Handoff.** Write `docs/designs/<slug>/design-notes.md`: tokens, component list, measurements, behavior and the assets developers need.
|
|
19
19
|
|
|
20
20
|
## Rules
|
|
21
21
|
|
package/agents/developer.md
CHANGED
|
@@ -8,7 +8,7 @@ You are a fullstack developer. You implement the tasks you are given, the way th
|
|
|
8
8
|
|
|
9
9
|
## Responsibilities
|
|
10
10
|
|
|
11
|
-
- **Implement.** Build the assigned task from `tasks.md`, following `architecture.md`, the project's conventions and the design in `
|
|
11
|
+
- **Implement.** Build the assigned task from `tasks.md`, following `architecture.md`, the project's conventions and the design in `docs/designs/`.
|
|
12
12
|
- **Test.** Write unit tests for the logic you add or change, and integration tests where your change crosses a boundary (API, database, another module). A test must be able to fail on a real bug.
|
|
13
13
|
- **Self-check.** Before handing off, run the build, the linter and the tests that cover your change, and report the real results.
|
|
14
14
|
- **Review fixes.** Address every finding in `review.md` that concerns your work, or explain why not.
|
package/agents/pm.md
CHANGED
|
@@ -9,7 +9,7 @@ You are the project manager. You own the outcome: what gets built, in what order
|
|
|
9
9
|
|
|
10
10
|
## Responsibilities
|
|
11
11
|
|
|
12
|
-
- **Requirements.** Turn the request into `spec.md
|
|
12
|
+
- **Requirements.** Turn the request into a spec (`spec.md`, or a file under `docs/specs/`): goal, users, scope, out of scope, user stories, and acceptance criteria that can be checked one by one. Until the team has a dedicated analyst, this is your job.
|
|
13
13
|
- **Clarification.** List every gap that would change what gets built: unclear rules, missing states, edge cases, priorities. Return them as questions instead of filling them in.
|
|
14
14
|
- **Scope.** Decide priority. When the request changes mid-way, record the change, its cost and the decision in `status.md`.
|
|
15
15
|
- **Assignment.** Decide which role owns each task in `tasks.md` and in what order, and record it in the assignments table of `status.md` (task ID, assignee role, status). You only assign; the workflow reads the table and dispatches the agents.
|
|
@@ -19,6 +19,9 @@ You are the project manager. You own the outcome: what gets built, in what order
|
|
|
19
19
|
|
|
20
20
|
## Rules
|
|
21
21
|
|
|
22
|
+
- Write into a spec only what is confirmed: stated by the user, or found in a document the user pointed to or a project file you read. A guess, a plausible default, a typical behavior of similar products or a recommended option nobody accepted is not confirmed. Raise it as a question and leave the spec silent on it, or marked as an open question.
|
|
23
|
+
- Do not call a spec ready while a question that would change its text is still open.
|
|
24
|
+
- You are the only role that creates, edits, moves or deletes specs. Others only read them.
|
|
22
25
|
- Acceptance criteria describe observable behavior, not implementation.
|
|
23
26
|
- A plan that does not cover an acceptance criterion is not approved.
|
|
24
27
|
- Never mark something done without evidence from QA or the Teamlead.
|
package/agents/qa.md
CHANGED
|
@@ -12,7 +12,7 @@ You are the QA engineer. You check that the product does what the spec says, ind
|
|
|
12
12
|
- **Coverage.** Every acceptance criterion has at least one test case. Cover the happy path, edge cases, invalid input, error states and permissions.
|
|
13
13
|
- **E2E testing.** Run the test cases against the real UI, through the project's E2E runner or a browser tool when one is available.
|
|
14
14
|
- **Automation.** Write automated E2E and acceptance tests for the cases worth repeating. Developers own unit tests; you own E2E and acceptance tests.
|
|
15
|
-
- **Visual check.** Compare the UI against the files in `
|
|
15
|
+
- **Visual check.** Compare the UI against the files in `docs/designs/` and report mismatches. The designer confirms what is intended.
|
|
16
16
|
- **Bugs.** Report each bug in `test-report.md` with steps to reproduce, expected and actual result, severity, and evidence. Verify the fix when it lands, and rerun regression tests.
|
|
17
17
|
- **Sign-off.** Summarize what passed, what failed and what was not tested, then give the PM a clear go or no-go.
|
|
18
18
|
|
package/agents/teamlead.md
CHANGED
|
@@ -14,7 +14,7 @@ You are the teamlead, the most senior developer on the team. You make the techni
|
|
|
14
14
|
- **Structure and conventions.** Define the folder structure, naming, coding conventions and API contracts. Follow what the project already does before introducing anything new.
|
|
15
15
|
- **Task breakdown.** Write `tasks.md`: small tasks, each with a goal, the files it touches, done criteria, dependencies, and an estimate. A developer must be able to start a task without guessing.
|
|
16
16
|
- **Estimates.** Give a range and the assumptions behind it, and name the riskiest task.
|
|
17
|
-
- **Code review.** Review the change for correctness, security (input validation, authorization, secrets), performance, and fit with the architecture
|
|
17
|
+
- **Code review.** Review the change for correctness, security (input validation, authorization, secrets), performance, and fit with the architecture, by the review guide and checklists the prompt points to (those of `levi-code-review`). Grade findings critical / warning / suggestion, each with a concrete fix, and write them where the prompt says (`review.md` by default). You are the gate before merge.
|
|
18
18
|
- **Unblocking.** Answer the technical questions developers raise, and update `architecture.md` when the answer changes the design.
|
|
19
19
|
- **Delivery pipeline.** Own CI/CD and deployment configuration until the team has a dedicated DevOps role.
|
|
20
20
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "levi-gear",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "An agentic kit: Agent Skills for Claude Code, Codex and Copilot, installable via npm",
|
|
5
5
|
"bin": {
|
|
6
6
|
"levi": "./bin/levi.js"
|
|
7
7
|
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "node --test test/codex-runtime.test.mjs test/quota-check.test.mjs"
|
|
10
|
+
},
|
|
8
11
|
"files": [
|
|
9
12
|
"agents",
|
|
10
13
|
"bin",
|
package/src/commands/list.js
CHANGED
|
@@ -7,7 +7,8 @@ function list(projectDir) {
|
|
|
7
7
|
if (!usecases.length) console.log('No usecases in the kit yet.');
|
|
8
8
|
for (const u of usecases) {
|
|
9
9
|
const roles = u.agents.length ? ` [agents: ${u.agents.map((a) => a.name).join(', ')}]` : '';
|
|
10
|
-
|
|
10
|
+
const requires = u.requires.length ? ` [requires: ${u.requires.join(', ')}]` : '';
|
|
11
|
+
console.log(`${u.id}${roles}${requires}\n ${u.description}`);
|
|
11
12
|
}
|
|
12
13
|
if (usecases.length) {
|
|
13
14
|
const installed = config.read(projectDir);
|
package/src/lib/agents.js
CHANGED
|
@@ -15,6 +15,10 @@ function parseList(value) {
|
|
|
15
15
|
return value ? value.split(',').map((s) => s.trim()).filter(Boolean) : null;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
function joinSections(...parts) {
|
|
19
|
+
return parts.map((p) => (p || '').trim()).filter(Boolean).join('\n\n') + '\n';
|
|
20
|
+
}
|
|
21
|
+
|
|
18
22
|
// Reads one agent file. `owner` is the skill that delegates to it, or null for team agents.
|
|
19
23
|
function readAgent(file, label, expectedName, owner, appendix = '') {
|
|
20
24
|
const { data, body } = parse(fs.readFileSync(file, 'utf8'));
|
|
@@ -33,7 +37,10 @@ function readAgent(file, label, expectedName, owner, appendix = '') {
|
|
|
33
37
|
return {
|
|
34
38
|
name: data.name,
|
|
35
39
|
description: data.description,
|
|
36
|
-
body:
|
|
40
|
+
body: joinSections(body, appendix),
|
|
41
|
+
// Kept apart so that sections can be inserted between them (see role-skills.js).
|
|
42
|
+
ownBody: body,
|
|
43
|
+
appendix,
|
|
37
44
|
owner,
|
|
38
45
|
tools,
|
|
39
46
|
model: data.model || null,
|
|
@@ -52,4 +59,4 @@ function loadTeam() {
|
|
|
52
59
|
.map((f) => readAgent(path.join(TEAM_DIR, f), `agents/${f}`, PREFIX + f.slice(0, -3), null, appendix));
|
|
53
60
|
}
|
|
54
61
|
|
|
55
|
-
module.exports = { PREFIX, CAPABILITIES, MODEL_TIERS, readAgent, loadTeam };
|
|
62
|
+
module.exports = { PREFIX, CAPABILITIES, MODEL_TIERS, joinSections, readAgent, loadTeam };
|
package/src/lib/desired-state.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const { ROUTER_NAME, skillName } = require('./usecases');
|
|
4
|
-
const { CODEX_SKILL_DIR, CODEX_POLICY, skillDirs, AGENT_TARGETS } = require('./tools');
|
|
4
|
+
const { CODEX_SKILL_DIR, CODEX_POLICY, skillDirs, skillDirFor, AGENT_TARGETS } = require('./tools');
|
|
5
|
+
const { joinSections } = require('./agents');
|
|
6
|
+
const { withRoleSkills } = require('./role-skills');
|
|
5
7
|
const { setField } = require('./frontmatter');
|
|
6
8
|
const { renderRouter } = require('./router');
|
|
7
9
|
|
|
10
|
+
const CODEX_RUN_STATE = path.join(__dirname, '..', 'runtime', 'codex-run-state.mjs');
|
|
11
|
+
const QUOTA_CHECK = path.join(__dirname, '..', 'runtime', 'quota-check.mjs');
|
|
12
|
+
|
|
8
13
|
// Group keys say which part of the kit a file belongs to; they decide where its hash is
|
|
9
14
|
// recorded in .levi.json.
|
|
10
15
|
const usecaseGroup = (id) => `usecase:${id}`;
|
|
@@ -25,20 +30,28 @@ function put(out, rel, content, group) {
|
|
|
25
30
|
|
|
26
31
|
// Every levi skill runs only when the user invokes it: Claude Code and Copilot read the
|
|
27
32
|
// frontmatter flag, Codex reads agents/openai.yaml (only written where Codex looks).
|
|
28
|
-
function addSkill(out, usecase, dir) {
|
|
33
|
+
function addSkill(out, usecase, dir, runRules) {
|
|
29
34
|
const root = path.posix.join(dir, skillName(usecase.id));
|
|
30
35
|
for (const rel of walk(usecase.dir, true)) {
|
|
31
36
|
let content = fs.readFileSync(path.join(usecase.dir, rel));
|
|
32
|
-
if (rel === 'SKILL.md') content = setField(content.toString('utf8'), 'disable-model-invocation', 'true');
|
|
37
|
+
if (rel === 'SKILL.md') content = joinSections(setField(content.toString('utf8'), 'disable-model-invocation', 'true'), runRules);
|
|
33
38
|
put(out, path.posix.join(root, rel), content, usecaseGroup(usecase.id));
|
|
34
39
|
}
|
|
35
|
-
|
|
40
|
+
// The quota guard in the run rules calls this helper, in every tool.
|
|
41
|
+
put(out, path.posix.join(root, 'scripts/quota-check.mjs'), fs.readFileSync(QUOTA_CHECK), usecaseGroup(usecase.id));
|
|
42
|
+
if (dir === CODEX_SKILL_DIR) {
|
|
43
|
+
put(out, path.posix.join(root, 'agents/openai.yaml'), CODEX_POLICY, usecaseGroup(usecase.id));
|
|
44
|
+
// The source skills remain portable Markdown. Codex gets this small durable-state
|
|
45
|
+
// helper so its dedicated runners can resume an interrupted run from files.
|
|
46
|
+
put(out, path.posix.join(root, 'scripts/codex-run-state.mjs'), fs.readFileSync(CODEX_RUN_STATE), usecaseGroup(usecase.id));
|
|
47
|
+
}
|
|
36
48
|
}
|
|
37
49
|
|
|
38
|
-
|
|
50
|
+
// `prepare` adapts an agent to one tool before it is rendered (team agents get their role skills).
|
|
51
|
+
function addAgents(out, agents, tools, group, prepare = (agent) => agent) {
|
|
39
52
|
for (const tool of tools) {
|
|
40
53
|
const target = AGENT_TARGETS[tool];
|
|
41
|
-
for (const agent of agents) put(out, path.posix.join(target.dir, agent.name + target.ext), target.render(agent), group);
|
|
54
|
+
for (const agent of agents) put(out, path.posix.join(target.dir, agent.name + target.ext), target.render(prepare(agent, tool)), group);
|
|
42
55
|
}
|
|
43
56
|
}
|
|
44
57
|
|
|
@@ -52,25 +65,39 @@ function addRouter(out, usecases, team, tools) {
|
|
|
52
65
|
}
|
|
53
66
|
}
|
|
54
67
|
|
|
55
|
-
//
|
|
56
|
-
|
|
68
|
+
// `ids` plus every usecase they require, directly or not, each once.
|
|
69
|
+
function withRequired(byId, ids) {
|
|
70
|
+
const all = [];
|
|
71
|
+
const visit = (id) => {
|
|
72
|
+
if (all.includes(id)) return;
|
|
73
|
+
all.push(id);
|
|
74
|
+
if (byId.has(id)) byId.get(id).requires.forEach(visit);
|
|
75
|
+
};
|
|
76
|
+
ids.forEach(visit);
|
|
77
|
+
return all;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// The files a clean install of `ids` (and what they require) for `tools` would contain: Map of
|
|
81
|
+
// project-relative path to { content, group }. Nothing is written here. Usecases that are a team
|
|
82
|
+
// role's skill are always installed, since the team always is and its agents rely on them.
|
|
57
83
|
function build(kit, ids, tools) {
|
|
58
84
|
const byId = new Map(kit.usecases.map((u) => [u.id, u]));
|
|
59
85
|
const out = new Map();
|
|
60
86
|
const missing = [];
|
|
61
87
|
const present = [];
|
|
62
|
-
|
|
88
|
+
const roleSkills = kit.usecases.filter((u) => u.skill).map((u) => u.id);
|
|
89
|
+
for (const id of withRequired(byId, [...ids, ...roleSkills])) {
|
|
63
90
|
if (!byId.has(id)) {
|
|
64
91
|
missing.push(id);
|
|
65
92
|
continue;
|
|
66
93
|
}
|
|
67
94
|
const usecase = byId.get(id);
|
|
68
95
|
present.push(usecase);
|
|
69
|
-
for (const dir of skillDirs(tools)) addSkill(out, usecase, dir);
|
|
96
|
+
for (const dir of skillDirs(tools)) addSkill(out, usecase, dir, kit.runRules);
|
|
70
97
|
addAgents(out, usecase.agents, tools, usecaseGroup(id));
|
|
71
98
|
}
|
|
72
99
|
addRouter(out, present, kit.team, tools);
|
|
73
|
-
addAgents(out, kit.team, tools, 'team');
|
|
100
|
+
addAgents(out, kit.team, tools, 'team', (agent, tool) => withRoleSkills(agent, present, skillDirFor(tool, tools)));
|
|
74
101
|
return { files: out, missing, ids: present.map((u) => u.id) };
|
|
75
102
|
}
|
|
76
103
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { PREFIX, joinSections } = require('./agents');
|
|
2
|
+
|
|
3
|
+
// A usecase can be the skill a team role uses for one kind of task (`skill-for` in its SKILL.md).
|
|
4
|
+
// The team agent gets a section that points to the skill's guide, so that it follows the guide
|
|
5
|
+
// whichever usecase calls it, not only when its own usecase runs.
|
|
6
|
+
function withRoleSkills(agent, usecases, skillDir) {
|
|
7
|
+
const role = agent.name.slice(PREFIX.length);
|
|
8
|
+
const mine = usecases.filter((u) => u.skill && u.skill.roles.includes(role));
|
|
9
|
+
if (!mine.length) return agent;
|
|
10
|
+
const rows = mine.map((u) => `| When ${u.skill.when} | \`${skillDir}/${PREFIX}${u.id}/${u.skill.guide}\` |`);
|
|
11
|
+
const section = [
|
|
12
|
+
'## Your skills',
|
|
13
|
+
'',
|
|
14
|
+
'These levi skills are yours. When a task you are given is one of the kinds below, read the guide before you start and follow it, whichever workflow called you and even when the prompt does not mention it. Paths in a guide are relative to its skill folder. The prompt still decides what to work on, which sources to use and where to write; where it says something the guide also covers, the prompt wins.',
|
|
15
|
+
'',
|
|
16
|
+
'| Task | Guide |',
|
|
17
|
+
'|---|---|',
|
|
18
|
+
...rows,
|
|
19
|
+
].join('\n');
|
|
20
|
+
return { ...agent, body: joinSections(agent.ownBody, section, agent.appendix) };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = { withRoleSkills };
|
package/src/lib/tools.js
CHANGED
|
@@ -17,6 +17,11 @@ function skillDirs(tools) {
|
|
|
17
17
|
return [...dirs];
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
// The skill folder an agent of `tool` reads: Copilot uses .claude/skills when Claude is installed.
|
|
21
|
+
function skillDirFor(tool, tools) {
|
|
22
|
+
return tool === 'claude' || (tool === 'copilot' && tools.includes('claude')) ? '.claude/skills' : '.agents/skills';
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
// Codex ignores SKILL.md frontmatter flags and reads its invocation policy from this file.
|
|
21
26
|
const CODEX_SKILL_DIR = '.agents/skills';
|
|
22
27
|
const CODEX_POLICY = 'policy:\n allow_implicit_invocation: false\n';
|
|
@@ -90,4 +95,4 @@ function invocationHelp(tools) {
|
|
|
90
95
|
.join('\n');
|
|
91
96
|
}
|
|
92
97
|
|
|
93
|
-
module.exports = { TOOLS, CODEX_SKILL_DIR, CODEX_POLICY, skillDirs, AGENT_TARGETS, invocationHelp };
|
|
98
|
+
module.exports = { TOOLS, CODEX_SKILL_DIR, CODEX_POLICY, skillDirs, skillDirFor, AGENT_TARGETS, invocationHelp };
|
package/src/lib/usecases.js
CHANGED
|
@@ -5,6 +5,8 @@ const { PREFIX, readAgent, loadTeam } = require('./agents');
|
|
|
5
5
|
|
|
6
6
|
const ROUTER_NAME = 'levi';
|
|
7
7
|
const KIT_DIR = path.join(__dirname, '..', '..', 'usecases');
|
|
8
|
+
// Rules every usecase follows; appended to each installed SKILL.md. Not a usecase: it is a file, not a folder.
|
|
9
|
+
const RUN_RULES_FILE = path.join(KIT_DIR, '_run-rules.md');
|
|
8
10
|
|
|
9
11
|
function skillName(id) {
|
|
10
12
|
return PREFIX + id;
|
|
@@ -25,6 +27,22 @@ function loadAgents(id, dir) {
|
|
|
25
27
|
);
|
|
26
28
|
}
|
|
27
29
|
|
|
30
|
+
function parseList(value) {
|
|
31
|
+
return (value || '').split(',').map((s) => s.trim()).filter(Boolean);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// A usecase can be the skill of team roles for one kind of task: `skill-for` (the roles),
|
|
35
|
+
// `skill-when` (the task, completing "When ...") and `skill-guide` (the file the role follows).
|
|
36
|
+
function loadRoleSkill(id, dir, data) {
|
|
37
|
+
const roles = parseList(data['skill-for']);
|
|
38
|
+
if (!roles.length) return null;
|
|
39
|
+
const label = `usecases/${id}/SKILL.md`;
|
|
40
|
+
if (!data['skill-when']) throw new Error(`${label}: skill-for needs skill-when`);
|
|
41
|
+
if (!data['skill-guide']) throw new Error(`${label}: skill-for needs skill-guide`);
|
|
42
|
+
if (!fs.existsSync(path.join(dir, data['skill-guide']))) throw new Error(`${label}: skill-guide "${data['skill-guide']}" not found`);
|
|
43
|
+
return { roles, when: data['skill-when'], guide: data['skill-guide'] };
|
|
44
|
+
}
|
|
45
|
+
|
|
28
46
|
function load(id) {
|
|
29
47
|
const dir = path.join(KIT_DIR, id);
|
|
30
48
|
const skillFile = path.join(dir, 'SKILL.md');
|
|
@@ -34,7 +52,28 @@ function load(id) {
|
|
|
34
52
|
throw new Error(`usecases/${id}/SKILL.md: name must be "${skillName(id)}", got "${data.name}"`);
|
|
35
53
|
}
|
|
36
54
|
if (!data.description) throw new Error(`usecases/${id}/SKILL.md: missing description`);
|
|
37
|
-
|
|
55
|
+
const requires = parseList(data.requires);
|
|
56
|
+
return { id, dir, description: data.description, requires, skill: loadRoleSkill(id, dir, data), agents: loadAgents(id, dir) };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// A usecase may build on others (`requires:` in its SKILL.md); they must exist in the kit.
|
|
60
|
+
// Role skills must name roles the team has.
|
|
61
|
+
function checkSkillRoles(usecases, team) {
|
|
62
|
+
const roles = new Set(team.map((a) => a.name.slice(PREFIX.length)));
|
|
63
|
+
for (const u of usecases) {
|
|
64
|
+
for (const role of (u.skill && u.skill.roles) || []) {
|
|
65
|
+
if (!roles.has(role)) throw new Error(`usecases/${u.id}/SKILL.md: skill-for names unknown team role "${role}"`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function checkRequires(usecases) {
|
|
71
|
+
const ids = new Set(usecases.map((u) => u.id));
|
|
72
|
+
for (const u of usecases) {
|
|
73
|
+
for (const r of u.requires) {
|
|
74
|
+
if (r === u.id || !ids.has(r)) throw new Error(`usecases/${u.id}/SKILL.md: requires unknown usecase "${r}"`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
38
77
|
}
|
|
39
78
|
|
|
40
79
|
// Every agent name must be unique across the team and all usecases, and a usecase id must not
|
|
@@ -60,7 +99,10 @@ function loadKit() {
|
|
|
60
99
|
: [];
|
|
61
100
|
const team = loadTeam();
|
|
62
101
|
checkNames(usecases, team);
|
|
63
|
-
|
|
102
|
+
checkRequires(usecases);
|
|
103
|
+
checkSkillRoles(usecases, team);
|
|
104
|
+
const runRules = fs.existsSync(RUN_RULES_FILE) ? fs.readFileSync(RUN_RULES_FILE, 'utf8').trim() : '';
|
|
105
|
+
return { usecases, team, runRules };
|
|
64
106
|
}
|
|
65
107
|
|
|
66
108
|
function listUsecases() {
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Durable, tool-neutral checkpoint helper installed with every Codex levi skill.
|
|
3
|
+
// It deliberately does not run agents: the Codex skill remains responsible for
|
|
4
|
+
// dispatching the right role, while this file makes a stopped run resumable.
|
|
5
|
+
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
|
|
9
|
+
const [command, workDir, ...args] = process.argv.slice(2);
|
|
10
|
+
const stateFile = workDir && path.join(workDir, 'run.json');
|
|
11
|
+
|
|
12
|
+
function die(message) {
|
|
13
|
+
console.error(message);
|
|
14
|
+
process.exitCode = 2;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function read() {
|
|
18
|
+
if (!stateFile || !fs.existsSync(stateFile)) throw new Error(`no run state at ${stateFile || '<workdir>'}`);
|
|
19
|
+
return JSON.parse(fs.readFileSync(stateFile, 'utf8'));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function write(state) {
|
|
23
|
+
fs.mkdirSync(workDir, { recursive: true });
|
|
24
|
+
state.updatedAt = new Date().toISOString();
|
|
25
|
+
const temporary = `${stateFile}.${process.pid}.tmp`;
|
|
26
|
+
fs.writeFileSync(temporary, JSON.stringify(state, null, 2) + '\n');
|
|
27
|
+
try {
|
|
28
|
+
fs.renameSync(temporary, stateFile);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
// Some Windows filesystems do not replace an existing destination on rename.
|
|
31
|
+
// The completed temporary file is still safer than writing JSON in place.
|
|
32
|
+
if (!['EEXIST', 'EPERM'].includes(error.code)) throw error;
|
|
33
|
+
fs.copyFileSync(temporary, stateFile);
|
|
34
|
+
fs.unlinkSync(temporary);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function print(value) {
|
|
39
|
+
console.log(JSON.stringify(value, null, 2));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function stage(state, name) {
|
|
43
|
+
const found = state.stages.find((item) => item.name === name);
|
|
44
|
+
if (!found) throw new Error(`unknown stage "${name}"; expected one of: ${state.stages.map((item) => item.name).join(', ')}`);
|
|
45
|
+
return found;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function previousStagesComplete(state, current) {
|
|
49
|
+
const index = state.stages.indexOf(current);
|
|
50
|
+
return state.stages.slice(0, index).every((item) => item.status === 'complete');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function record(state, type, details = {}) {
|
|
54
|
+
state.history.push({ at: new Date().toISOString(), type, ...details });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function update(commandName, callback) {
|
|
58
|
+
const state = read();
|
|
59
|
+
callback(state);
|
|
60
|
+
write(state);
|
|
61
|
+
print({ command: commandName, state: state.status, currentStage: state.currentStage, file: stateFile });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
if (command === 'init') {
|
|
66
|
+
const [usecase, slug, ...stageNames] = args;
|
|
67
|
+
if (!usecase || !slug || !stageNames.length) throw new Error('usage: init <workdir> <usecase> <slug> <stage>...');
|
|
68
|
+
if (new Set(stageNames).size !== stageNames.length) throw new Error('stage names must be unique');
|
|
69
|
+
if (fs.existsSync(stateFile)) throw new Error(`run state already exists at ${stateFile}; use status or resume instead`);
|
|
70
|
+
const now = new Date().toISOString();
|
|
71
|
+
const state = {
|
|
72
|
+
version: 1,
|
|
73
|
+
runtime: 'codex',
|
|
74
|
+
usecase,
|
|
75
|
+
slug,
|
|
76
|
+
status: 'running',
|
|
77
|
+
currentStage: stageNames[0],
|
|
78
|
+
createdAt: now,
|
|
79
|
+
updatedAt: now,
|
|
80
|
+
stages: stageNames.map((name) => ({ name, status: 'pending', attempts: 0, artifacts: [] })),
|
|
81
|
+
history: [{ at: now, type: 'initialized' }],
|
|
82
|
+
};
|
|
83
|
+
write(state);
|
|
84
|
+
print({ command: 'init', state: state.status, currentStage: state.currentStage, file: stateFile });
|
|
85
|
+
} else if (command === 'status') {
|
|
86
|
+
const state = read();
|
|
87
|
+
print({ state: state.status, currentStage: state.currentStage, stages: state.stages, history: state.history, file: stateFile });
|
|
88
|
+
} else if (command === 'begin') {
|
|
89
|
+
const [name] = args;
|
|
90
|
+
update(command, (state) => {
|
|
91
|
+
if (state.status !== 'running') throw new Error(`cannot begin while run is ${state.status}; use resume first`);
|
|
92
|
+
const current = stage(state, name);
|
|
93
|
+
if (state.currentStage !== name) throw new Error(`cannot begin ${name}; current stage is ${state.currentStage}`);
|
|
94
|
+
if (!previousStagesComplete(state, current)) throw new Error(`cannot begin ${name}; an earlier stage is incomplete`);
|
|
95
|
+
if (current.status === 'complete') throw new Error(`${name} is already complete`);
|
|
96
|
+
current.status = 'active';
|
|
97
|
+
current.attempts += 1;
|
|
98
|
+
record(state, 'began', { stage: name, attempt: current.attempts });
|
|
99
|
+
});
|
|
100
|
+
} else if (command === 'complete') {
|
|
101
|
+
const [name, ...artifacts] = args;
|
|
102
|
+
update(command, (state) => {
|
|
103
|
+
if (state.status !== 'running') throw new Error(`cannot complete while run is ${state.status}`);
|
|
104
|
+
const current = stage(state, name);
|
|
105
|
+
if (state.currentStage !== name) throw new Error(`cannot complete ${name}; current stage is ${state.currentStage}`);
|
|
106
|
+
if (!['active', 'pending'].includes(current.status)) throw new Error(`${name} is ${current.status}, not active`);
|
|
107
|
+
const missing = artifacts.filter((artifact) => !fs.existsSync(artifact));
|
|
108
|
+
if (missing.length) throw new Error(`cannot complete ${name}; missing artifact(s): ${missing.join(', ')}`);
|
|
109
|
+
current.status = 'complete';
|
|
110
|
+
current.completedAt = new Date().toISOString();
|
|
111
|
+
current.artifacts = [...new Set([...current.artifacts, ...artifacts])];
|
|
112
|
+
const next = state.stages[state.stages.indexOf(current) + 1];
|
|
113
|
+
state.currentStage = next ? next.name : null;
|
|
114
|
+
state.status = next ? 'running' : 'done';
|
|
115
|
+
record(state, 'completed', { stage: name, artifacts });
|
|
116
|
+
});
|
|
117
|
+
} else if (command === 'finish') {
|
|
118
|
+
const [name, ...artifacts] = args;
|
|
119
|
+
update(command, (state) => {
|
|
120
|
+
const current = stage(state, name);
|
|
121
|
+
if (state.currentStage !== name) throw new Error(`cannot finish at ${name}; current stage is ${state.currentStage}`);
|
|
122
|
+
const missing = artifacts.filter((artifact) => !fs.existsSync(artifact));
|
|
123
|
+
if (missing.length) throw new Error(`cannot finish at ${name}; missing artifact(s): ${missing.join(', ')}`);
|
|
124
|
+
current.status = 'complete';
|
|
125
|
+
current.completedAt = new Date().toISOString();
|
|
126
|
+
current.artifacts = [...new Set([...current.artifacts, ...artifacts])];
|
|
127
|
+
for (const later of state.stages.slice(state.stages.indexOf(current) + 1)) later.status = 'skipped';
|
|
128
|
+
state.currentStage = null;
|
|
129
|
+
state.status = 'done';
|
|
130
|
+
record(state, 'finished', { stage: name, artifacts });
|
|
131
|
+
});
|
|
132
|
+
} else if (command === 'wait' || command === 'block') {
|
|
133
|
+
const [name, ...message] = args;
|
|
134
|
+
update(command, (state) => {
|
|
135
|
+
const current = stage(state, name);
|
|
136
|
+
if (state.currentStage !== name) throw new Error(`cannot mark ${name}; current stage is ${state.currentStage}`);
|
|
137
|
+
current.status = command === 'wait' ? 'waiting_user' : 'blocked';
|
|
138
|
+
current.message = message.join(' ').trim();
|
|
139
|
+
state.status = current.status;
|
|
140
|
+
record(state, command, { stage: name, message: current.message });
|
|
141
|
+
});
|
|
142
|
+
} else if (command === 'resume') {
|
|
143
|
+
update(command, (state) => {
|
|
144
|
+
if (!['waiting_user', 'blocked'].includes(state.status)) throw new Error(`cannot resume while run is ${state.status}`);
|
|
145
|
+
const current = stage(state, state.currentStage);
|
|
146
|
+
current.status = 'active';
|
|
147
|
+
delete current.message;
|
|
148
|
+
state.status = 'running';
|
|
149
|
+
record(state, 'resumed', { stage: current.name });
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
die('usage: codex-run-state.mjs <init|status|begin|complete|finish|wait|block|resume> <workdir> ...');
|
|
153
|
+
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
die(error.message);
|
|
156
|
+
}
|