mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-29 05:11:19 -08:00
Grade every waiting lesson with a separate check before the lessons card asks for approval
AI Assisted
This commit is contained in:
1 parent
b06a4cb4ab
commit
1345aa0a95
36 files changed
+2812
-139
No files matched your search
@@ -35,7 +35,7 @@ On `local`, the map's bookkeeping is a script; the decisions are yours. `node "<
|
||||
|
||||
Load `./AGENTS.md` if it exists — its conventions govern; never re-ask what it answers. If missing, fold it into the Step 0 gate batch: *"No `AGENTS.md`. Pathfinder can chart without it. Continue, or run `plan2code-init` first?"* Record the outcome as the first line of `## Ground rules`: ``- `AGENTS.md` exists and governs.`` or, when missing, exactly ``- `AGENTS.md` is absent.`` (the handoff reads it).
|
||||
|
||||
**Lessons:** then read `references/lessons.md` and follow its Start and While working sections (`node "<S>/lessons.mjs"`).
|
||||
**Lessons:** then read `references/lessons.md` and follow its Start and While working sections (`node "<S>/lessons.mjs"`); note only what the person asks you to remember (references/lessons.md, While working).
|
||||
|
||||
## Rules
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ Check if `./AGENTS.md` exists:
|
||||
|
||||
Do not proceed until user confirms continuing without `AGENTS.md`.
|
||||
|
||||
**Lessons:** then read `references/lessons.md` and follow its Start and While working sections (`node "<S>/lessons.mjs"`); `<S>` is `scripts/` beside this SKILL.md, `~/.agents/skills/plan2code-1-plan/scripts/` globally.
|
||||
**Lessons:** then read `references/lessons.md` and follow its Start and While working sections (`node "<S>/lessons.mjs"`); note only what the person asks you to remember (references/lessons.md, While working); `<S>` is `scripts/` beside this SKILL.md, `~/.agents/skills/plan2code-1-plan/scripts/` globally.
|
||||
|
||||
## Rules
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ The FIRST thing you do, before anything else in this file — before Step 1, bef
|
||||
## Rules
|
||||
|
||||
- Follow `./AGENTS.md` if it exists
|
||||
- **Lessons:** then read `references/lessons.md` and follow its Start and While working sections (`node "<S>/lessons.mjs"`).
|
||||
- **Lessons:** then read `references/lessons.md` and follow its Start and While working sections (`node "<S>/lessons.mjs"`); note only what the person asks you to remember (references/lessons.md, While working).
|
||||
- Never remove completed `[x]` tasks without explicit approval
|
||||
- Warn if changes invalidate completed work
|
||||
- Keep task numbers sequential
|
||||
|
||||
@@ -22,7 +22,7 @@ The FIRST thing you do, before anything else in this file — before Auto-Discov
|
||||
## Rules
|
||||
|
||||
- Follow `./AGENTS.md` if it exists
|
||||
- **Lessons:** then read `references/lessons.md` and follow its Start and While working sections (`node "<S>/lessons.mjs"`).
|
||||
- **Lessons:** then read `references/lessons.md` and follow its Start and While working sections (`node "<S>/lessons.mjs"`); note only what the person asks you to remember (references/lessons.md, While working).
|
||||
- Require planning document before proceeding
|
||||
- Tasks must be specific enough for a developer with NO context
|
||||
- Use checkbox format `- [ ]` for Task items ONLY (not prerequisites, acceptance criteria, or success criteria)
|
||||
|
||||
@@ -24,7 +24,7 @@ The FIRST thing you do, before anything else in this file — before the Require
|
||||
## Rules
|
||||
|
||||
- Follow `./AGENTS.md` if it exists
|
||||
- **Lessons:** then read `references/lessons.md` and follow its Start and While working sections (`node "<S>/lessons.mjs"`).
|
||||
- **Lessons:** then read `references/lessons.md` and follow its Start and While working sections (`node "<S>/lessons.mjs"`); note only what the person asks you to remember (references/lessons.md, While working).
|
||||
- Complete steps IN ORDER
|
||||
- STOP and ask user before proceeding when:
|
||||
- Incomplete tasks found (Step 1)
|
||||
|
||||
@@ -14,7 +14,7 @@ The FIRST thing you do, before anything else in this file, before running a scri
|
||||
|
||||
Read `./AGENTS.md` when it exists: its commands, its `## Test map` and anything it says about slow suites or code reached by name. Dead Code still works without one, but the test map is what tells it which tests and build to run after a removal; without it the scripts read the project's config files, and the person confirms the commands.
|
||||
|
||||
**Lessons:** follow `references/lessons.md` → Start and While working.
|
||||
**Lessons:** follow `references/lessons.md` → Start and While working; note only what the person asks you to remember (references/lessons.md, While working).
|
||||
|
||||
## Scripts
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ The FIRST thing you do, before anything else in this file, before reading the br
|
||||
|
||||
Read `./AGENTS.md` when it exists: its commands, its `## Test map` and anything it says about slow suites. PR Prep still works without one: the scripts find the project's commands from its config files, and nothing here needs Plan2Code's specs.
|
||||
|
||||
**Lessons:** then read `references/lessons.md` and follow its Start and While working sections (`node "<S>/lessons.mjs"`).
|
||||
**Lessons:** then read `references/lessons.md` and follow its Start and While working sections (`node "<S>/lessons.mjs"`); note only what the person asks you to remember (references/lessons.md, While working).
|
||||
|
||||
## Scripts
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ When this file is `references/ui-prototype.md` inside Pathfinder, Plan, Revise p
|
||||
|
||||
Read `./AGENTS.md` when it exists: its stack, its style files and its conventions help Step 1 find the look. Its absence does not block this skill.
|
||||
|
||||
**Lessons:** then read `references/lessons.md` and follow its Start and While working sections (`node "<S>/lessons.mjs"`).
|
||||
**Lessons:** then read `references/lessons.md` and follow its Start and While working sections (`node "<S>/lessons.mjs"`); note only what the person asks you to remember (references/lessons.md, While working).
|
||||
|
||||
## Scripts
|
||||
|
||||
|
||||
+2
-1
@@ -139,7 +139,8 @@ The Learning row and banner send a `__learning` action with `do`. It is no hop:
|
||||
- `switch-off`: `switch off`.
|
||||
- `move-log`: `list --log-all`, then the card below.
|
||||
- `remove`: `remove --confirm` (the page already asked).
|
||||
- `review`: `list`, then the card below. While the state is `not-set-up`, `list --first-ask` instead: a `firstAsk` goes up as the reference's The first ask card (never `decide --file` before it), then `decide --first-ask yes` or `decide --first-ask no --skill dashboard`; on Yes, the card below from the list it returns.
|
||||
- `tidy`: while Learning is On, `tidy-input`, then up to 10 proposals, each `note --type tidy --change merge|reword|retire|move --targets <ids> --reason "<one sentence>" --skill dashboard` (`--text` for a merge or reword, `--area` for a move; one change each, nothing for lessons that are fine). A retire's reason is what you saw: git marks it and the code no longer does this, or `followed` 0 and none in 90 days (a hint only, never alone for a lesson that is not marked). Then the `review` check step with `check-input --tidy`, `list --check <checkId>` and the card below. No proposals: say so in the menu's `note`. In `decide`'s results a tidy-up's `outOfDate` is gone (its lesson changed since), and `applied` and `left` need no follow-up.
|
||||
- `review`: the check step from `references/lessons.md` End (check-input, the checker, check-record), with an `activity` line ("Checking 4 lessons") posted while it runs, then `list --check <checkId>` (`list` when there was nothing to check), then the card below. While the state is `not-set-up`, `list --first-ask` instead: a `firstAsk` goes up as the reference's The first ask card (never `decide --file` before it), then `decide --first-ask yes` or `decide --first-ask no --skill dashboard`; on Yes, the card below from the list it returns.
|
||||
|
||||
The card: post `list`'s `card` as one `lessons` item with `--wait` (the page shows it over the menu; give it a new `id` when an earlier lessons card is in the session). Write the reply's `Decisions:` JSON to a file in the session folder, adding what End step 6 says a choice still needs, run `decide --file <that file>`, and handle its results as End step 7 does. An empty `card` needs no post. The lessons card is the only question the dashboard shows: where End says to ask (a Move's `why` and `about`, or once more for an item), take `about` from the files the line names and post that row again as a new lessons card with the choices `Reword and move` and `Leave` (other rows: their own choices), its `note` saying what is needed.
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Helper Strength
|
||||
> Shared by the skills that start helpers (subagents): Init, Init Update, Pathfinder, Plan, Revise Plan, Document, Quick Task, Implement, Implement + Review, Review, Finalize, X-ray, Diagnose, PR Prep, Test, Dead Code and Update Dependencies. Read it when you first start a helper in a session. Never invoked as a skill.
|
||||
> Shared by the skills that start helpers (subagents): the dashboard (lesson check only), Init, Init Update, Pathfinder, Plan, Revise Plan, Document, Quick Task, Implement, Implement + Review, Review, Finalize, X-ray, Diagnose, PR Prep, Test, Dead Code and Update Dependencies. Read it when you first start a helper in a session. Never invoked as a skill.
|
||||
|
||||
## The words
|
||||
|
||||
@@ -24,6 +24,7 @@ Never write a model or vendor name in a brief, a report or a file, and never inv
|
||||
| Build task needing a design decision the spec leaves open | strongest (or keep it yourself) | high |
|
||||
| Pathfinder research question, sketch | standard | medium |
|
||||
| Plan's PLAN-DRAFT cross-check against the conversation | standard | medium |
|
||||
| Lesson check (`lesson-check.md`) | standard | medium |
|
||||
| Review analysis, focused scope | standard | high |
|
||||
| Review analysis, branch or full scope, or touching security, auth or data | strongest | high |
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
# Lesson check: the checker's brief
|
||||
> Read by the noting skills (Implement, Implement + Review, Quick Task, Diagnose, X-ray, Review, Test) and the dashboard when they start the checker, and by the checker itself. Never invoked as a skill.
|
||||
|
||||
You are the checker. You grade waiting lessons before a person decides on them. You judge only: the person still decides every lesson.
|
||||
|
||||
## Hard rules
|
||||
|
||||
- Never edit, create or delete any file.
|
||||
- Never run a command. The search results you need are already in the input.
|
||||
- Read only the files the input names (each lesson's `files`, plus `AGENTS.md` when `context.agentsMd` is set). Read nothing else.
|
||||
- Judge only: no fixes, no advice outside a verdict's reason or suggestion.
|
||||
- Return the JSON below as the whole reply: no prose before or after it, no code fence.
|
||||
|
||||
## The input
|
||||
|
||||
The JSON that `lessons.mjs check-input` printed:
|
||||
|
||||
- `checkId`: copy it into your reply unchanged.
|
||||
- `lessons`: each with `id`, `text`, `why`, `kind`, `about`, `files` (`path`, `hash`, `read`: `whole` or `sampled`), `budgetHit` (true when files were left unread) and, when the lesson carries a search, `search` and `searchResult` (`matched`, `hits`, `filesSearched`).
|
||||
- `context`: `agentsMd` (`AGENTS.md` or null), `saved` (the project's saved lessons: `id`, `text`) and `waiting` (the other waiting lessons: `id`, `text`).
|
||||
|
||||
## The four tests
|
||||
|
||||
Give every lesson all four, each a verdict and one sentence of reason.
|
||||
|
||||
- **true**: True against the code. Read the listed files and the search result: does the code still do what the lesson says? A `searchResult` that did not match, or matched where the lesson says it should not, counts against it.
|
||||
- **worth**: Worth keeping. Not obvious from reading the code, not a one-off, and the `why` earns its place. A teammate's run would act differently because of it.
|
||||
- **overlap**: Overlap or conflict. Compare with `context.saved`, `context.waiting` and `AGENTS.md`: a near-duplicate, or a statement that contradicts one. Name what it overlaps in the reason.
|
||||
- **clear**: Clear enough. One sentence a teammate can act on without this conversation: it names the thing and says what to do.
|
||||
|
||||
## Tidy-ups
|
||||
|
||||
With `check-input --tidy`, a lesson may carry `type: "tidy"`, `change` (merge, reword, retire or move), `reason` and `targets` (the saved lessons it touches: `id`, `text`, `why`, `kind`, `about`, `area`). Give it the same four tests and the same reply shape, judging the change:
|
||||
|
||||
- merge, reword: the lesson under test is `text`, the new wording, with the targets' `about`. **true**: it is still true against the files. **worth**: it is worth more than the targets said apart. **overlap**: it overlaps `context.saved` (the targets are left out of it). **clear**: one sentence a teammate can act on. A merge that drops a fact its targets held is a Doubt on **true**.
|
||||
- retire: grade the proposal, so Pass means the lesson should go. **true**: the reason holds against the files (the lesson no longer matches the code). **worth**: retiring loses nothing a teammate needs. **overlap**: no other saved lesson depends on it. **clear**: the reason is one plain sentence. `reason` is the proposer's view, never proof.
|
||||
- Suggest a wording only for a merge or reword; a retire or move has none to change, and a suggestion there is dropped.
|
||||
- move: `area` is where it lands (`targets[0].area` is where it is). **clear**: does the new area's name fit what the lesson is about? The other tests grade the lesson as it stands.
|
||||
|
||||
## The three verdicts
|
||||
|
||||
- **Pass**: it holds.
|
||||
- **Doubt**: you cannot tell, or it is weak. Give a Doubt when you could not read enough to decide, when `budgetHit` is true and the unread files could change the answer, or when the search does not test what the lesson says.
|
||||
- **Fail**: it is plainly wrong, a duplicate, a conflict, or unclear. Say what is wrong.
|
||||
|
||||
## A suggested wording
|
||||
|
||||
Optional, on a lesson with a Doubt or Fail where a better sentence would fix it. One sentence, at most 200 characters, in the same voice as the lesson, never a secret, a person's name or a customer detail. Leave `suggestion` out when you have none. A bad one is dropped.
|
||||
|
||||
## The reply
|
||||
|
||||
```json
|
||||
{
|
||||
"checkId": "<the input's checkId>",
|
||||
"how": "helper",
|
||||
"verdicts": [
|
||||
{
|
||||
"id": "<lesson id>",
|
||||
"tests": {
|
||||
"true": { "verdict": "Pass", "reason": "One sentence." },
|
||||
"worth": { "verdict": "Pass", "reason": "One sentence." },
|
||||
"overlap": { "verdict": "Doubt", "reason": "One sentence." },
|
||||
"clear": { "verdict": "Pass", "reason": "One sentence." }
|
||||
},
|
||||
"suggestion": "Optional one-sentence wording."
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
One verdict per lesson in `lessons`, none for a lesson not listed. `how` is `helper` when you are a fresh helper, `same-agent` when the noting agent grades in a separate step. Every `reason` is one sentence of at most 200 characters, on one line, with no secret in it.
|
||||
@@ -27,9 +27,12 @@ Once per run: when a reference sends you here inside a run that already did Star
|
||||
|
||||
- Before the first edit in a folder outside the areas already read, run `read --paths <that folder> --run <handle>`, keep the new `run`, and print its `line` when not empty, such as "Read 3 more for Web console server."
|
||||
- When a lesson changes what you do, and you would have done otherwise, print at that moment: "Following a lesson: <the lesson>".
|
||||
Then run `node "<S>/lessons.mjs" follow --lesson <its id> --skill <this skill>` (the ids come from `read`) so the reader can show how often lessons are followed. It is recorded on this machine only and does nothing while Learning is off; skip it quietly when it fails.
|
||||
- When your own memory disagrees with a lesson, follow the lesson and say "My own memory says otherwise; following the project's lesson: <the lesson>". If the person says the memory is right, note a doubt about that lesson.
|
||||
|
||||
The rest of this section is for the seven skills that note lessons: Implement, Implement + Review, Quick Task, Diagnose, X-ray, Review and Test.
|
||||
**Remember this (every skill that reads lessons).** When the person asks for something to be remembered ("remember this", "so this doesn't happen again" or the like), note it in that turn with `--source said` (the note commands below) and print the returned "Noted for the end of the run: <the lesson>" line. The script refuses a correction or convention without a `--why`: when the person gave no reason for one, ask one short question first ("Why does this matter?") and note it once with their answer as the Why; with no answer, note it with `--why "You asked for this to be remembered."`: the card's row then asks for the reason, and only a Reword with one saves it. Noting the same words again with a different `--why` replaces the waiting item. A said lesson in a skill with no End waits, and shows in the dashboard banner's Review.
|
||||
|
||||
Inferred lessons and fixes to `AGENTS.md` (below) are for the seven skills that note lessons only: Implement, Implement + Review, Quick Task, Diagnose, X-ray, Review and Test. The script refuses `--source inferred` from the other eight, which note only what the person said and the doubts Start step 5 and the memory bullet above ask for.
|
||||
|
||||
**What to offer.** Offer only what a teammate's run should follow: a fact about the code, never secrets, customer or personal details, or remarks about people. Facts about this codebase that a teammate would need are offered as lessons; a person's own preferences stay in whatever memory their agent keeps. Never offer what is already in `AGENTS.md` or in a lesson just read.
|
||||
|
||||
@@ -44,7 +47,8 @@ The rest of this section is for the seven skills that note lessons: Implement, I
|
||||
|
||||
**The note commands** (`--skill` is this skill's name, such as `implement`):
|
||||
|
||||
- A lesson: `node "<S>/lessons.mjs" note --type lesson --text "<one sentence>" --kind <kind> --about <one to three files, or one folder> --source said|inferred [--seen <files>] [--why "<one sentence>"] --skill <name>`
|
||||
- A lesson: `node "<S>/lessons.mjs" note --type lesson --text "<one sentence>" --kind <kind> --about <one to three files, or one folder> --source said|inferred [--seen <files>] [--why "<one sentence>"] [--shows-in <glob> --match should|never --text-match "<literal>"] --skill <name>`
|
||||
Give it a search (all three flags or none) when the lesson names text that should always, or never, appear in some files, such as "never `localStorage` in `src/web-console/public/**/*.js`": the check and later reads test it against the code, and a search that stops agreeing raises a doubt. The literal is one line, at most 120 characters.
|
||||
- A doubt about a saved lesson: `note --type doubt --target <lesson id> --found "<one sentence>" --skill <name>`
|
||||
- A fix to `AGENTS.md`: whatever corrects something `AGENTS.md` states is a fix, not a lesson: `note --type agents-fix --before "<exact text>" --after "<new text>" [--file .agents-docs/<name>.md] --skill <name>`. A test map row is `note --type agents-fix --test-map-row '<{"area","paths":[..],"run","shared"}>' --skill <name>`. Note a lesson only when `AGENTS.md` has no place for it.
|
||||
- A new area: when a lesson fits no existing area and is not general, run `areas --suggest` and note the fitting suggestion, or, when the test map offers none, a name and paths of your own: `note --type area --name "<Area name>" --paths <glob,glob> --skill <name>`. It shows in the same list as Create, Rename or Drop.
|
||||
@@ -53,13 +57,19 @@ Print the returned `line`, such as "Noted for the end of the run: <the lesson>".
|
||||
|
||||
## End
|
||||
|
||||
The seven noting skills only (and any skill sent here by Start's Review now), before the commit instructions and before the console's finish.
|
||||
The seven noting skills (and any skill sent here by Start's Review now) run it before the commit instructions and before the console's finish. The eight read-only skills have no End: their said lessons wait for the next noting run or the dashboard banner's Review.
|
||||
|
||||
1. Run `node "<S>/lessons.mjs" list` (`list --first-ask` when the state is `not-set-up`).
|
||||
**The check** (before step 1, unless the state is `not-set-up`). Skip it when `references/lesson-check.md` is not beside this file (a read-only skill sent here by Review now ships no checker brief): run plain `list`, and the rows show Not checked yet. Otherwise run `node "<S>/lessons.mjs" check-input`. `lessons` empty: skip the check and run step 1 as written. Otherwise:
|
||||
|
||||
- **Start the checker** with `references/lesson-check.md` and the JSON. With helpers on and available, it is a fresh helper given reading tools only, never relying on a permission mode (Claude Code: a custom helper already installed whose tool list holds only reading tools, such as `tools: Read, Grep, Glob`, never the built-in `Explore` or a general-purpose one, since both keep the shell; Devin: `run_subagent` with the read-only explore profile; Codex: a fresh helper told it may only read), `how: "helper"`, at `helper-strength.md`'s lesson check row (standard strength, medium effort). With Subagents off for the skill, no helper support, or (Claude Code) no reading-only helper installed, you grade in a separate step after re-reading the brief, `how: "same-agent"`; the card says so.
|
||||
- Write its reply to a file in the console session folder, or the OS temp folder in a terminal, never in the project. Run `check-record --file <path>`. Exit 4: give the checker its `problems` once and record again; still failing, step 1 runs `list --check-failed "<one line>"` and every lesson still shows.
|
||||
- Step 1 then runs `list --check <checkId>`. On the web console, post an `activity` line while it runs ("Checking 4 lessons").
|
||||
|
||||
1. Run `node "<S>/lessons.mjs" list` (`list --first-ask` when the state is `not-set-up`; `list --check <checkId>` after a check, or `list --check-failed "<one line>"` when it failed).
|
||||
2. `items` empty and no `firstAsk`: say nothing and skip this step.
|
||||
3. `firstAsk` present: see The first ask below, instead of 4 to 7.
|
||||
4. Show `opening` first when present.
|
||||
5. **On the web console:** post the returned `card` as one `lessons` item with `--wait` (a new `id` when an earlier lessons card is in the session). Its reply has one line per decision ("Keep: ...", "Reword: ...") and a `Decisions:` line holding them as JSON: that JSON is step 6's file, plus what a choice still needs. A `Suggestions wanted on` line for it: reply in its `thread` and, in the same patch, send `suggested` (row id to one of that row's `choices`, such as `{"w1":"Keep"}`), which outlines those buttons without choosing them. **In a terminal:** ask each group in `rounds` with your question tool, one question per item with exactly its `choices` and nothing pre-selected (`heading`, `text`, `why`, `origin` and `note` are what the person reads; an area shows its `name` and `paths`); with no question tool, a numbered list. A choice that needs more (step 6) asks the person for it.
|
||||
5. **On the web console:** post the returned `card` as one `lessons` item with `--wait` (a new `id` when an earlier lessons card is in the session). Its reply has one line per decision ("Keep: ...", "Reword: ...") and a `Decisions:` line holding them as JSON: that JSON is step 6's file, plus what a choice still needs. A `Suggestions wanted on` line for it: reply in its `thread` and, in the same patch, send `suggested` (row id to one of that row's `choices`, such as `{"w1":"Keep"}`), which outlines those buttons without choosing them. **In a terminal:** ask each group in `rounds` with your question tool, one question per item with exactly its `choices` and nothing pre-selected (`heading`, `text`, `why`, `origin` and `note` are what the person reads; an area shows its `name` and `paths`); with no question tool, a numbered list. Show the card's `checked` line first ("Checked 6 lessons in 40 seconds by a fresh helper that could only read", "... by the same agent that noted them", or "The check could not run: <reason>"). Read each item's `check` and `tag` into its text in this order: every Fail, then every Doubt (each as "Fail <test>: <reason>"), then the pass line ("Passed the other N", "Passed the check" with none, and no pass line when all four found something), then its `tag` when present. A `suggestion` is offered as a Reword carrying exactly those words, which the person may adjust. A choice that needs more (step 6) asks the person for it.
|
||||
6. Write the decisions, one `{ "id", "choice" }` per answered item plus what its choice needs, to a JSON file in the console session folder, or the OS temp folder in a terminal, never in the project. Run `decide --file <path>` and print its `closing` line, such as "Kept 2 (1 reworded), retired 1. 1 still waiting." What a choice needs:
|
||||
- Reword of a lesson, a doubt or a lesson whose files are gone: the new `text`, plus `why`, `kind`, `about` or `area` when they change.
|
||||
- Rename of an area: the new `name`, plus `paths` when they change.
|
||||
@@ -74,7 +84,7 @@ Never stage or commit: what End writes is part of the run's change.
|
||||
|
||||
## Unattended runs
|
||||
|
||||
A run with nobody there (an Implementation Loop phase started with `--loop`, or a helper) follows Start without asking the heads-up, follows While working and notes lessons, but never runs End, never approves and never shows the first ask. A helper reports a lesson to the main agent in its result, and the main agent notes it as its own. When `note` exits 5 in an unattended run, the lesson is not written, and the run's report says "1 lesson was not noted: it held secret-shaped text" without the text.
|
||||
A run with nobody there (an Implementation Loop phase started with `--loop`, or a helper) follows Start without asking the heads-up, follows While working, notes lessons, records each "Following a lesson" moment with `follow` (as above; a helper reports its follows to the main agent, which records them), but never runs End, never approves and never shows the first ask. A helper reports a lesson to the main agent in its result, and the main agent notes it as its own. When `note` exits 5 in an unattended run, the lesson is not written, and the run's report says "1 lesson was not noted: it held secret-shaped text" without the text. A loop phase never runs the check: its lessons are graded at the next lessons card.
|
||||
|
||||
## With Learning off
|
||||
|
||||
|
||||
+923
-38
File diff suppressed because it is too large.
Load diff
@@ -26,7 +26,7 @@ The ✕ on a chip (after the page's two-step confirm) sends `session:[{"i":"__de
|
||||
|
||||
## A Learning action
|
||||
|
||||
The Learning row and banner send `session:[{"i":"__learning","do":"switch-on"}]` (`do` is `review`, `switch-on`, `switch-off`, `move-log` or `remove`; Remove was confirmed on the page). No hop: you stay the dashboard. Run `lessons.mjs` as the dashboard skill's "A Learning action arrives" says (a `review` while Learning is not set up is `list --first-ask` and the first ask, before anything is kept; the lessons card is the only question this page shows), then `open --resume <sid> --no-open --workflow dashboard` and post the menu again with `--wait`. Pause for me never reaches you: the page saves it itself. A `__launch` with `fromBanner: true` came from a dashboard showing lessons waiting.
|
||||
The Learning row and banner send `session:[{"i":"__learning","do":"switch-on"}]` (`do` is `review`, `switch-on`, `switch-off`, `move-log`, `remove` or `tidy`; Remove was confirmed on the page). No hop: you stay the dashboard. Run `lessons.mjs` as the dashboard skill's "A Learning action arrives" says (a `review` while Learning is not set up is `list --first-ask` and the first ask, before anything is kept; the lessons card is the only question this page shows), then `open --resume <sid> --no-open --workflow dashboard` and post the menu again with `--wait`. Pause for me never reaches you: the page saves it itself. A `__launch` with `fromBanner: true` came from a dashboard showing lessons waiting.
|
||||
|
||||
## A strength suggestion
|
||||
|
||||
|
||||
@@ -126,6 +126,49 @@ export function writePause(cwd, paused, now) {
|
||||
return { paused: true, since };
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ follow counts */
|
||||
|
||||
/** One line per "Following a lesson" moment, on this machine only. */
|
||||
function followsFile(cwd) {
|
||||
return path.join(storeDir(cwd), "follows.ndjson");
|
||||
}
|
||||
|
||||
/**
|
||||
* Append one follow: `{"lesson":"<area>/<slug>","at":"<ISO>","skill":"<name>"}`.
|
||||
* The file is only ever appended to, so two runs at once cannot lose a count.
|
||||
*/
|
||||
export function recordFollow(cwd, { lesson, skill }, now) {
|
||||
const file = followsFile(cwd);
|
||||
ensureDir(path.dirname(file));
|
||||
const line = JSON.stringify({ lesson: String(lesson), at: toDate(now).toISOString(), skill: String(skill) });
|
||||
fs.appendFileSync(file, line + "\n");
|
||||
}
|
||||
|
||||
/** `{ <lesson id>: { count, last } }`, summed on read; an unreadable line is skipped. */
|
||||
export function followCounts(cwd) {
|
||||
let text;
|
||||
try {
|
||||
text = fs.readFileSync(followsFile(cwd), "utf8");
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
const counts = {};
|
||||
for (const raw of text.split("\n")) {
|
||||
if (!raw.trim()) continue;
|
||||
let row;
|
||||
try {
|
||||
row = JSON.parse(raw);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
if (!row || typeof row.lesson !== "string" || typeof row.at !== "string" || Number.isNaN(Date.parse(row.at))) continue;
|
||||
const c = counts[row.lesson] || (counts[row.lesson] = { count: 0, last: row.at });
|
||||
c.count += 1;
|
||||
if (Date.parse(row.at) > Date.parse(c.last)) c.last = row.at;
|
||||
}
|
||||
return counts;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------ the waiting store */
|
||||
|
||||
const pad = (n) => String(n).padStart(2, "0");
|
||||
@@ -232,9 +275,42 @@ export function learningState(cwd = process.cwd(), now, { prune = true } = {}) {
|
||||
|
||||
/* ------------------------------------------------------- the console's view */
|
||||
|
||||
// Where the dashboard starts to nudge a tidy-up: general.md holds at most 25
|
||||
// lessons (GENERAL_MAX in lessons.mjs, which the installed console does not
|
||||
// carry), so 22 is close; an area file has no cap, so 30 is a long file.
|
||||
export const NEAR_CAP_GENERAL = 22;
|
||||
export const NEAR_CAP_AREA = 30;
|
||||
|
||||
/**
|
||||
* Whether the project's saved lessons are crowded: general.md at 22 or more,
|
||||
* or any other area file at 30 or more (counted as `### ` headings). Reads
|
||||
* only; a missing folder or an unreadable file counts as not crowded.
|
||||
*/
|
||||
export function lessonsNearCap(cwd = process.cwd()) {
|
||||
const dir = path.join(worktreeOf(cwd), ".plan2code", "lessons");
|
||||
let names;
|
||||
try {
|
||||
names = fs.readdirSync(dir);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
for (const name of names) {
|
||||
if (!name.endsWith(".md")) continue;
|
||||
let text;
|
||||
try {
|
||||
text = fs.readFileSync(path.join(dir, name), "utf8");
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
const count = text.split(/\r?\n/).filter((l) => l.startsWith("### ")).length;
|
||||
if (count >= (name === "general.md" ? NEAR_CAP_GENERAL : NEAR_CAP_AREA)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* What the dashboard's scan carries as `scan.learning`:
|
||||
* `{ state, pausedSince, waiting, oldestDays }`, or null when the state is
|
||||
* `{ state, pausedSince, waiting, oldestDays, nearCap }`, or null when the state is
|
||||
* `unknown` (a settings format this console does not know: the page then
|
||||
* draws no row) or when the core fails, so a broken store never fails `open`.
|
||||
* Reads without pruning: the console server writes nothing here but the pause.
|
||||
@@ -254,5 +330,6 @@ export function learningScan(cwd = process.cwd(), { now, read = learningState }
|
||||
pausedSince: s.pausedSince || null,
|
||||
waiting: Number.isInteger(waiting.count) ? waiting.count : 0,
|
||||
oldestDays: Number.isInteger(waiting.oldestDays) ? waiting.oldestDays : 0,
|
||||
nearCap: s.state === "on" && lessonsNearCap(cwd),
|
||||
};
|
||||
}
|
||||
@@ -856,9 +856,12 @@ export const ITEM_KINDS = new Set([
|
||||
// type and its choices, and nothing arrives already chosen (FR-14, FR-15).
|
||||
// `gone` is a saved lesson whose files no longer exist: the list offers it
|
||||
// with a doubt's words.
|
||||
export const LESSON_ROW_TYPES = ["lesson", "doubt", "gone", "agents-fix", "log-line", "area"];
|
||||
const LESSON_ROW_TEXT = ["why", "kind", "area", "origin", "note", "before", "after", "found", "heading", "file", "name"];
|
||||
const LESSON_ROW_LISTS = ["about", "areas", "flags", "lessons", "paths"];
|
||||
// `tidy` is a proposed change to saved lessons (merge, reword, retire or
|
||||
// move): `change` names it, `targets` the lessons it touches, and a merge or
|
||||
// reword carries its new `wording` and that wording's `wordingWhy`.
|
||||
export const LESSON_ROW_TYPES = ["lesson", "doubt", "gone", "agents-fix", "tidy", "log-line", "area"];
|
||||
const LESSON_ROW_TEXT = ["why", "kind", "area", "origin", "note", "before", "after", "found", "heading", "file", "name", "change", "wording", "wordingWhy"];
|
||||
const LESSON_ROW_LISTS = ["about", "areas", "flags", "lessons", "paths", "targets"];
|
||||
const LESSONS_RIGHT = {
|
||||
kind: "lessons",
|
||||
rows: [{ id: "w1", type: "lesson", text: "Run a page test with node scripts/node-test.mjs <file>.", choices: ["Keep", "Reword", "Drop"] }],
|
||||
@@ -868,6 +871,49 @@ const FIRST_ASK_RIGHT = {
|
||||
firstAsk: { lesson: { id: "w1", text: "..." }, sentences: ["...", "...", "..."], yes: "Switch Learning on", no: "Not for this project", later: "..." },
|
||||
};
|
||||
|
||||
// What the check found, as lessons.mjs list puts it on a row (`check`) and on
|
||||
// the card (`checked`), and the two words a row's `tag` may carry.
|
||||
export const LESSON_ROW_TAGS = ["Checked in an earlier run", "Not checked yet"];
|
||||
const LESSON_CHECK_KEYS = ["fails", "doubts", "passed", "suggestion"];
|
||||
const CHECK_RIGHT = { check: { fails: [{ test: "Search", reason: "It matches 3 files." }], doubts: [], passed: 3, suggestion: "A shorter wording." } };
|
||||
const CHECKED_RIGHT = { checked: { how: "helper", count: 6, seconds: 40 } };
|
||||
const isCount = (n) => Number.isInteger(n) && n >= 0;
|
||||
|
||||
function lessonCheckProblems(check, name, at) {
|
||||
if (!isPlainObject(check)) return [rule(at, name, "must be the { fails, doubts, passed, suggestion? } lessons.mjs gave", CHECK_RIGHT)];
|
||||
const problems = [];
|
||||
for (const key of Object.keys(check)) {
|
||||
if (!LESSON_CHECK_KEYS.includes(key)) problems.push(rule(at, `${name} "${key}"`, `is not a field of a check. Use ${LESSON_CHECK_KEYS.join(", ")}`, CHECK_RIGHT));
|
||||
}
|
||||
for (const key of ["fails", "doubts"]) {
|
||||
const list = check[key];
|
||||
if (list == null) continue;
|
||||
if (!Array.isArray(list) || list.length > 4) {
|
||||
problems.push(rule(at, `${name} ${key}`, "must be an array of at most 4 { test, reason } entries", CHECK_RIGHT));
|
||||
continue;
|
||||
}
|
||||
list.forEach((e, i) => {
|
||||
const ok = isPlainObject(e) && typeof e.test === "string" && typeof e.reason === "string" && e.reason.length <= 240;
|
||||
if (!ok) problems.push(rule(at, `${name} ${key}[${i}]`, "must be { test, reason }, two strings, the reason at most 240 characters", CHECK_RIGHT));
|
||||
});
|
||||
}
|
||||
if (check.passed != null && !(Number.isInteger(check.passed) && check.passed >= 0 && check.passed <= 4)) {
|
||||
problems.push(rule(at, `${name} passed`, "must be a whole number from 0 to 4", CHECK_RIGHT));
|
||||
}
|
||||
if (check.suggestion != null && (typeof check.suggestion !== "string" || check.suggestion.length > 200)) {
|
||||
problems.push(rule(at, `${name} suggestion`, "must be a string of at most 200 characters, or left out", CHECK_RIGHT));
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
function lessonsCheckedProblems(checked, at) {
|
||||
const how = isPlainObject(checked) && ["helper", "same-agent"].includes(checked.how);
|
||||
const ran = how && isCount(checked.count) && isCount(checked.seconds) && Object.keys(checked).every((k) => ["how", "count", "seconds"].includes(k));
|
||||
const failed = isPlainObject(checked) && typeof checked.failed === "string" && checked.failed.length <= 200 && Object.keys(checked).length === 1;
|
||||
if (ran || failed) return [];
|
||||
return [rule(at, "checked", 'must be { how: "helper" or "same-agent", count, seconds } (whole numbers), or { failed } with a reason of at most 200 characters', CHECKED_RIGHT)];
|
||||
}
|
||||
|
||||
// What is wrong with a lessons item, as rule() sentences.
|
||||
function lessonsProblems(item, at) {
|
||||
const problems = [];
|
||||
@@ -923,7 +969,12 @@ function lessonsProblems(item, at) {
|
||||
if (row.refused != null && !isPlainObject(row.refused)) {
|
||||
problems.push(rule(at, `${name} refused`, "must be the { pattern, part } lessons.mjs gave, or null", { refused: { pattern: "aws-access-key", part: "AKIA" } }));
|
||||
}
|
||||
if (row.check != null) problems.push(...lessonCheckProblems(row.check, `${name} check`, at));
|
||||
if (row.tag != null && !LESSON_ROW_TAGS.includes(row.tag)) {
|
||||
problems.push(rule(at, `${name} tag`, `must be one of ${LESSON_ROW_TAGS.map((t) => `"${t}"`).join(", ")}, or left out`, { tag: LESSON_ROW_TAGS[0] }));
|
||||
}
|
||||
});
|
||||
if (item.checked != null) problems.push(...lessonsCheckedProblems(item.checked, at));
|
||||
// The agent's answer to Ask for suggestions, readable by the page: row id to
|
||||
// one of that row's own choice words. It outlines a button; it never picks.
|
||||
const sug = item.suggested;
|
||||
|
||||
@@ -191,11 +191,11 @@ export function answerLines(item, v) {
|
||||
|
||||
// The choice that keeps a row as it stands, per row type (FR-15). A refused
|
||||
// row cannot take it until it is reworded.
|
||||
export const LESSON_KEEP_WORD = { lesson: "Keep", doubt: "Keep", gone: "Keep", "agents-fix": "Apply", "log-line": "Move", area: "Create" };
|
||||
export const LESSON_KEEP_WORD = { lesson: "Keep", doubt: "Keep", gone: "Keep", "agents-fix": "Apply", tidy: "Apply", "log-line": "Move", area: "Create" };
|
||||
// The choices that open the row for editing.
|
||||
export const LESSON_EDIT_WORDS = new Set(["Reword", "Reword and move", "Rename"]);
|
||||
// The edit word per row type: what a refused row's keep word goes back to.
|
||||
export const LESSON_EDIT_WORD = { lesson: "Reword", doubt: "Reword", gone: "Reword", "agents-fix": "Reword", "log-line": "Reword and move", area: "Rename" };
|
||||
export const LESSON_EDIT_WORD = { lesson: "Reword", doubt: "Reword", gone: "Reword", "agents-fix": "Reword", tidy: "Reword", "log-line": "Reword and move", area: "Rename" };
|
||||
// The first ask's answers, as the agent reads them.
|
||||
export const FIRST_ASK_WORDS = { yes: "Switch Learning on", no: "Not for this project" };
|
||||
|
||||
@@ -211,12 +211,17 @@ export function lessonEditField(row) {
|
||||
// list gave none (a refused line comes masked and with none).
|
||||
const logLessons = (row) => (Array.isArray(row.lessons) && row.lessons.length ? row.lessons.map(String) : [row.text || ""]);
|
||||
|
||||
/** The edit fields' first values: the row as it stands. */
|
||||
export function lessonEditStart(row) {
|
||||
if (row.type === "agents-fix") return { after: lessonOriginal(row) };
|
||||
if (row.type === "area") return { name: lessonOriginal(row), paths: [...(row.paths || [])] };
|
||||
if (row.type === "log-line") return { lessons: logLessons(row), why: row.why || "", area: row.area || "" };
|
||||
return { text: lessonOriginal(row), why: row.why || "", area: row.area || "" };
|
||||
/**
|
||||
* The edit fields' first values: the row as it stands, or its text replaced by
|
||||
* `prefill` (a suggested wording) when one is given.
|
||||
*/
|
||||
export function lessonEditStart(row, prefill) {
|
||||
const given = typeof prefill === "string" && prefill.trim() ? prefill : null;
|
||||
if (row.type === "agents-fix") return { after: given ?? lessonOriginal(row) };
|
||||
if (row.type === "area") return { name: given ?? lessonOriginal(row), paths: [...(row.paths || [])] };
|
||||
if (row.type === "log-line") return { lessons: given ? [given] : logLessons(row), why: row.why || "", area: row.area || "" };
|
||||
if (row.type === "tidy") return { text: given ?? lessonOriginal(row), why: row.wordingWhy || "", area: row.area || "" };
|
||||
return { text: given ?? lessonOriginal(row), why: row.why || "", area: row.area || "" };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -227,6 +232,8 @@ export function lessonOriginal(row) {
|
||||
if (row.type === "agents-fix") return row.after || row.text || "";
|
||||
if (row.type === "area") return row.name || row.text || "";
|
||||
if (row.type === "log-line") return logLessons(row).join("\n");
|
||||
// A tidy row's words are the new wording, not the sentence describing the change.
|
||||
if (row.type === "tidy") return row.wording || "";
|
||||
return row.text || "";
|
||||
}
|
||||
|
||||
@@ -267,7 +274,8 @@ export function lessonDecision(row, choice, edit = {}) {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
const why = typeof edit.why === "string" ? edit.why.trim() : row.why || "";
|
||||
const baseWhy = row.type === "tidy" ? row.wordingWhy || "" : row.why || "";
|
||||
const why = typeof edit.why === "string" ? edit.why.trim() : baseWhy;
|
||||
const area = typeof edit.area === "string" && edit.area && edit.area !== (row.area || "") ? edit.area : "";
|
||||
if (row.type === "log-line") {
|
||||
const texts = typed.split("\n");
|
||||
@@ -275,7 +283,7 @@ export function lessonDecision(row, choice, edit = {}) {
|
||||
}
|
||||
const out = { ...d, text: typed };
|
||||
// An emptied Why is sent as "", so decide does not keep the old one.
|
||||
if (why || (typeof edit.why === "string" && row.why)) out.why = why;
|
||||
if (why || (typeof edit.why === "string" && baseWhy)) out.why = why;
|
||||
if (area) out.area = area;
|
||||
return out;
|
||||
}
|
||||
@@ -294,7 +302,7 @@ export function lessonMissing(row, decision) {
|
||||
/** The words one decision reads as: "Keep: <text>", "Reword: <new text>", "Apply: <file>". */
|
||||
export function lessonDecisionLine(row, d) {
|
||||
const shown =
|
||||
d.choice === "Apply"
|
||||
d.choice === "Apply" && !(row && row.type === "tidy")
|
||||
? (row && row.file) || "AGENTS.md"
|
||||
: Array.isArray(d.lessons)
|
||||
? d.lessons.map((l) => (l && l.text) || "").join(" / ")
|
||||
@@ -982,13 +990,14 @@ export function deleteReply(spec) {
|
||||
// A Learning control on the dashboard (screens/learning-row.js and the
|
||||
// waiting banner). No hop: the dashboard agent runs lessons.mjs for it. Plain
|
||||
// wording, no em dashes: these lines are read by the agent.
|
||||
export const LEARNING_ACTIONS = ["review", "switch-on", "switch-off", "move-log", "remove"];
|
||||
export const LEARNING_ACTIONS = ["review", "switch-on", "switch-off", "move-log", "remove", "tidy"];
|
||||
const LEARNING_REPLIES = {
|
||||
review: "Review the waiting lessons.",
|
||||
"switch-on": "Switch Learning on for this project.",
|
||||
"switch-off": "Switch Learning off for this project.",
|
||||
"move-log": "Move the failure log into lessons.",
|
||||
remove: "Remove all saved lessons from this project. Learning stays on.",
|
||||
tidy: "Tidy up the saved lessons: propose merges, rewords, retires and moves.",
|
||||
};
|
||||
export function learningAction(what) {
|
||||
if (!LEARNING_ACTIONS.includes(what)) throw new Error("unknown Learning action: " + what);
|
||||
@@ -1016,6 +1025,13 @@ export function learningBannerText(learning) {
|
||||
return `${n} ${n === 1 ? "lesson is" : "lessons are"} waiting for your review (oldest ${d} ${d === 1 ? "day" : "days"}).`;
|
||||
}
|
||||
|
||||
// The tidy-up nudge's line, or "" when it shows nothing: the saved lessons are
|
||||
// near their limit (the scan's nearCap) and Learning is on.
|
||||
export function learningNearCapText(learning) {
|
||||
if (!learning || learning.state !== "on" || learning.nearCap !== true) return "";
|
||||
return "Lessons are nearing their limit. Tidy up?";
|
||||
}
|
||||
|
||||
// What the delete dialog says about the spec, from the scan alone. `touched`
|
||||
// stays a number: the page formats it in the person's own locale.
|
||||
// A handoff on the dashboard (scan.handoffs). The page sends only the id; the
|
||||
|
||||
@@ -41,6 +41,7 @@ import {
|
||||
lessonDecision,
|
||||
lessonMissing,
|
||||
lessonEditStart,
|
||||
lessonEditField,
|
||||
lessonReworded,
|
||||
startsTicked,
|
||||
} from "../answers.js";
|
||||
@@ -1825,6 +1826,8 @@ function buildLessons(card, item, staged) {
|
||||
};
|
||||
|
||||
if (item.opening) card.appendChild(el("p", "lessons-opening", item.opening));
|
||||
const how = lessonsCheckedLine(item.checked);
|
||||
if (how) card.appendChild(el("p", "lessons-checked", how));
|
||||
const list = el("ul", "lessons-rows");
|
||||
for (const row of item.rows || []) list.appendChild(lessonRow(item, row, draft, commit));
|
||||
card.appendChild(list);
|
||||
@@ -1850,6 +1853,61 @@ function buildLessons(card, item, staged) {
|
||||
commentField(card, item, "Anything to add?");
|
||||
}
|
||||
|
||||
const plural = (n, one) => `${n} ${one}${n === 1 ? "" : "s"}`;
|
||||
|
||||
// The card's one how-checked line, or "" when the card carries none.
|
||||
function lessonsCheckedLine(checked) {
|
||||
if (!checked || typeof checked !== "object") return "";
|
||||
if (typeof checked.failed === "string") return `The check could not run: ${checked.failed}`;
|
||||
const by = checked.how === "helper" ? "a fresh helper that could only read" : checked.how === "same-agent" ? "the same agent that noted them" : "";
|
||||
if (!by) return "";
|
||||
return `Checked ${plural(checked.count, "lesson")} in ${plural(checked.seconds, "second")} by ${by}`;
|
||||
}
|
||||
|
||||
// What the check found on one row: each Fail then each Doubt on a line of its
|
||||
// own, then a quiet pass line. Nothing at all for a row the check never saw.
|
||||
function lessonCheckLines(li, item, row, draft, commit) {
|
||||
const check = row.check;
|
||||
if (!check || typeof check !== "object") return;
|
||||
const fails = Array.isArray(check.fails) ? check.fails : [];
|
||||
const doubts = Array.isArray(check.doubts) ? check.doubts : [];
|
||||
const box = el("div", "lesson-checks");
|
||||
for (const [word, list] of [["Fail", fails], ["Doubt", doubts]]) {
|
||||
for (const e of list) {
|
||||
const line = el("p", "lesson-check " + word.toLowerCase());
|
||||
line.appendChild(el("span", "lesson-check-word", word));
|
||||
line.appendChild(document.createTextNode(` ${e.test}: ${e.reason}`));
|
||||
box.appendChild(line);
|
||||
}
|
||||
}
|
||||
const found = fails.length + doubts.length;
|
||||
// With all four tests flagged there is nothing left that passed.
|
||||
if (!found || check.passed !== 0) box.appendChild(el("p", "lesson-check-pass", found && Number.isInteger(check.passed) ? `Passed the other ${check.passed}` : "Passed the check"));
|
||||
if (check.suggestion) {
|
||||
const sug = el("p", "lesson-suggestion");
|
||||
sug.appendChild(el("span", null, `Suggested wording: ${check.suggestion}`));
|
||||
const use = el("button", "btn sm", "Use this wording");
|
||||
use.type = "button";
|
||||
use.id = `lesson-use-${item.id}-${row.id}`;
|
||||
use.addEventListener("click", () => {
|
||||
// Picks Reword and opens it on the suggestion; what is sent is a
|
||||
// normal Reword of whatever the person leaves in the box.
|
||||
const word = LESSON_EDIT_WORD[row.type];
|
||||
draft.picks[row.id] = (row.choices || []).includes(word) ? word : "Reword";
|
||||
draft.leaveAll = false;
|
||||
// Only the words change: a Why or Area already typed stays.
|
||||
const start = lessonEditStart(row, check.suggestion);
|
||||
const key = lessonEditField(row).key;
|
||||
draft.edits[row.id] = { ...(draft.edits[row.id] || start), [key]: start[key] };
|
||||
commit(true);
|
||||
document.getElementById(use.id)?.focus();
|
||||
});
|
||||
sug.appendChild(use);
|
||||
box.appendChild(sug);
|
||||
}
|
||||
li.appendChild(box);
|
||||
}
|
||||
|
||||
// One waiting item: what it is, why, where it came from, and its own choices.
|
||||
function lessonRow(item, row, draft, commit) {
|
||||
const pick = draft.picks[row.id] || "";
|
||||
@@ -1868,6 +1926,16 @@ function lessonRow(item, row, draft, commit) {
|
||||
pair.appendChild(el("p", "lessons-fix-label", "After"));
|
||||
pair.appendChild(el("blockquote", "lessons-after", row.after || row.text || ""));
|
||||
li.appendChild(pair);
|
||||
} else if (row.type === "tidy") {
|
||||
li.appendChild(el("p", "lessons-text", row.text));
|
||||
// A merge or reword replaces lessons already saved: show them, so the change reads whole.
|
||||
const was = (row.targets || []).filter((t) => t && t.text);
|
||||
if ((row.change === "merge" || row.change === "reword") && was.length) {
|
||||
li.appendChild(el("p", "lessons-heading", row.change === "merge" ? "It replaces these lessons:" : "It replaces this wording:"));
|
||||
const ul = el("ul", "lessons-become");
|
||||
for (const t of was) ul.appendChild(el("li", null, t.text));
|
||||
li.appendChild(ul);
|
||||
}
|
||||
} else if (row.type === "log-line") {
|
||||
li.appendChild(el("p", "lessons-text", row.text));
|
||||
const become = (row.lessons || []).filter(Boolean);
|
||||
@@ -1885,6 +1953,8 @@ function lessonRow(item, row, draft, commit) {
|
||||
// The doubt's and the fix's origin repeat what is drawn above them.
|
||||
if (row.origin && !["doubt", "gone", "agents-fix"].includes(row.type)) li.appendChild(el("p", "lessons-origin", row.origin));
|
||||
if (row.note) li.appendChild(el("p", "lessons-note", row.note));
|
||||
if (row.tag) li.appendChild(el("p", "lessons-tag", row.tag));
|
||||
lessonCheckLines(li, item, row, draft, commit);
|
||||
|
||||
for (const f of Array.isArray(row.flags) ? row.flags : []) {
|
||||
const what = FLAG_WORDS[f && f.pattern] || "something personal";
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
loopDriving,
|
||||
learningBusyNow,
|
||||
LEARNING_BUSY_MS,
|
||||
learningBusyLimit,
|
||||
} from "../selectors.js";
|
||||
import { whenTitle, whenWords } from "../labels.js";
|
||||
import { hooks, page, redraw, saveNow } from "../state.js";
|
||||
@@ -49,6 +50,7 @@ import {
|
||||
learningAction,
|
||||
learningReply,
|
||||
learningBannerText,
|
||||
learningNearCapText,
|
||||
noteSwitchShows,
|
||||
noteTabEmpty,
|
||||
defaultNoteTicks,
|
||||
@@ -1440,16 +1442,17 @@ function learningBanner(sc) {
|
||||
const busy = learningBusyNow(state);
|
||||
// Review pressed, or the choices just saved: the banner says what the agent
|
||||
// is doing, in the same place, so the wait is never silent.
|
||||
const working = busy && (busy.what === "review" || busy.what === "decide") ? busy : null;
|
||||
const working = busy && (busy.what === "review" || busy.what === "decide" || busy.what === "tidy") ? busy : null;
|
||||
const text = learningBannerText(sc && sc.learning);
|
||||
if (!text && !working) return null;
|
||||
const nudge = learningNearCapText(sc && sc.learning);
|
||||
if (!text && !nudge && !working) return null;
|
||||
const banner = el("div", "callout is-info dash-nudge learn-banner");
|
||||
banner.setAttribute("role", "status");
|
||||
if (working) {
|
||||
banner.classList.add("is-busy");
|
||||
banner.setAttribute("aria-busy", "true");
|
||||
const line = el("span", "dash-nudge-text learn-busy");
|
||||
line.append(el("span", "spinner tiny"), document.createTextNode(working.what === "review" ? "Opening lessons…" : "Saving your lessons…"));
|
||||
line.append(el("span", "spinner tiny"), document.createTextNode(working.what === "review" ? "Opening lessons…" : working.what === "tidy" ? "Looking over your lessons…" : "Saving your lessons…"));
|
||||
banner.appendChild(line);
|
||||
if (working.what === "review") {
|
||||
const review = el("button", "btn sm primary", "Review");
|
||||
@@ -1459,14 +1462,21 @@ function learningBanner(sc) {
|
||||
}
|
||||
return banner;
|
||||
}
|
||||
banner.appendChild(el("span", "dash-nudge-text", text));
|
||||
const review = el("button", "btn sm primary", "Review");
|
||||
review.type = "button";
|
||||
const why = hooks.learningBlocked();
|
||||
review.disabled = Boolean(why);
|
||||
if (why) review.title = why;
|
||||
review.addEventListener("click", () => sendLearning("review"));
|
||||
banner.appendChild(review);
|
||||
// Each line is its own row with its own button: lessons waiting, and lessons near their limit.
|
||||
const row = (words, label, what, primary) => {
|
||||
const r = el("div", "learn-banner-row");
|
||||
r.appendChild(el("span", "dash-nudge-text", words));
|
||||
const b = el("button", "btn sm" + (primary ? " primary" : ""), label);
|
||||
b.type = "button";
|
||||
b.disabled = Boolean(why);
|
||||
if (why) b.title = why;
|
||||
b.addEventListener("click", () => sendLearning(what));
|
||||
r.appendChild(b);
|
||||
banner.appendChild(r);
|
||||
};
|
||||
if (text) row(text, "Review", "review", true);
|
||||
if (nudge) row(nudge, "Tidy up", "tidy", !text);
|
||||
return banner;
|
||||
}
|
||||
|
||||
@@ -1478,7 +1488,7 @@ function learningBanner(sc) {
|
||||
function watchLearningBusy(busy) {
|
||||
const timer = setInterval(() => {
|
||||
if (page.learningBusy !== busy) return clearInterval(timer);
|
||||
if (Date.now() - busy.at > LEARNING_BUSY_MS) {
|
||||
if (Date.now() - busy.at > learningBusyLimit(busy)) {
|
||||
clearInterval(timer);
|
||||
page.learningBusy = null;
|
||||
redraw();
|
||||
@@ -1493,8 +1503,8 @@ function watchLearningBusy(busy) {
|
||||
if (!busy.seen && Date.now() - busy.at < 3000) return;
|
||||
clearInterval(timer);
|
||||
page.learningBusy = null;
|
||||
if (busy.what === "review") {
|
||||
const none = hooks.banner("No lessons are waiting any more.", "info");
|
||||
if (busy.what === "review" || busy.what === "tidy") {
|
||||
const none = hooks.banner(busy.what === "tidy" ? "Nothing to tidy up right now." : "No lessons are waiting any more.", "info");
|
||||
setTimeout(() => hooks.clearBanner(none), 4000);
|
||||
}
|
||||
redraw();
|
||||
@@ -1523,13 +1533,13 @@ export async function sendLearning(what) {
|
||||
// the agent answers.
|
||||
const sc = scan();
|
||||
const from = sc && sc.learning && sc.learning.state;
|
||||
if ((what === "switch-on" || what === "switch-off" || what === "review") && from) {
|
||||
if ((what === "switch-on" || what === "switch-off" || what === "review" || what === "tidy") && from) {
|
||||
const busy = { what, from, at: Date.now(), seen: false };
|
||||
page.learningBusy = busy;
|
||||
redraw();
|
||||
// One redraw at the limit, so an action the agent never answers stops spinning.
|
||||
setTimeout(redraw, LEARNING_BUSY_MS + 500);
|
||||
if (what === "review") watchLearningBusy(busy);
|
||||
if (what === "review" || what === "tidy") watchLearningBusy(busy);
|
||||
}
|
||||
try {
|
||||
const res = await fetch("/submit", {
|
||||
|
||||
@@ -155,6 +155,7 @@ function moreMenu() {
|
||||
};
|
||||
list.append(
|
||||
item("Switch off for this project", () => hooks.sendLearning("switch-off")),
|
||||
item("Tidy up lessons", () => hooks.sendLearning("tidy")),
|
||||
item("Move the failure log into lessons", () => hooks.sendLearning("move-log")),
|
||||
item("Remove all lessons…", () => openRemoveConfirm(), " is-danger")
|
||||
);
|
||||
@@ -504,6 +505,49 @@ function openRemoveConfirm() {
|
||||
dlg.showModal();
|
||||
}
|
||||
|
||||
// The same slug lessons.mjs gives a lesson's heading (slugOf), so a lesson's id
|
||||
// is `<file name without .md>/<slug>` here as there.
|
||||
function slugOf(text) {
|
||||
return String(text || "")
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "")
|
||||
.slice(0, 60)
|
||||
.replace(/-+$/, "");
|
||||
}
|
||||
|
||||
/** "Followed 12 times, last on Nov 20", "Followed once, last on Nov 20" or "Not followed yet". */
|
||||
function followLine(entry) {
|
||||
if (!entry || !(entry.count > 0)) return "Not followed yet";
|
||||
const last = shortDate(entry.last);
|
||||
const times = entry.count === 1 ? "once" : `${entry.count} times`;
|
||||
return `Followed ${times}${last ? ", last on " + last : ""}`;
|
||||
}
|
||||
|
||||
// One file's text through the page's Markdown, a quiet follow line under each
|
||||
// lesson's heading (a "### " line).
|
||||
function appendLessonText(part, file, follows) {
|
||||
const area = String(file.name || "").replace(/\.md$/i, "");
|
||||
const chunks = String(file.text || "").split(/\r?\n(?=### )/);
|
||||
const add = (text) => {
|
||||
if (!text.trim()) return;
|
||||
const div = el("div", "md");
|
||||
mdInto(div, text);
|
||||
part.appendChild(div);
|
||||
};
|
||||
for (const chunk of chunks) {
|
||||
const m = /^### (.+?)\s*(?:\r?\n|$)/.exec(chunk);
|
||||
if (!m) {
|
||||
add(chunk);
|
||||
continue;
|
||||
}
|
||||
add(m[0]);
|
||||
const line = el("p", "learn-follow", followLine(follows[`${area}/${slugOf(m[1])}`]));
|
||||
part.appendChild(line);
|
||||
add(chunk.slice(m[0].length));
|
||||
}
|
||||
}
|
||||
|
||||
// Open the lessons: every lesson file, read-only, through the page's Markdown.
|
||||
async function openLessons() {
|
||||
let dlg = document.getElementById("learn-lessons-modal");
|
||||
@@ -525,7 +569,7 @@ async function openLessons() {
|
||||
try {
|
||||
const res = await fetch("/learning/lessons", { cache: "no-store" });
|
||||
if (res.status !== 200) throw new Error(String(res.status));
|
||||
const { files } = await res.json();
|
||||
const { files, follows } = await res.json();
|
||||
body.replaceChildren();
|
||||
if (!files || !files.length) {
|
||||
body.appendChild(el("p", "md-p", "No lessons are saved in this project yet."));
|
||||
@@ -534,9 +578,7 @@ async function openLessons() {
|
||||
for (const f of files) {
|
||||
const part = el("section", "learn-lessons-file");
|
||||
part.appendChild(el("p", "learn-lessons-name", f.name));
|
||||
const text = el("div", "md");
|
||||
mdInto(text, f.text || "");
|
||||
part.appendChild(text);
|
||||
appendLessonText(part, f, follows || {});
|
||||
body.appendChild(part);
|
||||
}
|
||||
} catch {
|
||||
|
||||
@@ -15,6 +15,16 @@ export const WORKING_GRACE_MS = 5 * 60 * 1000;
|
||||
// How long a Learning action may show as working before the page gives up
|
||||
// waiting for the agent (it normally answers in a second or two).
|
||||
export const LEARNING_BUSY_MS = 30000;
|
||||
// Review and Tidy up first grade every waiting lesson (check-input, a checker,
|
||||
// check-record), which often takes longer than LEARNING_BUSY_MS: while the
|
||||
// agent is still working on one, the page waits up to this long instead.
|
||||
export const LEARNING_CHECK_MS = 5 * 60 * 1000;
|
||||
|
||||
/** How long a Learning action may stay busy: LEARNING_CHECK_MS for a Review or Tidy up the agent is still working on, else LEARNING_BUSY_MS. */
|
||||
export function learningBusyLimit(busy) {
|
||||
const checking = (busy.what === "review" || busy.what === "tidy") && (page.pendingResult || agentWorking());
|
||||
return checking ? LEARNING_CHECK_MS : LEARNING_BUSY_MS;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Learning action the person just pressed while the agent works on it, or
|
||||
@@ -31,9 +41,9 @@ export function learningBusyNow(state) {
|
||||
page.learningBusy = null;
|
||||
return null;
|
||||
};
|
||||
if (Date.now() - busy.at > LEARNING_BUSY_MS) return end();
|
||||
if (Date.now() - busy.at > learningBusyLimit(busy)) return end();
|
||||
if ((busy.what === "switch-on" || busy.what === "switch-off") && busy.from !== state) return end();
|
||||
if (busy.what === "review" && ((page.S && page.S.items) || []).some((i) => i && i.kind === "lessons" && isOpen(i))) return end();
|
||||
if ((busy.what === "review" || busy.what === "tidy") && ((page.S && page.S.items) || []).some((i) => i && i.kind === "lessons" && isOpen(i))) return end();
|
||||
return busy;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +112,8 @@
|
||||
/* Lessons waiting: the banner nearest the title, in the accent tint. */
|
||||
.dash-nudge.learn-banner { border-left-width: 4px; }
|
||||
.learn-banner .btn { margin-left: auto; }
|
||||
/* Two lines in one banner (lessons waiting, lessons near their limit): each its own row. */
|
||||
.learn-banner-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; flex: 1 1 100%; }
|
||||
|
||||
/* Open the lessons: each file under its own name. */
|
||||
.learn-lessons-file + .learn-lessons-file { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--rule); }
|
||||
@@ -120,6 +122,8 @@
|
||||
A lesson's title is a long heading: balanced wrapping (tokens.css) halves it, so fill each line. */
|
||||
.learn-lessons-file .md { max-width: none; }
|
||||
.learn-lessons-file .md-h { text-wrap: wrap; }
|
||||
/* One quiet line under a lesson's heading: how often it was followed. */
|
||||
.learn-follow { margin: 2px 0 6px; font-size: var(--fs-sm); color: var(--ink-3); }
|
||||
|
||||
/* The lessons card (cards.js buildLessons): one block per item, none chosen at first. */
|
||||
.lessons-opening { margin: 14px 0 0; font-size: var(--fs-md); color: var(--ink-3); }
|
||||
@@ -138,6 +142,15 @@
|
||||
.lessons-found { font-size: var(--fs-md); color: var(--ink-2); }
|
||||
.lessons-origin,
|
||||
.lessons-note { font-size: var(--fs-sm); color: var(--ink-3); }
|
||||
.lessons-tag { font-size: var(--fs-sm); color: var(--ink-3); font-style: italic; }
|
||||
.lessons-checked { margin: 6px 0 0; font-size: var(--fs-sm); color: var(--ink-3); }
|
||||
.lesson-checks { margin: 0 0 6px; }
|
||||
.lesson-checks p { margin: 0 0 4px; font-size: var(--fs-md); }
|
||||
.lesson-check-word { font-weight: 700; margin-right: 2px; }
|
||||
.lesson-check.fail { color: var(--warn); }
|
||||
.lesson-check.doubt { color: var(--stage); }
|
||||
.lesson-checks .lesson-check-pass { color: var(--ink-3); font-size: var(--fs-sm); }
|
||||
.lesson-suggestion { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; color: var(--ink-2); }
|
||||
.lessons-fix blockquote {
|
||||
margin: 0 0 8px;
|
||||
padding: 6px 10px;
|
||||
|
||||
@@ -52,7 +52,7 @@ import { cleanSetting, offered } from "./public/subagents.js";
|
||||
import { DEFAULT_ACCENT, DEFAULT_CARD_WIDTH, accentId, cardWidth } from "./public/palette.js";
|
||||
import { SERVABLE, TYPES, asset } from "./static.mjs";
|
||||
import { handoffsDir, isHandoffId } from "./handoffs.mjs";
|
||||
import { learningScan, learningState, writePause } from "./learning.mjs";
|
||||
import { followCounts, learningScan, learningState, writePause } from "./learning.mjs";
|
||||
import { linkToOpen, openFile, openLink } from "./open-link.mjs";
|
||||
import {
|
||||
NotepadError,
|
||||
@@ -743,7 +743,9 @@ function readLessonFiles(worktree) {
|
||||
}
|
||||
|
||||
function learningLessons(req, res, ctx) {
|
||||
return json(res, 200, { files: readLessonFiles(ctx.worktree() || ctx.project) }, { "cache-control": "no-store" });
|
||||
const project = ctx.worktree() || ctx.project;
|
||||
// follows: how often each saved lesson was followed, read from this machine's store.
|
||||
return json(res, 200, { files: readLessonFiles(project), follows: followCounts(project) }, { "cache-control": "no-store" });
|
||||
}
|
||||
|
||||
// What an unknown git host is, for the git board's pull-request link. Saved
|
||||
|
||||
Reference in new issue
Block a user