lab-kit-cli 1.8.0__tar.gz → 1.10.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/.github/workflows/ci.yml +2 -1
  2. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/CHANGELOG.md +28 -0
  3. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/PKG-INFO +2 -1
  4. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/docs/model.md +40 -9
  5. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/method/METHOD.md +5 -1
  6. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/pyproject.toml +2 -2
  7. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/skills/lab-mission/SKILL.md +2 -0
  8. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/skills/lab-talk/SKILL.md +8 -3
  9. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/src/lab_kit/__init__.py +1 -1
  10. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/src/lab_kit/checks.py +15 -3
  11. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/src/lab_kit/cli.py +1 -1
  12. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/src/lab_kit/history.py +149 -21
  13. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/src/lab_kit/record.py +59 -2
  14. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/src/lab_kit/site.py +64 -1
  15. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/src/lab_kit/views.py +5 -0
  16. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/src/lab_kit/write.py +5 -1
  17. lab_kit_cli-1.10.0/tests/test_drafts.py +225 -0
  18. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/tests/test_held.py +2 -1
  19. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/tests/test_integrity.py +20 -1
  20. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/tests/test_order.py +9 -1
  21. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/tests/test_parked.py +7 -2
  22. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/tests/test_site.py +26 -0
  23. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/.github/workflows/policy.yml +0 -0
  24. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/.github/workflows/release.yml +0 -0
  25. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/.gitignore +0 -0
  26. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/AGENTS.md +0 -0
  27. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/CLAUDE.md +0 -0
  28. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/CONTRIBUTING.md +0 -0
  29. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/LICENSE +0 -0
  30. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/README.md +0 -0
  31. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/agents/reviewer.md +0 -0
  32. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/skills/lab-review/SKILL.md +0 -0
  33. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/skills/lab-set-up/SKILL.md +0 -0
  34. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/skills/lab-work/SKILL.md +0 -0
  35. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/src/lab_kit/runs.py +0 -0
  36. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/src/lab_kit/supervise.py +0 -0
  37. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/tests/test_flow.py +0 -0
  38. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/tests/test_mission.py +0 -0
  39. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/tests/test_needs.py +0 -0
  40. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/tests/test_refusals.py +0 -0
  41. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/tests/test_states.py +0 -0
  42. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/tests/test_vocabulary.py +0 -0
  43. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/tests/test_wording.py +0 -0
  44. {lab_kit_cli-1.8.0 → lab_kit_cli-1.10.0}/tools/import_run.py +0 -0
@@ -2,6 +2,7 @@ name: gate
2
2
 
3
3
  on:
4
4
  push:
5
+ branches: [main]
5
6
  pull_request:
6
7
 
7
8
  jobs:
@@ -21,7 +22,7 @@ jobs:
21
22
  python -m pip install --upgrade pip
22
23
  python -m pip install -e ".[dev,site]"
23
24
  - name: Tests
24
- run: python -m pytest -q -rs
25
+ run: python -m pytest -q -rs -n auto # the runner has four cores; the tests take half the time
25
26
  env:
26
27
  LAB_SITE_TESTS: required # the site's tests run and fail like any other; they never skip here
27
28
  # What a lab gets is the wheel: build it, install it alone, and set up a lab with it.
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.10.0
4
+
5
+ - **A settled decision is a draft until something acts on it.** A mission that carries it is launched, or a run or a
6
+ trial starts of a step its `order:` names, of a step under a goal or a question that came out of it, or of a step
7
+ that uses a resource whose amounts it set: from then it is locked, and a change of mind is a new decision. Until
8
+ then it may be revised, so a talk that refines yesterday's plan changes yesterday's decision instead of stacking a
9
+ new one on it. `lab check` holds a locked decision as it was committed when it was acted on, and lets a draft change, though a settled decision is never reopened.
10
+ `lab show` and the decision's page say which it is.
11
+ - **A draft decision may be folded into another draft** with `folds: [D<n>, ...]`: its file is removed, its number is
12
+ never used again, its log lines are read as about the decision that took it in, and an old link to it opens that
13
+ decision. A locked decision cannot be folded. A resource whose `from` named the draft names the decision that
14
+ took it in.
15
+ - `lab mission launch` writes a line in the lab's log about the decision it carries (`Mission launched:`), which
16
+ locks it. What locks a decision is read from what the record holds: the log, the lists of runs, and every `order:`
17
+ it was committed with. A goal's or a question's `from:` no longer changes once committed, and a resource's `from`
18
+ changes only with its amounts, save in both cases to the decision that folded the one it named.
19
+ - What git holds about a lab's decisions is read once per commit and kept in `~/.cache/lab-kit/held/`, outside the
20
+ lab. If it cannot be read, `lab check` fails and says why. A mission launched before 1.10.0 wrote no line in the
21
+ log: its own file is read instead, so pointing it at another decision moves its lock with it.
22
+ - The skills `lab-talk` and `lab-mission` and the method changed: run `lab init` in a lab after upgrading.
23
+
24
+ ## 1.9.0
25
+
26
+ - **A Missions page** on the site, compact like Decisions: the current first, then the next, then the closed.
27
+ Each mission shows its status mark, the decision it carries, what it is for, its steps as marks with how many
28
+ are closed, its last log line, and its rules and log folded. The rail lists the page with how many are current,
29
+ and Now's mission line links to it.
30
+
3
31
  ## 1.8.0
4
32
 
5
33
  - **A question with nothing left under it is the agent's next step.** `lab now` ("Yours next") and Now's "Next for
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: lab-kit-cli
3
- Version: 1.8.0
3
+ Version: 1.10.0
4
4
  Summary: A research lab's record, its method, and the command that keeps both.
5
5
  Project-URL: Homepage, https://github.com/pierg/lab-kit
6
6
  Project-URL: Issues, https://github.com/pierg/lab-kit/issues
@@ -12,6 +12,7 @@ Requires-Dist: pyyaml
12
12
  Requires-Dist: tomli; python_version < '3.11'
13
13
  Provides-Extra: dev
14
14
  Requires-Dist: pytest; extra == 'dev'
15
+ Requires-Dist: pytest-xdist; extra == 'dev'
15
16
  Provides-Extra: site
16
17
  Requires-Dist: folio-kb>=0.7.0; extra == 'site'
17
18
  Description-Content-Type: text/markdown
@@ -16,7 +16,7 @@ A lab is a tree, and the decisions that shaped it.
16
16
  | **Reading** | One look at what already exists: sealed runs, traces, the benchmark's own definitions. What it looks at; then what was seen and what that suggests. It sets no bar in advance, so it can suggest and never confirm. | open, waiting, running, done, dropped |
17
17
  | **Run** | One try at producing what an experiment demands: when, on which resource, what changed since the run before, how it ended, what it used. An experiment has one or more, until one finishes. | running, finished, failed |
18
18
  | **Result** | One number from a finished run: a plain label, how it reads, and the command that prints it again. | |
19
- | **Decision** | One thing discussed with you and settled: first what there is to discuss, then what was decided and why. | open, done |
19
+ | **Decision** | One thing discussed with you and settled: first what there is to discuss, then what was decided and why. A settled one is a draft until something acts on it, then locked. | open, done |
20
20
 
21
21
  **One set of states for everything.** A goal, a question, an experiment, a build and a reading use the same
22
22
  seven words, and each type uses only those it can be in:
@@ -314,9 +314,32 @@ work (a decision with a new `order:`), stop a run. Say it, and the agent records
314
314
  you as for the agent: a locked plan is changed by a new experiment that replaces it, and an outcome is
315
315
  worked out from the results, not decided.
316
316
 
317
- **A settled decision stays as it was settled.** Its `decided:`, its `about:`, its `parks:`, its `unparks:`, its `drops:`, its `order:` and its Decided text never
318
- change once committed; a change of mind is a new decision. `lab check` holds this against the lab's
319
- history. So a decision cannot be made, afterwards, to be about something it never discussed.
317
+ **A settled decision is a draft until something acts on it.** A decision is acted on when a mission that
318
+ carries it is launched, or when a run or a trial starts, after it was settled, of an experiment that its `order:`
319
+ names (by its own id, its question's or its goal's), that sits under a goal or a question that came out of it, or
320
+ that uses a resource whose amounts it set. Until then it may be revised, though never reopened: a talk that refines
321
+ yesterday's plan changes yesterday's decision, and does not stack a new one on top of it.
322
+
323
+ Drafts that say one thing between them may also be folded into one of them: it lists the others under `folds:`
324
+ (`folds: [D13, D14]`), takes in what they said, and their files are removed. What a folded draft had taken in moves
325
+ with it, so the decision that takes it in lists those too. A folded number is never used again, its log lines stay
326
+ and are read as lines about the decision that took it in, and an old link to it opens that decision. Whatever named
327
+ it (a mission's `carries:`, a resource's `from`, a goal's or a question's `from:`) is pointed at the decision that
328
+ took it in, in the same change. Only a decision the log says was settled is folded.
329
+
330
+ What locks a decision is read from what the record holds and does not take back: the lab's log, the lists of runs,
331
+ and every `order:` the decision was ever committed with, so emptying its order unlocks nothing. Where a goal or a
332
+ question came from is held too: its `from:` never changes once committed, save to the decision that folded the one
333
+ it named; and a resource's `from` changes only with its amounts, or to the decision that folded it.
334
+
335
+ Once something has acted on it, the decision is **locked**: its `decided:`, its `about:`, its `parks:`, its
336
+ `unparks:`, its `drops:`, its `order:`, its `folds:` and its Decided text stay as they were committed before the
337
+ first commit that records what acted on it (the mission's launch in the log, the run's line in `runs.tsv`), or, while
338
+ none does, as in the last commit. An edit committed together with the act is already too late: commit the decision
339
+ first. A change of mind is a new decision. `lab check` holds this against the lab's history, and refuses a
340
+ locked decision folded into another. So a decision cannot be made, afterwards, to be about something it never
341
+ discussed once anything was done on its word. `lab show` and the decision's page say whether it is a draft or locked,
342
+ and since when.
320
343
 
321
344
  The agent decides everything else and records each choice in the log. It drops an experiment or a
322
345
  build that will not be done, saying why. It answers a question itself with `lab answer`: a test yes, no or mixed, an estimate found. The command refuses the other kind's answers, and
@@ -335,7 +358,7 @@ repository and place the lab publishes to has:
335
358
  - for a metered resource, the decision that set those amounts (`from`). It is a settled decision
336
359
  that lists the resource under `about:`, so a resource that appears later needs a decision of its
337
360
  own. An amount, or its unit, changes only together with `from`, which then names the later
338
- decision that changed it. A resource is never removed: one that is no longer used says so
361
+ decision that changed it; a `from` that named a draft later folded into another is read as that one. A resource is never removed: one that is no longer used says so
339
362
  (`retired = "<why>"`) and takes no run. Use outside a run is a row added under `other_use`, and
340
363
  rows are only added. `lab check` holds all of this against the lab's history, and `lab run`
341
364
  refuses a metered resource whose amounts, or the decisions behind them, are not as git holds
@@ -392,7 +415,8 @@ missions before it takes a machine.
392
415
 
393
416
  - `lab mission new "<title>" --carries <decision>` saves a mission, as next.
394
417
  - `lab mission launch [<mission>]` makes one current: the one named, or with no id the one saved last. It refuses
395
- while the decision it carries is open, and while the mission does not say what it is for.
418
+ while the decision it carries is open, and while the mission does not say what it is for. It writes one line in the
419
+ lab's log about that decision (`Mission launched:`), which locks it.
396
420
  - `lab mission log [<mission>] "<what happened>"` adds a line to a current mission's log. Lines are only added.
397
421
  - `lab mission close [<mission>] [--stopped] "<what it did, or why it stopped>"` ends a current mission: its status
398
422
  becomes done (stopped, with `--stopped`, when it ended before its work did), its log ends with that line, and one
@@ -481,7 +505,13 @@ A folder is named after its card's title, so a short title gives a short path.
481
505
  ## 7. The site
482
506
 
483
507
  Now (the dashboard), a page per goal, question, experiment, build, reading and decision, Decisions,
484
- Log, Resources, Glossary. Every page has the copy-path control.
508
+ Missions (when the lab has any), Log, Resources, Glossary. Every page has the copy-path control.
509
+
510
+ **Missions** lists every mission compactly, as Decisions lists decisions: the current first, then the next,
511
+ then the closed, the latest first. Each shows its status as a mark, the decision it carries, what it is for,
512
+ the steps its decision orders as one mark each with how many are closed, its last log line, and its rules
513
+ and whole log folded. The rail names the page, with how many missions are current; Now's mission line
514
+ links to it.
485
515
 
486
516
  **The rail** on the left of every page is the lab as a tree: each goal, its questions under it, and
487
517
  each question's steps under that. A row shows a mark for its type (G, Q, E, B, R), its short id, its
@@ -818,8 +848,9 @@ in UTC. The file holds no other heading, and a line no other `|`. The kinds are
818
848
  `decision` lines, each with the opening of what was decided. A `doing` line holds what the agent is
819
849
  starting on and why now. A line written before the kit kept the time has none.
820
850
  A line is about a goal, a question or a step, and a `decision` line about its decision. The one other line
821
- about a decision is the `agent` line `lab mission close` writes when a mission that carried it ends (`Mission done:`
822
- or `Mission stopped:`, and `Mission closed:` as 1.4.0 wrote it).
851
+ about a decision is an `agent` line about a mission that carried it: `lab mission launch` writes `Mission launched:`
852
+ when it starts, and `lab mission close` writes `Mission done:` or `Mission stopped:` when it ends (`Mission closed:`
853
+ as 1.4.0 wrote it). A line about a decision folded into another is read as about that one.
823
854
  `lab log` ends a line with no space, even when the so what is empty. Spaces at the end of a log line
824
855
  are not part of it: `lab check` compares the committed lines of `log.md` with those spaces left out,
825
856
  so removing or adding them changes no committed line.
@@ -39,7 +39,11 @@ judgement. The lab's own `AGENTS.md` adds only what is local.
39
39
  `lab new`, `lab lock` and `lab run`; otherwise judged.*
40
40
  6. **Record what was decided and why, in the lab's words.** A decision is written out of a conversation
41
41
  with the operator, and you show them the text as recorded. Their messages are not copied into the
42
- lab. Never record a decision that was not discussed with them. *Held by `lab decide`; that the
42
+ lab. Never record a decision that was not discussed with them. A settled decision that nothing has acted on yet (no
43
+ mission launched on it, no run of a step it orders, of a step under what came out of it, or on a resource whose
44
+ amounts it set) is a draft: when the talk refines it, revise it rather than
45
+ stacking a new decision on top. Once acted on, it is locked, and a change of mind is a new decision. *Held by
46
+ `lab decide` and `lab check`; that the
43
47
  record is faithful is judged.*
44
48
  7. **Say what you are on.** The operator reads the site to know whether anything is happening, and
45
49
  should never have to ask you. When you start on a card or move to another, log it:
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
5
5
  [project]
6
6
  dynamic = ["readme"]
7
7
  name = "lab-kit-cli"
8
- version = "1.8.0"
8
+ version = "1.10.0"
9
9
  description = "A research lab's record, its method, and the command that keeps both."
10
10
  license = "MIT"
11
11
  authors = [{ name = "Piergiuseppe Mallozzi" }]
@@ -13,7 +13,7 @@ requires-python = ">=3.10"
13
13
  dependencies = ["pyyaml", "tomli; python_version < '3.11'"]
14
14
 
15
15
  [project.optional-dependencies]
16
- dev = ["pytest"]
16
+ dev = ["pytest", "pytest-xdist"]
17
17
  # folio serves the operator's site and lab_kit.site draws its pages, through the views hook of folio-kb 0.7.0.
18
18
  # The `lab` command itself needs no folio.
19
19
  site = ["folio-kb>=0.7.0"]
@@ -58,6 +58,8 @@ operator wants its parts run separately, such as one wave each.
58
58
 
59
59
  1. `lab mission launch` launches the mission saved last; `lab mission launch <id>` a given one.
60
60
  The command refuses while the decision is open or the mission does not say what it is for.
61
+ Launching acts on the decision: from then it is locked, and the lab's log says so. Revise the
62
+ decision before you launch, and commit it before the launch is committed.
61
63
  2. `lab mission <id>`. Read its rules, then the rules of every other current mission it lists:
62
64
  they share the lab's resources, so never take a machine or a slot another current mission
63
65
  holds. When two missions' rules would collide, bring that to the operator before you start.
@@ -50,13 +50,18 @@ from the record, shortest first. A decision is a discussion, not a request for a
50
50
  is an option. If the discussion changes the options, rewrite the card's Options before deciding.
51
51
  4. When it is settled, write what was decided and why, in the lab's words, in two to four sentences:
52
52
  `lab decide <decision> --with <their name> "<what was decided and why>"`.
53
- 5. Show them the sentence you recorded. If they correct it, the correction is a new decision.
53
+ 5. Show them the sentence you recorded. If they correct it, and `lab show <decision>` says it is still a draft
54
+ (no mission launched on it, no run of a step it orders, of a step under what came out of it, or on a resource
55
+ whose amounts it set), revise that decision: its card, its Decided text, its
56
+ lists. Only a locked decision needs a new one. When drafts in a row say one thing between them, fold them into
57
+ one: it lists the others under `folds:` and takes in what they said; remove their files, and point whatever named
58
+ them (a mission's `carries:`, a resource's `from`, a card's `from:`) at it.
54
59
  6. Make what follows: `lab new goal|question ... --from <decision>`, a change to `resources.toml`,
55
60
  an override on an experiment. Then go on with the lab-work skill.
56
61
 
57
62
  A decision that will change an amount, add a resource or allow one experiment a higher cap lists
58
63
  that resource or that experiment under `about:` before it is decided: `lab new decision "<title>"
59
- --about <resource or id>`. What a settled decision is about cannot be changed afterwards, and a
64
+ --about <resource or id>`. What a locked decision is about cannot be changed afterwards, and a
60
65
  resource's new amount names the decision in `from`.
61
66
 
62
67
  ## When they decide something nobody raised
@@ -72,7 +77,7 @@ the Decided text why and what would bring it back. To bring one back, a new deci
72
77
  When they agree an order of work ("this first, then these side by side"), record it on the decision as
73
78
  `order: [<ids>]`, first to last: goals, questions or steps, each once. A question or a goal stands for every
74
79
  step under it; a step named on its own takes its own place. Steps not named follow, in the tree's order. Say
75
- the order in the Decided text too. To change it, a new decision with a new `order:`; never edit a settled one,
80
+ the order in the Decided text too. To change it, revise the decision while it is a draft, else a new decision with a new `order:`; never edit a locked one,
76
81
  and never write the order anywhere else (not in `AGENTS.md`, not on a step).
77
82
 
78
83
  ## Rules
@@ -1,2 +1,2 @@
1
1
  """lab-kit: a research lab's record, its method, and the command that keeps both."""
2
- __version__ = "1.8.0"
2
+ __version__ = "1.10.0"
@@ -11,7 +11,7 @@ KEYS = { # what a card's front matter may hold; a state is never among them
11
11
  "experiment": {"title", "needs", "uses", "override", "replaces", "because", "cost", "waiting_on", "dropped", "see"},
12
12
  "build": {"title", "needs", "commits", "tests", "waiting_on", "dropped", "see"},
13
13
  "reading": {"title", "needs", "waiting_on", "dropped", "see"},
14
- "decision": {"title", "about", "date", "holds", "parks", "unparks", "drops", "order", "decided", "see"},
14
+ "decision": {"title", "about", "date", "holds", "parks", "unparks", "drops", "order", "folds", "decided", "see"},
15
15
  }
16
16
 
17
17
 
@@ -29,6 +29,8 @@ def run(lab, rederive=True):
29
29
  if not here:
30
30
  notes.append("the store is not here: runs and re-derivation were not checked")
31
31
  unchecked = True
32
+ if lab.held.get("error"): # what locks a decision is read from git; without it a lock could be edited away unseen
33
+ bad("history", "git", f"what locks a decision could not be read from the lab's history: {lab.held['error']}")
32
34
 
33
35
  absent = {} # the libraries the charter names whose folder is not on this machine
34
36
 
@@ -160,6 +162,16 @@ def run(lab, rederive=True):
160
162
  bad("links", d["path"], f"order names {i!r}, which is not a goal, a question or a step of the lab")
161
163
  for i in sorted({i for i in d["order"] if d["order"].count(i) > 1}):
162
164
  bad("links", d["path"], f"order names {i} more than once: each has one place")
165
+ for i in d["folds"]: # the drafts it took in: decisions of the lab once, folded into this one only
166
+ i = str(i)
167
+ if not re.fullmatch(r"D[1-9]\d*", i):
168
+ bad("links", d["path"], f"folds names {i!r}, which is not a decision's id")
169
+ elif i in nodes:
170
+ bad("links", d["path"], f"folds {i}, which is still here: a decision folded into another has its file removed")
171
+ elif not any(l["about"] == i and l["kind"] == "decision" and l["what"].startswith("Decided:") for l in lab.lines):
172
+ bad("links", d["path"], f"folds {i}, which the log never says was decided: only a settled decision of this lab is folded")
173
+ elif sum(str(f) == i for e in lab.decisions for f in e["folds"]) > 1:
174
+ bad("links", d["path"], f"folds {i}, which another decision, or this one twice, also folds")
163
175
  done = d["decided"]
164
176
  if done and not ({"date", "with"} <= set(done) and R.flat(d["slots"].get("Decided", ""))):
165
177
  bad("cards", d["path"], "a settled decision holds when, with whom, and what was decided and why under Decided")
@@ -321,10 +333,10 @@ def run(lab, rederive=True):
321
333
  where = f"log.md line {l['line']}"
322
334
  if l["kind"] not in R.KINDS:
323
335
  bad("log", where, f"kind {l['kind']!r}; one of {', '.join(R.KINDS)}")
324
- kind = nodes.get(l["about"], {}).get("type")
336
+ kind = nodes.get(lab.folded.get(l["about"], l["about"]), {}).get("type") # a line about a folded decision is about the one that took it in
325
337
  if l["kind"] == "doing" and not l["so"]:
326
338
  bad("log", where, "a `doing` line says why now, after what the agent is starting on")
327
- closes = l["kind"] == "agent" and kind == "decision" and l["what"].startswith(("Mission closed: ", "Mission done: ", "Mission stopped: ")) # written by `lab mission close`
339
+ closes = l["kind"] == "agent" and kind == "decision" and l["what"].startswith(("Mission launched: ", "Mission closed: ", "Mission done: ", "Mission stopped: ")) # written by `lab mission launch` and `close`
328
340
  if kind is None or ((kind == "decision") != (l["kind"] == "decision") and not closes):
329
341
  bad("log", where, f"is about {l['about']!r}: a decision line is about its decision, as is the line that closes a mission, any other about a goal, a question, an experiment, a build or a reading")
330
342
 
@@ -113,7 +113,7 @@ def main(argv=None):
113
113
  print(f"saved {made}: {path}. Say what it is for under the front matter, and its rules")
114
114
  elif rest[0] == "launch" and len(rest) <= 2:
115
115
  made, path = write.mission_launch(lab, ident())
116
- print(f"launched {made}: {path}")
116
+ print(f"launched {made}: {path}, and log.md")
117
117
  elif rest[0] in ("log", "close") and len(rest) == 2 and re.fullmatch(r"M\d+", rest[1]):
118
118
  raise SystemExit(f'say what happened after the mission: lab mission {rest[0]} {rest[1]} "<what>"')
119
119
  elif rest[0] == "log" and len(rest) in (2, 3):
@@ -15,14 +15,19 @@ same place: what was committed under the old name is held under the new one.
15
15
  - A `results.tsv` that a review has passed keeps every committed row. Once a results review that passed is committed
16
16
  together with the rows it read, those rows stay, whatever the card and the file say later. Rows committed while
17
17
  the last passed review was of other rows, such as a draft row added after it, were never reviewed and are not held.
18
- - A settled decision keeps its `decided:`, its `about:`, its `parks:`, its `unparks:`, its `order:` and its Decided text as first committed.
18
+ - A settled decision is a draft until something acts on it: a mission that carries it is launched, or a run starts of a
19
+ step its `order:` names, of a step under what came out of it, or of a step on a resource whose amounts it set. From
20
+ then it is locked, and keeps its `decided:`, `about:`, `parks:`, `unparks:`, `drops:`,
21
+ `order:`, `folds:` and Decided text as committed before the first commit that records the act (the last commit,
22
+ while none does). What locks it is read from what git holds (`held_scope`), so no later edit takes it back. A draft may be revised, never
23
+ reopened, or folded into another decision with `folds:`; then its file goes, and its number is never used again.
19
24
  - A resource, once committed, is never removed. A metered resource's `granted`, `per_run` and `unit` change only together
20
25
  with `from`, which then names another settled decision that lists the resource. Its `other_use` rows only grow.
21
- - None of these files is deleted, and none changes its number.
26
+ - None of these files is deleted, save a draft decision folded into another, and none changes its number.
22
27
  """
23
28
  from __future__ import annotations
24
29
 
25
- import glob, os, re, subprocess
30
+ import glob, json, os, re, subprocess
26
31
 
27
32
  from . import record as R
28
33
 
@@ -115,17 +120,77 @@ def resources(lab):
115
120
  bad(f"{name} was removed {when}: a resource is never removed. One that is no longer used gets `retired = \"<why>\"`")
116
121
  continue
117
122
  if any(k in a for k in ("granted", "per_run")) and tuple(a.get(k) for k in ("granted", "per_run", "unit")) != tuple(b.get(k) for k in ("granted", "per_run", "unit")):
118
- d = lab.nodes.get(str(b.get("from")))
123
+ d = lab.nodes.get(lab.folded.get(str(b.get("from")), str(b.get("from")))) # a draft folded into another is read as that one
119
124
  if b.get("from") == a.get("from") or not d or d["type"] != "decision" or d["state"] != "done" or name not in d["about"]:
120
125
  bad(f"{name}: `granted`, `per_run` or `unit` changed {when}, and `from` does not name another settled decision: an amount changes out of a decision")
126
+ elif "from" in a and str(a.get("from")) != str(b.get("from")) and lab.folded.get(str(a.get("from"))) != str(b.get("from")):
127
+ bad(f"{name}: `from` changed {when} from {a.get('from')} to {b.get('from')} with its amounts unchanged: it names the decision that set them, and changes only with them, or to the decision that folded it")
121
128
  lost = subsequence(rows(a), rows(b))
122
129
  if lost is not None:
123
130
  bad(f"{name}: an `other_use` row was removed or changed {when}: {lost[0]}, {lost[1]}, {lost[2][:40]!r}. Rows are only added")
124
131
  return sorted(set(problems))
125
132
 
126
133
 
134
+ def card(text):
135
+ """A card's front matter and slots as a version in git has them, or (None, {})."""
136
+ try:
137
+ fm, slots, _ = R.parse(text)
138
+ except Exception:
139
+ return None, {}
140
+ return (fm, slots) if isinstance(fm, dict) else (None, {})
141
+
142
+
143
+ def ids(v):
144
+ return [str(i) for i in (v if isinstance(v, list) else [v] if v is not None else [])]
145
+
146
+
147
+ def held_scope(lab):
148
+ """What git holds about where things came from, which no later edit takes back: each goal's and question's `from:`
149
+ as first committed, each resource's every `from`, and each decision's every committed `order:`. Read once per lab;
150
+ empty outside git."""
151
+ root, out = lab.root, {"from": {}, "granted": {}, "orders": {}}
152
+ if not committed(root):
153
+ return out
154
+ # It depends only on the commits, so it is kept per commit, outside the lab: reading it costs a git call per card.
155
+ head = (git(root, "rev-parse", "HEAD") or "").strip()
156
+ top = (git(root, "rev-parse", "--show-prefix") or "").strip()
157
+ cache = os.path.join(os.environ.get("XDG_CACHE_HOME") or os.path.expanduser("~/.cache"), "lab-kit", "held",
158
+ R.text_hash(os.path.realpath(root) + "|" + top + "|" + head + "|" + str(sorted(n["path"] for n in lab.goals + lab.questions)))[:32] + ".json")
159
+ try:
160
+ kept = json.load(open(cache))
161
+ return {"from": kept["from"], "granted": {k: set(v) for k, v in kept["granted"].items()}, "orders": {k: set(v) for k, v in kept["orders"].items()}}
162
+ except (OSError, ValueError, KeyError, TypeError, AttributeError):
163
+ pass
164
+ for n in lab.goals + lab.questions:
165
+ names = (git(root, "log", "--reverse", "--follow", "--name-only", "--format=%H", "--", n["path"]) or "").split() # each commit, then the name it had there
166
+ if len(names) >= 2:
167
+ fm, _ = card(git(root, "show", f"{names[0]}:{names[1]}") or "") # a name git prints is from the repository's top
168
+ if fm and fm.get("from") is not None:
169
+ out["from"][n["id"]] = str(fm.get("from"))
170
+ for c in (git(root, "log", "--format=%H", "--relative", "--", "resources.toml") or "").split():
171
+ for name, r in (tables(git(root, "show", f"{c}:./resources.toml")) or {}).items():
172
+ if isinstance(r, dict) and r.get("from") is not None:
173
+ out["granted"].setdefault(name, set()).add(str(r.get("from")))
174
+ for where, commits in held(root, "decisions").items():
175
+ m = DECISION.fullmatch(commits[-1][1])
176
+ if m:
177
+ for c, path in commits:
178
+ fm, _ = card(git(root, "show", f"{c}:./{path}") or "")
179
+ if fm and fm.get("decided") is not None:
180
+ out["orders"].setdefault(f"D{int(m.group(1))}", set()).update(ids(fm.get("order")))
181
+ try:
182
+ os.makedirs(os.path.dirname(cache), exist_ok=True)
183
+ with open(cache + ".tmp", "w") as f:
184
+ json.dump({"from": out["from"], "granted": {k: sorted(v) for k, v in out["granted"].items()}, "orders": {k: sorted(v) for k, v in out["orders"].items()}}, f)
185
+ os.replace(cache + ".tmp", cache)
186
+ except OSError:
187
+ pass # no place to keep it: it is read again next time
188
+ return out
189
+
190
+
127
191
  def decisions(lab, versions=None, now=None):
128
- """The settled decisions that are no longer as they were first committed settled."""
192
+ """The locked decisions that are no longer as they were when something first acted on them, and the decisions that
193
+ are gone without another decision folding them in while they were still drafts."""
129
194
  root, problems = lab.root, []
130
195
  if not committed(root):
131
196
  return problems
@@ -135,29 +200,92 @@ def decisions(lab, versions=None, now=None):
135
200
 
136
201
  def settled(text):
137
202
  """What a decision's card says was decided, and about what, or None while it says nothing."""
138
- try:
139
- fm, slots, _ = R.parse(text)
140
- except Exception:
203
+ fm, slots = card(text)
204
+ if not fm or fm.get("decided") is None:
141
205
  return None
142
- if not isinstance(fm, dict) or fm.get("decided") is None:
143
- return None
144
- ids = lambda v: sorted(str(i) for i in (v if isinstance(v, list) else [v] if v is not None else []))
145
- order = [str(i) for i in (fm.get("order") if isinstance(fm.get("order"), list) else [fm.get("order")] if fm.get("order") is not None else [])] # its order is kept as written: first to last
146
- return str(fm.get("decided")), ids(fm.get("about")), ids(fm.get("parks")), ids(fm.get("unparks")), ids(fm.get("drops")), order, R.flat(slots.get("Decided", ""))
206
+ s = lambda key: sorted(ids(fm.get(key)))
207
+ return (str(fm.get("decided")), s("about"), s("parks"), s("unparks"), s("drops"), ids(fm.get("order")), s("folds"), # its order is kept as written
208
+ R.flat(slots.get("Decided", "")))
209
+
210
+ def last(path):
211
+ """The last commit that still had a file: HEAD while only the work tree lacks it, else the one before its removal."""
212
+ if git(root, "cat-file", "-e", f"HEAD:./{path}") is not None:
213
+ return "HEAD"
214
+ gone = (git(root, "log", "-1", "--diff-filter=D", "--format=%H", "--", path) or "").strip()
215
+ return f"{gone}^" if gone else "HEAD"
216
+
217
+ def launched(c, ident):
218
+ """When a mission that carried a decision was launched, as the last commit that held the decision has the
219
+ missions: once it is folded, whatever carried it carries the decision that took it in."""
220
+ names = (git(root, "ls-tree", "--name-only", f"{c}:./missions") or "").split()
221
+ for name in names:
222
+ fm, slots = card(git(root, "show", f"{c}:./missions/{name}") or "")
223
+ if fm and str(fm.get("carries") or "").strip() == ident:
224
+ for raw in str(slots.get("Log", "")).split("\n"):
225
+ hit = R.MISSION_LINE.match(raw.rstrip())
226
+ if hit and hit.group(3).strip() == "launched":
227
+ return f"{hit.group(1)}T{hit.group(2)}:59+00:00"
228
+ if str(fm.get("status") or "") in ("current", "done", "stopped"):
229
+ return "its mission's launch"
230
+ return None
231
+
232
+ def first(acts):
233
+ """The earliest commit, in history's order, that records any of what acted, or None while none does yet."""
234
+ found = []
235
+ for _, path, text in acts:
236
+ where_ = path if path.startswith("missions/") else path.split("/")[0] # `log.md`, a mission, or `goals` as a whole: a renamed folder is the same place
237
+ c = (git(root, "log", "--reverse", "--find-renames", "--format=%H", "-S", text, "--", where_) or "").split()
238
+ if c:
239
+ found.append((int((git(root, "rev-list", "--count", c[0]) or "0").strip() or 0), c[0]))
240
+ return min(found)[1] if found else None
147
241
 
148
242
  for where, commits in sorted(versions.items()):
149
243
  if not DECISION.fullmatch(commits[-1][1]):
150
244
  continue
245
+ ident = f"D{int(DECISION.fullmatch(commits[-1][1]).group(1))}"
246
+ held_as = [(c, path, settled(git(root, "show", f"{c}:./{path}") or "")) for c, path in commits] # oldest first
247
+ held_as = [h for h in held_as if h[2]]
248
+ orders = {i for _, _, h in held_as for i in h[5]} # every order it was ever committed with: emptying it unlocks nothing
151
249
  if where not in now:
152
- bad(commits[-1][1], "was committed and is gone; nothing recorded is removed")
250
+ into = lab.nodes.get(lab.folded.get(ident, ""))
251
+ c = last(commits[-1][1])
252
+ fm, _ = card(git(root, "show", f"{c}:./{commits[-1][1]}") or "")
253
+ acted = None
254
+ if fm and fm.get("decided") is not None:
255
+ acts = lab.acts(ident, orders | set(ids(fm.get("order"))), lab.settled_at(ident, fm.get("decided")))
256
+ acted = acts[0][0] if acts else launched(c, ident)
257
+ if not into:
258
+ bad(commits[-1][1], "was committed and is gone; nothing recorded is removed. A draft decision is folded into another with `folds:`")
259
+ elif acted:
260
+ bad(commits[-1][1], f"is folded into {into['id']}, and something acted on it at {acted}: a locked decision stays")
153
261
  continue
154
- for c, path in commits: # oldest first, under whichever name it had then
155
- was = settled(git(root, "show", f"{c}:./{path}") or "")
156
- if was:
157
- mine = path if path in now[where] else now[where][0]
158
- if settled(R.read(os.path.join(root, mine))) != was:
159
- bad(mine, f"was settled in {c[:8]}" + ("" if mine == path else f", as {path}") + ", and what it parks, drops or brings back, the order it sets, its `decided:`, its `about:` or its Decided text has changed since; a change of mind is a new decision")
160
- break
262
+ mine = lambda path: path if path in now[where] else now[where][0]
263
+ if not held_as:
264
+ continue # never committed settled: what is committed now is held from then
265
+ if settled(R.read(os.path.join(root, mine(held_as[0][1])))) is None:
266
+ bad(mine(held_as[0][1]), f"was settled in {held_as[0][0][:8]} and no longer says what was decided: a settled decision is never reopened, even while it is a draft")
267
+ continue
268
+ d = lab.nodes.get(ident)
269
+ if not d or d.get("type") != "decision":
270
+ continue
271
+ acts = lab.acts(ident, orders | set(d["order"]), d["settled_at"])
272
+ if not acts:
273
+ continue # settled and still a draft: it may be revised until something acts on it
274
+ # Held as the decision was committed before the first commit that records what acted on it; while no commit
275
+ # records it yet, as the last commit has it. An edit committed with the act, or after it, is a change of mind.
276
+ at = first(acts)
277
+ before = (lambda c: git(root, "merge-base", "--is-ancestor", c, f"{at}^") is not None) if at else (lambda c: True)
278
+ c, path, was = next(((c, p, w) for c, p, w in reversed(held_as) if before(c)), held_as[0])
279
+ if settled(R.read(os.path.join(root, mine(path)))) != was:
280
+ bad(mine(path), f"was locked when {acts[0][0][:16].replace('T', ' ')} acted on it, as committed in {c[:8]}" + ("" if mine(path) == path else f" as {path}")
281
+ + ", and what it parks, drops, folds or brings back, the order it sets, its `decided:`, its `about:` or its Decided text has changed since; a change of mind is a new decision")
282
+
283
+ # Where a goal or a question came from is held: once committed, its `from:` changes only to the decision that
284
+ # folded the one it named. Else a decision could be unlocked by pointing what came out of it elsewhere.
285
+ for n in lab.goals + lab.questions:
286
+ was_, is_ = lab.held["from"].get(n["id"]), str(n.get("from"))
287
+ if was_ is not None and was_ != is_ and lab.folded.get(was_) != is_:
288
+ bad(n["path"], f"`from:` was {was_} when first committed and is {is_} now: where a {n['type']} came from does not change, save to the decision that folded the one it named")
161
289
  return problems
162
290
 
163
291
 
@@ -55,7 +55,7 @@ COLUMNS = {"results.tsv": ("name", "label", "value", "reads", "versus", "command
55
55
  HASH = 2 # how a folder is hashed in the locks and runs made now; one without the marker was made with the first way
56
56
  NUMBER = re.compile(r"[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?")
57
57
  LISTS = {"goal": ("see",), "question": ("needs", "see"), "experiment": ("needs", "uses", "see"), "build": ("needs", "commits", "tests", "see"),
58
- "reading": ("needs", "see"), "decision": ("about", "holds", "parks", "unparks", "drops", "order", "see")} # the front matter keys that hold a list
58
+ "reading": ("needs", "see"), "decision": ("about", "holds", "parks", "unparks", "drops", "order", "folds", "see")} # the front matter keys that hold a list
59
59
  TEXTS = ("title", "asks", "kind", "from", "replaces", "because", "cost", "waiting_on", "dropped", "answered") # and those that hold one value
60
60
 
61
61
 
@@ -355,6 +355,18 @@ class Lab:
355
355
  mine = sorted((r for r in self.runs if r.get("experiment") == x["id"]), key=lambda r: (str(r.get("started")), r["id"])) # in the order they started
356
356
  x["trials"], x["runs"] = [r for r in mine if r["kind"] == "trial"], [r for r in mine if r["kind"] != "trial"]
357
357
  x["finished"] = next((r for r in x["runs"] if r["state"] == "finished"), None) # the only source of its results
358
+ self.folded = {str(f): d["id"] for d in self.decisions for f in d["folds"]} # a draft folded into another decision, by its old id
359
+ self.held = {"from": {}, "granted": {}, "orders": {}} # what git holds about where things came from: see history.held_scope
360
+ try:
361
+ from . import history
362
+ self.held = history.held_scope(self)
363
+ except Exception as err: # a lab outside git, or a git that cannot be read: today's files say it all
364
+ self.held["error"] = str(err)
365
+ for d in self.decisions: # a settled decision is a draft until something acts on it; from then on it is locked
366
+ d["settled_at"] = self.settled_at(d["id"], d["decided"]) if d["state"] == "done" else None
367
+ d["acts"] = self.acts(d["id"], d["order"], d["settled_at"]) if d["settled_at"] else []
368
+ d["acted"] = d["acts"][0][0] if d["acts"] else None
369
+ d["locked"] = bool(d["acts"])
358
370
  self.results = {}
359
371
  for x in self.experiments:
360
372
  for row in x["results"]:
@@ -655,7 +667,7 @@ class Lab:
655
667
  out = []
656
668
  for n, path in self._numbered(f"{self.root}/decisions/D*.md", r"/D(\d+)-[^/]+\.md$", {}, "D<n>-<name>.md"):
657
669
  fm, slots = self._card(path, "decision")
658
- d = {"title": f"D{n}", "about": [], "holds": [], "parks": [], "unparks": [], "drops": [], "order": [], "decided": None, "date": "", "see": [], **fm, "id": f"D{n}", "type": "decision", "slots": slots,
670
+ d = {"title": f"D{n}", "about": [], "holds": [], "parks": [], "unparks": [], "drops": [], "order": [], "folds": [], "decided": None, "date": "", "see": [], **fm, "id": f"D{n}", "type": "decision", "slots": slots,
659
671
  "path": self.rel(path), "dir": self.rel(os.path.dirname(path))}
660
672
  d["state"] = "done" if d["decided"] else "open"
661
673
  out.append(d)
@@ -689,6 +701,51 @@ class Lab:
689
701
  out.append(m)
690
702
  return out
691
703
 
704
+ def settled_at(self, ident, decided):
705
+ """When a decision was settled: the moment of the log line `lab decide` wrote, else the start of its day."""
706
+ line = next((l for l in self.lines if l["about"] == ident and l["kind"] == "decision" and l["what"].startswith("Decided:")), None)
707
+ if line:
708
+ return line["at"]
709
+ when = decided.get("date") if isinstance(decided, dict) else None
710
+ return day(when) or None
711
+
712
+ def acts(self, ident, order, since, came=(), granted=()):
713
+ """What acted on a settled decision, earliest first: [(moment, file, text)], where `file` is the record's file
714
+ that says so and `text` what it says there, so git can tell from which commit on it was so. A mission that
715
+ carries it was launched (the line `lab mission launch` writes in the lab's log, which only grows), or a run or
716
+ a trial started, after it was settled, of an experiment that its `order:` names (by its own id, its question's
717
+ or its goal's), that sits under a goal or a question that came out of it, or that uses a resource whose amounts
718
+ it set. `came` and `granted` add goals, questions and resources that history says came out of it. While there
719
+ is none, the decision is a draft, and may be revised."""
720
+ start, out = moment(since), []
721
+ after = lambda t: moment(t) and (start is None or moment(t) >= start)
722
+ launches = [l for l in self.lines if l["kind"] == "agent" and l["what"].startswith("Mission launched: ")]
723
+ out += [(l["at"], "log.md", f"| {ident} | agent | {l['what']}") for l in launches if l["about"] == ident and after(l["at"])]
724
+ said = {l["what"].split()[2] for l in launches if len(l["what"].split()) > 2} # missions whose launch the lab's log holds, whatever they carry now
725
+ for m in self.missions: # a mission launched by a kit before 1.10.0 wrote no line in the lab's log: its own log says it
726
+ if m["carries"] != ident or m["id"] in said:
727
+ continue
728
+ line = next((l for l in m["log"] if l.get("what") == "launched"), None)
729
+ if line and after(f"{line['day']}T{line['time']}:00+00:00"):
730
+ out += [(f"{line['day']}T{line['time']}:00+00:00", m["path"], f"- {line['day']} {line['time']} | launched")]
731
+ elif not line and m["state"] != "next" and since:
732
+ out += [(since, m["path"], f"carries: {ident}")]
733
+ held = self.held
734
+ scope = (set(order) | set(came) | set(held["orders"].get(ident, ())) # what it orders, or ever ordered as committed
735
+ | {n["id"] for n in self.goals + self.questions if str(n.get("from")) == ident} # and what came out of it, as now
736
+ | {i for i, f in held["from"].items() if f == ident}) # or as first committed
737
+ granted = (set(granted) | {name for name, froms in held["granted"].items() if ident in froms} # what it ever set the amounts of
738
+ | {name for name, r in self.resources.items() if isinstance(r, dict) and str(r.get("from")) == ident})
739
+ for x in self.experiments:
740
+ if scope & {x["id"], x["question"], x["goal"]} or granted & set(map(str, x.get("uses") or [])):
741
+ out += [(r["started"], os.path.join(x["dir"], "runs.tsv"), r["id"]) for r in x["runs"] + x["trials"] if r.get("started") and after(r["started"])]
742
+ return sorted((a for a in out if moment(a[0])), key=lambda a: moment(a[0]))
743
+
744
+ def acted_on(self, ident, order, since):
745
+ """The first moment anything acted on a settled decision, or None while nothing has (see `acts`)."""
746
+ found = self.acts(ident, order, since)
747
+ return found[0][0] if found else None
748
+
692
749
  def mission(self, ident):
693
750
  return next((m for m in self.missions if m["id"] == ident), None)
694
751
 
@@ -166,6 +166,54 @@ def header_css():
166
166
  return "".join(out)
167
167
 
168
168
 
169
+ # A mission's status reads as a card's state: next as open, current as running, done as done, stopped as dropped.
170
+ MISSION_KEY = {"next": "open", "current": "running", "done": "done", "stopped": "dropped"}
171
+
172
+
173
+ def mission_mark(m):
174
+ return mark(MISSION_KEY.get(m["state"], "open"), m["state"])
175
+
176
+
177
+ def mission_box(lab, T, m):
178
+ """One mission, compact: what it carries and where it stands, its steps as marks, its last line, and its log folded."""
179
+ d = lab.nodes.get(m["carries"])
180
+ carries = named(lab, d["id"]) if d and d["type"] == "decision" else '<span class="muted">no decision: lab check says why</span>'
181
+ started = next((l for l in m["log"] if l.get("what") == "launched"), None)
182
+ head = (f'{e(m["id"])} · {mission_mark(m)} {e(m["state"])} · carries {carries}'
183
+ + (f' · launched {nice(started["day"])}' if started else ""))
184
+ rows = []
185
+ if L.flat(m["description"]):
186
+ rows.append(("For", T(L.flat(m["description"]))))
187
+ steps = lab.mission_steps(m)
188
+ if steps:
189
+ done = sum(x["state"] in L.CLOSED for x in steps)
190
+ rows.append(("Steps", f'{done} of {len(steps)} closed <span class="marks">' + "".join(dot(x, f'{x["id"]} {x["title"]}: {label(x)}') for x in steps) + "</span>"))
191
+ lines = [l for l in m["log"] if l.get("what")]
192
+ if lines:
193
+ last = lines[-1]
194
+ rows.append(("Last", f'<span class="muted">{nice(last["day"])} {e(last["time"])}</span> {T(last["what"])}'))
195
+ if L.flat(m["slots"].get("Rules", "")):
196
+ rows.append(("Rules", f'<details><summary>the rules of this mission</summary>{block(T, m["slots"]["Rules"])}</details>'))
197
+ if len(lines) > 1:
198
+ rows.append(("Log", f'<details><summary>{len(lines)} lines</summary><ul class="mlog">'
199
+ + "".join(f'<li><span class="muted">{nice(l["day"])} {e(l["time"])}</span> {T(l["what"])}</li>' for l in lines) + "</ul></details>"))
200
+ return (f'<div class="box mission m-{e(m["state"])}" id="{e(m["id"])}"><div class="decisionhead">{head}</div>'
201
+ f'<p class="decisionq">{e(m["title"] or m["path"])}</p>'
202
+ '<dl class="decisionrows">' + "".join(f"<dt>{k}</dt><dd>{v}</dd>" for k, v in rows) + "</dl></div>")
203
+
204
+
205
+ def missions_page(lab, T):
206
+ """Every mission: the current first, then the next, then the closed, the latest first."""
207
+ body = ["<h1>Missions</h1>", '<p class="lead">A mission carries out a settled decision across sessions: its rules, and a log a later session resumes from.</p>']
208
+ closed = sorted([m for m in lab.missions if m["state"] in ("done", "stopped")], key=lambda m: m["n"], reverse=True)
209
+ for title, group in (("Current", [m for m in lab.missions if m["state"] == "current"]), ("Next", [m for m in lab.missions if m["state"] == "next"]), ("Closed", closed)):
210
+ if group:
211
+ body.append(f"<h2>{title}</h2>" + "".join(mission_box(lab, T, m) for m in group))
212
+ if not lab.missions:
213
+ body.append('<p class="muted">None yet.</p>')
214
+ return frame(lab, "Missions", "".join(body))
215
+
216
+
169
217
  def libraries(lab):
170
218
  """The other libraries this lab's charter names, each with where it is on disk and where it is served."""
171
219
  if not hasattr(lab, "_libraries"):
@@ -205,6 +253,9 @@ def page_title(lab, target):
205
253
 
206
254
  def ref(lab, ident, text=None):
207
255
  n = lab.nodes.get(ident)
256
+ if not n and ident in lab.folded: # a draft decision folded into a later one is read there
257
+ into = lab.folded[ident]
258
+ return f'<a class="ref" href="/{into}" data-tip="folded into {e(into)}">{e(text or ident)}</a>'
208
259
  if not n:
209
260
  return e(ident)
210
261
  return f'<a class="ref" href="/{ident}" data-tip="{e(n["title"])} ({e(label(n))})">{e(text or ident)}</a>'
@@ -325,6 +376,8 @@ CSS = """
325
376
  .lv .slot p+p{margin-top:.5rem}
326
377
  .lv .box{background:var(--surface);border:1px solid var(--rule);border-radius:8px;padding:.9rem 1.1rem;margin:0 0 1rem}
327
378
  .lv .box.decision{border-left:3px solid var(--warn);background:var(--warn-soft);margin:0 0 .8rem}
379
+ .lv .box.mission{border-left:3px solid var(--rule-strong);margin:0 0 .8rem}.lv .box.mission.m-current{border-left-color:var(--info);background:var(--info-soft)}
380
+ .lv .box.mission .marks{margin-left:.4rem}.lv .mlog{margin:.3rem 0 0;padding-left:1.1rem;font-size:.86rem}.lv .box.mission summary{cursor:pointer;color:var(--ink-3);font-size:.86rem}
328
381
  .lv .box.decision.closed{border-left-color:var(--ok);background:var(--ok-soft)}
329
382
  .lv .decisionhead{font:500 .78rem var(--sans);color:var(--muted);margin:0 0 .3rem}
330
383
  .lv .decisionq{font-size:1.08rem;line-height:1.45;margin:0 0 .6rem;font-weight:600}
@@ -730,6 +783,11 @@ def decision_box(lab, T, d, link=True, title=True):
730
783
  if done:
731
784
  rows.append((f'Decided {nice(d["decided"].get("date"))}', block(T, d["slots"].get("Decided", ""))))
732
785
  rows += [(verb if done else f"Would {verb.lower()}", "<br>".join(named(lab, i) if i in lab.nodes else e(i) for i in d[key])) for key, verb in (("parks", "Parks"), ("unparks", "Brings back")) if d[key]]
786
+ if d["folds"]:
787
+ rows.append(("Folds in", ", ".join(e(str(i)) for i in d["folds"]) + ": earlier drafts, revised into this one before anything acted on them"))
788
+ if done:
789
+ rows.append(("Locked", f'since {clock(d["acted"])}: something acted on it, so a change of mind is a new decision') if d["locked"]
790
+ else ("Draft", "Nothing has acted on it yet: it is revised here, not replaced by a new decision"))
733
791
  if d["order"]:
734
792
  rows.append(("Orders the work" if done else "Would order the work", "<ol>" + "".join(f"<li>{named(lab, i) if i in lab.nodes else e(i)}</li>" for i in d["order"]) + "</ol>"))
735
793
  if done and L.flat(d["slots"].get("Note", "")):
@@ -890,7 +948,7 @@ def live_box(lab, T):
890
948
  + (f' on {e(", ".join(x["uses"]))}' if x["uses"] else "") + ".</p>")
891
949
  for m in [m for m in lab.missions if m["state"] == "current"]:
892
950
  last = next((l for l in reversed(m["log"]) if l.get("what")), None)
893
- rows.append(f'<p><span class="who">mission</span>{mark("running")} {e(m["id"])} {e(m["title"])}'
951
+ rows.append(f'<p><span class="who">mission</span>{mark("running")} <a href="/missions#{e(m["id"])}">{e(m["id"])} {e(m["title"])}</a>'
894
952
  + (f' <span class="muted">last, {nice(last["day"])} {e(last["time"])}: {T(last["what"])}</span>' if last else "") + "</p>")
895
953
  d = lab.doing()
896
954
  if d:
@@ -1435,6 +1493,7 @@ class Provider:
1435
1493
  from folio.views import View
1436
1494
  lab = self.lab()
1437
1495
  T = Text(lab, inner)
1496
+ inner = lab.folded.get(inner, inner) # an old link to a folded draft opens the decision that took it in
1438
1497
  parts = inner.split("/")
1439
1498
  genre, status, description, page, path = "", "", "", None, ""
1440
1499
  if inner == "":
@@ -1443,6 +1502,8 @@ class Provider:
1443
1502
  page, path = log_page(lab, T, parts[1] if len(parts) == 2 else ""), "log.md"
1444
1503
  elif inner == "decisions":
1445
1504
  page = decisions_page(lab, T)
1505
+ elif inner == "missions":
1506
+ page = missions_page(lab, T)
1446
1507
  elif inner == "resources":
1447
1508
  page, path = resources_page(lab, T), "resources.toml"
1448
1509
  elif inner == "glossary":
@@ -1479,6 +1540,8 @@ class Provider:
1479
1540
 
1480
1541
  talk = len(lab.open_decisions())
1481
1542
  out = [{"title": "Now", "url": "/lab/"}, {"title": "Decisions", "url": "/lab/decisions/", **({"status": f"{talk} to discuss", "tone": "warn"} if talk else {})}]
1543
+ current = sum(m["state"] == "current" for m in lab.missions)
1544
+ out += [{"title": "Missions", "url": "/lab/missions/", **({"status": f"{current} current", "tone": "info"} if current else {})}] if lab.missions else []
1482
1545
  out += [{"title": t, "url": f"/lab/{p}"} for t, p in (("Log", "log/"), ("Resources", "resources/"), ("Glossary", "glossary/"))]
1483
1546
  for g in lab.live(lab.goals):
1484
1547
  questions, under = [], []
@@ -26,6 +26,11 @@ def decision_text(lab, d):
26
26
  for key, verb in (("parks", "Parks"), ("unparks", "Brings back"), ("drops", "Drops")):
27
27
  if d[key]:
28
28
  out += [f"{verb}: " + ", ".join(f"{i} {lab.nodes[i]['title']}" if i in lab.nodes else i for i in d[key])]
29
+ if d["folds"]:
30
+ out += ["Folds in the drafts: " + ", ".join(map(str, d["folds"]))]
31
+ if d["state"] == "done":
32
+ out += [f"Locked: acted on at {d['acted'][:16].replace('T', ' ')}; a change of mind is a new decision" if d["locked"]
33
+ else "A draft: nothing has acted on it yet, so revise it here rather than opening a new decision"]
29
34
  if d["order"]:
30
35
  out += [("Orders the work" if d["decided"] else "Would order the work") + ", first to last: " + ", ".join(d["order"])]
31
36
  out += [f"{slot}. {R.flat(d['slots'][slot])}" for slot in ("Seen", "Options", "Recommendation", "Decided") if R.flat(d["slots"].get(slot, ""))]
@@ -122,7 +122,8 @@ def new(lab, kind, parent, title, replaces=None, origin=None, about=(), because=
122
122
  for a in about:
123
123
  if lab.nodes.get(a, {}).get("type") not in ("goal", "question") + R.STEPS and a not in lab.resources:
124
124
  stop(f"--about {a}: no goal, question, experiment, build or reading has that id, and resources.toml lists no such resource")
125
- n = 1 + max([int(d["id"][1:]) for d in lab.decisions] or [0])
125
+ used = [d["id"] for d in lab.decisions] + list(lab.folded) + [l["about"] for l in lab.lines] # a folded decision's number is never used again
126
+ n = 1 + max([int(i[1:]) for i in used if re.fullmatch(r"D[1-9]\d*", str(i))] or [0])
126
127
  ident, path = f"D{n}", f"decisions/D{n}-{slug(title)}.md"
127
128
  text = CARDS["decision"].format(title=quoted, about=", ".join(about), today=today())
128
129
  elif kind == "goal":
@@ -443,8 +444,11 @@ def mission_launch(lab, ident=None):
443
444
  stop(f"{m['carries']} is still open: a mission carries out a settled decision. Settle it with the operator first")
444
445
  if not m["description"]:
445
446
  stop(f"{m['path']}: say what the mission is for, in the paragraph under the front matter")
447
+ title = (m["title"] or "untitled").replace("|", "/")
448
+ line = log_line(lab, m["carries"], "agent", f"Mission launched: {m['id']} {title}", f"It carries {m['carries']}, which is locked from now on", _mission=True)
446
449
  _mission_append(lab, m, _mission_line("launched"))
447
450
  _mission_status(lab, m, "current")
451
+ log(lab, m["carries"], "agent", *line, _mission=True) # the lab's log only grows: it holds that the decision was acted on
448
452
  return m["id"], m["path"]
449
453
 
450
454
 
@@ -0,0 +1,225 @@
1
+ """A settled decision is a draft until something acts on it: a mission that carries it is launched, or a run starts of
2
+ a step its `order:` names. A draft may be revised, or folded into a later decision; a locked one may not."""
3
+ import glob, os, re, sys
4
+
5
+ from test_flow import experiment, fill, front, git, lab, open_question
6
+ from test_integrity import commit
7
+ from test_order import order
8
+ from test_mission import saved
9
+
10
+
11
+ def settled_order(root, ids, title, text):
12
+ card, ident = order(root, ids, title)
13
+ lab(root, "decide", ident, "--with", "Ada", text)
14
+ return card, ident
15
+
16
+
17
+ def test_a_draft_is_revised_until_a_run_of_a_step_it_orders_starts(tmp_path):
18
+ root = str(tmp_path)
19
+ open_question(root)
20
+ ident, d, command = experiment(root)
21
+ card, d2 = settled_order(root, [ident], "The first experiment first", "The error experiment first: it is the cheapest check of the law.")
22
+ commit(root)
23
+ text = open(card).read()
24
+ # nothing has run since it was settled: its order and its Decided text may still change
25
+ open(card, "w").write(text.replace("the cheapest check", "the quickest check").replace(f"order: [{ident}]", "order: [G1.Q1]"))
26
+ assert "the record is sound" in lab(root, "check", "--no-rederive")
27
+ commit(root, "the order, revised")
28
+ # a run of a step it orders acts on it: from then it is locked
29
+ lab(root, "lock", ident)
30
+ lab(root, "run", ident, "--wait", "--", *command)
31
+ commit(root, "the run")
32
+ assert "Locked: acted on at" in lab(root, "show", d2)
33
+ revised = open(card).read()
34
+ open(card, "w").write(revised.replace("the quickest check", "the fastest check"))
35
+ out = lab(root, "check", "--no-rederive", ok=False)
36
+ assert f"{os.path.relpath(card, root)}: was locked when" in out and "a change of mind is a new decision" in out
37
+ commit(root, "reworded after the run") # committed in the same second as the run's, it is still after it
38
+ assert "was locked when" in lab(root, "check", "--no-rederive", ok=False)
39
+ git(root, "revert", "--no-edit", "HEAD")
40
+ open(card, "w").write(revised)
41
+ assert "the record is sound" in lab(root, "check", "--no-rederive")
42
+
43
+
44
+ def test_a_draft_is_folded_into_a_later_decision_and_its_number_is_never_used_again(tmp_path):
45
+ root = str(tmp_path)
46
+ open_question(root)
47
+ card2, d2 = settled_order(root, ["G1.Q1"], "The first question first", "The first question first: it is the only one.")
48
+ card3, d3 = settled_order(root, ["G1"], "The goal first", "The goal first, with its first question at the top.")
49
+ _, mission = saved(root, "The first question", d3)
50
+ commit(root)
51
+ assert (d2, d3) == ("D2", "D3")
52
+
53
+ # D2 is folded into D3: its file goes, and D3 says it took it in
54
+ os.remove(card2)
55
+ front(card3, folds="[D2]")
56
+ assert "the record is sound" in lab(root, "check", "--no-rederive")
57
+ assert "Folds in the drafts: D2" in lab(root, "show", "D3")
58
+ # its log line stays, read as about D3; a new decision does not take its number
59
+ assert "| D2 | decision | Decided: The first question first" in open(f"{root}/log.md").read()
60
+ out = lab(root, "new", "decision", "Something else", "--about", "G1")
61
+ assert "made D4" in out
62
+ os.remove(glob.glob(f"{root}/decisions/D4-*.md")[0])
63
+ commit(root, "D2 folded into D3")
64
+ assert "the record is sound" in lab(root, "check", "--no-rederive")
65
+
66
+ # what it may fold: an earlier decision that is gone, once
67
+ front(card3, folds="[D1]")
68
+ assert "folds D1, which is still here" in lab(root, "check", "--no-rederive", ok=False)
69
+ front(card3, folds="[D2, D2]")
70
+ assert "also folds" in lab(root, "check", "--no-rederive", ok=False)
71
+ front(card3, folds="[D2, x]")
72
+ assert "folds names 'x', which is not a decision's id" in lab(root, "check", "--no-rederive", ok=False)
73
+ front(card3, folds="[D2]")
74
+
75
+ # a decision gone without a fold is still a removal
76
+ text3 = open(card3).read()
77
+ os.remove(card3)
78
+ assert "was committed and is gone" in lab(root, "check", "--no-rederive", ok=False)
79
+ open(card3, "w").write(text3)
80
+
81
+ # a locked decision is not folded: D3 is launched on, then folded into a later one
82
+ lab(root, "mission", "launch")
83
+ commit(root, "launched")
84
+ card4, d4 = settled_order(root, ["G1"], "The goal, again", "The goal first, again.")
85
+ assert d4 == "D4" # the D4 made above was never committed or logged, so its number is free
86
+ os.remove(card3)
87
+ front(card4, folds="[D2, D3]") # what D3 took in moves with it
88
+ text = open(mission).read()
89
+ open(mission, "w").write(text.replace(f"carries: {d3}", f"carries: {d4}"))
90
+ out = lab(root, "check", "--no-rederive", ok=False)
91
+ assert "is folded into D4, and something acted on it" in out
92
+
93
+
94
+ def test_the_site_opens_a_folded_decision_where_it_went(tmp_path):
95
+ import pytest
96
+ pytest.importorskip("folio")
97
+ from lab_kit import record, site
98
+ root = str(tmp_path)
99
+ open_question(root)
100
+ card2, d2 = settled_order(root, ["G1.Q1"], "The first question first", "The first question first: it is the only one.")
101
+ card3, d3 = settled_order(root, ["G1"], "The goal first", "The goal first, with its first question at the top.")
102
+ os.remove(card2)
103
+ front(card3, folds="[D2]")
104
+ lab_ = record.Lab(root)
105
+ assert lab_.folded == {"D2": "D3"}
106
+ assert 'href="/D3"' in site.ref(lab_, "D2")
107
+ box = site.decision_box(lab_, site.Text(lab_, "D3"), lab_.nodes["D3"])
108
+ assert "Folds in" in box and "Draft" in box
109
+
110
+
111
+ def test_a_settled_decision_is_never_reopened_even_as_a_draft(tmp_path):
112
+ root = str(tmp_path)
113
+ open_question(root)
114
+ card, d2 = settled_order(root, ["G1.Q1"], "The first question first", "The first question first: it is the only one.")
115
+ commit(root)
116
+ text = open(card).read()
117
+ open(card, "w").write(re.sub(r"decided: .*\n", "", text).split("## Decided")[0])
118
+ assert "no longer says what was decided: a settled decision is never reopened" in lab(root, "check", "--no-rederive", ok=False)
119
+ open(card, "w").write(text)
120
+ front(card, folds="[D99]")
121
+ assert "folds D99, which the log never says was decided" in lab(root, "check", "--no-rederive", ok=False)
122
+
123
+
124
+ def test_what_acted_on_a_decision_cannot_be_taken_back_to_unlock_it(tmp_path):
125
+ from test_mission import saved
126
+ root = str(tmp_path)
127
+ open_question(root)
128
+ ident, d, command = experiment(root)
129
+ card, d2 = settled_order(root, [ident], "The first experiment first", "The error experiment first: it is the cheapest check of the law.")
130
+ lab(root, "lock", ident)
131
+ lab(root, "run", ident, "--wait", "--", *command) # under G1.Q1, which came out of D1, and named by D2's order
132
+ commit(root)
133
+ d1 = glob.glob(f"{root}/decisions/D1-*.md")[0]
134
+ question = glob.glob(f"{root}/goals/G1-*/Q1-*/question.md")[0]
135
+ texts = {p: open(p).read() for p in (card, d1, question, f"{root}/resources.toml")}
136
+
137
+ # D2 is locked by the run of the step it orders: emptying its order does not unlock it
138
+ open(card, "w").write(texts[card].replace(f"order: [{ident}]", "order: []").replace("the cheapest check", "the quickest check"))
139
+ assert "was locked when" in lab(root, "check", "--no-rederive", ok=False)
140
+ open(card, "w").write(texts[card])
141
+
142
+ # D1 is locked by a run under the question that came out of it: pointing the question elsewhere is refused
143
+ front(question, **{"from": d2})
144
+ open(d1, "w").write(texts[d1].replace("It runs on the laptop.", "It runs on the GPU."))
145
+ out = lab(root, "check", "--no-rederive", ok=False)
146
+ assert "`from:` was D1 when first committed" in out and "D1-" in out and "was locked when" in out
147
+ open(question, "w").write(texts[question])
148
+ open(d1, "w").write(texts[d1])
149
+
150
+ # a resource's `from` does not move without its amounts
151
+ open(f"{root}/resources.toml", "w").write(texts[f"{root}/resources.toml"].replace('from = "D1"', f'from = "{d2}"'))
152
+ commit(root, "the gpu's from moved")
153
+ assert "`from` changed in " in lab(root, "check", "--no-rederive", ok=False)
154
+ git(root, "revert", "--no-edit", "HEAD")
155
+
156
+ # a mission's launch is in the lab's log: pointing the mission elsewhere afterwards does not unlock its decision
157
+ card3, d3 = settled_order(root, ["G1"], "The goal first", "The goal first, with its first question at the top.")
158
+ _, mission = saved(root, "The goal", d3)
159
+ lab(root, "mission", "launch")
160
+ assert f"| {d3} | agent | Mission launched: M1 The goal |" in open(f"{root}/log.md").read()
161
+ commit(root, "launched")
162
+ text = open(mission).read()
163
+ open(mission, "w").write(text.replace(f"carries: {d3}", f"carries: {d2}"))
164
+ text3 = open(card3).read()
165
+ open(card3, "w").write(text3.replace("at the top", "first of all"))
166
+ assert f"{os.path.relpath(card3, root)}: was locked when" in lab(root, "check", "--no-rederive", ok=False)
167
+ open(mission, "w").write(text)
168
+ open(card3, "w").write(text3)
169
+
170
+ # a decision locked by a run is not folded away
171
+ os.remove(card)
172
+ front(card3, folds=f"[{d2}]")
173
+ assert f"is folded into {d3}, and something acted on it" in lab(root, "check", "--no-rederive", ok=False)
174
+
175
+
176
+ def test_a_lock_is_read_from_history_by_lab_show_and_lab_check_alike(tmp_path):
177
+ from test_mission import saved
178
+ root = str(tmp_path)
179
+ open_question(root)
180
+ ident, d, command = experiment(root)
181
+ card, d2 = settled_order(root, [ident], "The first experiment first", "The error experiment first: it is the cheapest check of the law.")
182
+ commit(root)
183
+ lab(root, "lock", ident)
184
+ lab(root, "run", ident, "--wait", "--", *command)
185
+ text = open(card).read()
186
+ open(card, "w").write(text.replace("the cheapest check", "the quickest check"))
187
+ commit(root, "the run, and the decision reworded with it") # an edit committed with the act is already a change of mind
188
+ assert "was locked when" in lab(root, "check", "--no-rederive", ok=False)
189
+ git(root, "revert", "--no-edit", "HEAD")
190
+
191
+ # its order emptied: lab show still says locked, as lab check holds it
192
+ root = str(tmp_path / "order")
193
+ os.makedirs(root)
194
+ open_question(root)
195
+ ident, d, command = experiment(root)
196
+ card, d2 = settled_order(root, [ident], "The first experiment first", "The error experiment first: it is the cheapest check of the law.")
197
+ commit(root)
198
+ lab(root, "lock", ident)
199
+ lab(root, "run", ident, "--wait", "--", *command)
200
+ commit(root, "the run")
201
+ front(card, order="[]")
202
+ assert "Locked: acted on at" in lab(root, "show", d2)
203
+
204
+ # D1 folded away in two commits: first pointed elsewhere and named under `folds:`, then removed
205
+ d1 = glob.glob(f"{root}/decisions/D1-*.md")[0]
206
+ front(card, order=f"[{ident}]", folds="[D1]")
207
+ for path in glob.glob(f"{root}/goals/G1-*/goal.md") + glob.glob(f"{root}/goals/G1-*/Q1-*/question.md"):
208
+ front(path, **{"from": d2})
209
+ commit(root, "D1 folded into D2")
210
+ os.remove(d1)
211
+ commit(root, "D1 removed")
212
+ assert "is folded into D2, and something acted on it" in lab(root, "check", "--no-rederive", ok=False)
213
+
214
+ # a mission launched for one decision and pointed at another later does not lock the other
215
+ root = str(tmp_path / "mission")
216
+ os.makedirs(root)
217
+ open_question(root)
218
+ card2, d2 = settled_order(root, ["G1"], "The goal first", "The goal first, with its first question at the top.")
219
+ _, mission = saved(root, "The goal", d2)
220
+ lab(root, "mission", "launch")
221
+ card3, d3 = settled_order(root, ["G1.Q1"], "The question first", "The first question first: it is the only one.")
222
+ text = open(mission).read()
223
+ open(mission, "w").write(text.replace(f"carries: {d2}", f"carries: {d3}"))
224
+ assert "A draft: nothing has acted on it yet" in lab(root, "show", d3)
225
+ assert "Locked: acted on at" in lab(root, "show", d2)
@@ -157,7 +157,8 @@ def test_a_rename_is_the_same_record_under_another_name(tmp_path):
157
157
 
158
158
  def redecide(root, d, was):
159
159
  card = f"{root}/decisions/D1-where-the-lab-starts.md"
160
- open(card, "w").write(open(card).read().replace("It runs on the laptop.", "It runs on the GPU."))
160
+ text = open(card).read()
161
+ open(card, "w").write(text.replace("It runs on the laptop.", "It runs on the GPU."))
161
162
  return "decisions/D1-where-the-lab-starts.md"
162
163
 
163
164
  under_cover("relocked", relock, "differs from the lock first committed in")
@@ -210,9 +210,21 @@ def test_amounts_and_settled_decisions_change_only_out_of_a_decision(tmp_path):
210
210
  commit(root, "a larger grant, out of D2")
211
211
  assert "the record is sound" in lab(root, "check", "--no-rederive")
212
212
 
213
- # a settled decision is not reworded, reopened or removed
213
+ # a settled decision that nothing has acted on is a draft: it may be revised
214
214
  text = open(card).read()
215
+ assert "A draft: nothing has acted on it yet" in lab(root, "show", "D2")
215
216
  open(card, "w").write(text.replace("A thousand hours", "Ten thousand hours"))
217
+ assert "the record is sound" in lab(root, "check", "--no-rederive")
218
+ open(card, "w").write(text)
219
+
220
+ # once a mission that carries it is launched, it is locked: it is not reworded, reopened or removed
221
+ from test_mission import saved
222
+ saved(root, "The full comparison", "D2")
223
+ lab(root, "mission", "launch")
224
+ commit(root, "the mission")
225
+ assert "Locked: acted on at" in lab(root, "show", "D2")
226
+ open(card, "w").write(text.replace("A thousand hours", "Ten thousand hours"))
227
+ assert "was locked when" in lab(root, "check", "--no-rederive", ok=False)
216
228
  assert "its Decided text has changed since; a change of mind is a new decision" in lab(root, "check", "--no-rederive", ok=False)
217
229
  open(card, "w").write(text.replace('with: "Ada"', 'with: "Grace"'))
218
230
  assert "has changed since" in lab(root, "check", "--no-rederive", ok=False)
@@ -514,6 +526,10 @@ def test_there_is_no_way_around_a_decision_to_a_larger_amount(tmp_path):
514
526
  two, d2, command2 = experiment(root, title="The same on the other name", uses="[gpu-b]", command=open(f"{d}/plan/sample.py").read())
515
527
  assert "whose amounts name no settled decision that lists it" in lab(root, "lock", two, ok=False) # D1 is settled, and is not about gpu-b
516
528
  card = glob.glob(f"{root}/decisions/D1-*.md")[0]
529
+ from test_mission import saved
530
+ saved(root, "The first question", "D1")
531
+ lab(root, "mission", "launch") # D1 is acted on, so it is locked
532
+ commit(root, "launched")
517
533
  front(card, about="[gpu, gpu-b]") # so the settled decision is made to be about it
518
534
  assert "its `about:` or its Decided text has changed since" in lab(root, "check", "--no-rederive", ok=False)
519
535
  lab(root, "review", two, "plan", "pass", "As the first.")
@@ -562,6 +578,9 @@ def test_there_is_no_way_around_a_decision_to_a_larger_amount(tmp_path):
562
578
  root = under(tmp_path, "override")
563
579
  open_question(root)
564
580
  ident, d, command = experiment(root, uses="[gpu]", command=WRITES % "0.5" + USES % 5)
581
+ from test_mission import saved
582
+ saved(root, "The first question", "D1")
583
+ lab(root, "mission", "launch") # acted on, so D1 is locked
565
584
  commit(root)
566
585
  front(f"{d}/experiment.md", override="{gpu: 6}")
567
586
  lab(root, "review", ident, "plan", "pass", "One thing varies; the refuting line can hold.")
@@ -64,7 +64,15 @@ def test_the_order_names_what_it_orders_once_and_stays_as_settled(tmp_path):
64
64
  git(root, "init", "-q")
65
65
  git(root, "add", ".")
66
66
  git(root, "commit", "-qm", "settled")
67
- front(card, order="[G1.Q1, G1.Q2]") # a settled order is changed by a new decision, not by editing this one
67
+ front(card, order="[G1.Q1, G1.Q2]") # while nothing has acted on it, a settled order is a draft and may be revised
68
+ assert "the record is sound" in lab(root, "check", "--no-rederive")
69
+ front(card, order="[G1.Q2, G1.Q1]")
70
+ from test_mission import saved
71
+ saved(root, "The biased coin first", d2)
72
+ lab(root, "mission", "launch")
73
+ git(root, "add", ".")
74
+ git(root, "commit", "-qm", "launched")
75
+ front(card, order="[G1.Q1, G1.Q2]") # once a mission is launched on it, the order is changed by a new decision, not by editing this one
68
76
  assert "the order it sets" in lab(root, "check", "--no-rederive", ok=False)
69
77
 
70
78
 
@@ -80,5 +80,10 @@ def test_parking_names_a_question_the_decision_is_about_and_stays_as_settled(tmp
80
80
  git(root, "init", "-q")
81
81
  git(root, "add", ".")
82
82
  git(root, "commit", "-qm", "settled")
83
- front(card, parks="[]") # what a settled decision parked cannot be taken back by editing it
84
- assert "and what it parks, drops or brings back, the order it sets, its `decided:`" in lab(root, "check", "--no-rederive", ok=False)
83
+ from test_mission import saved
84
+ saved(root, "The fair coin", d2)
85
+ lab(root, "mission", "launch")
86
+ git(root, "add", ".")
87
+ git(root, "commit", "-qm", "launched")
88
+ front(card, parks="[]") # what a locked decision parked cannot be taken back by editing it
89
+ assert "and what it parks, drops, folds or brings back, the order it sets, its `decided:`" in lab(root, "check", "--no-rederive", ok=False)
@@ -460,3 +460,29 @@ def test_every_state_has_one_mark_on_every_page_and_an_answer_is_a_boxed_word(tm
460
460
  assert S.key(busy) == "running" and "G1.Q1.2 running" in S.dot(busy) and " live" in S.dot(busy) # a question with a running step pulses
461
461
  assert S.key({"type": "goal", "state": "open", "questions": [busy]}) == "running"
462
462
  assert S.key({**busy, "state": "parked"}) == "parked"
463
+
464
+
465
+ def test_missions_have_a_compact_page_like_decisions_and_a_line_in_the_rail(tmp_path):
466
+ from test_flow import open_question
467
+ from test_order import order, three_steps
468
+ from test_mission import saved
469
+ root = str(tmp_path)
470
+ open_question(root)
471
+ three_steps(root)
472
+ card, d2 = order(root, ["G1.Q2.2", "G1.Q1", "G1.Q2"])
473
+ site = Provider(root)
474
+ assert all(r["title"] != "Missions" for r in site.rail()) # no mission yet: no page in the rail
475
+ saved(root, "The weight first", d2)
476
+ lab(root, "decide", d2, "--with", "Ada", "The weight on heads first.")
477
+ lab(root, "mission", "launch")
478
+ lab(root, "mission", "log", "started G1.Q2.2 in its own session")
479
+ site = Provider(root)
480
+ entry = next(r for r in site.rail() if r["title"] == "Missions")
481
+ assert entry["url"] == "/lab/missions/" and entry["status"] == "1 current"
482
+ page = site.get("missions").main
483
+ assert 'id="M1"' in page and "The weight first" in page and "Current" in page and f'href="/lab/{d2}/"' in page
484
+ assert re.search(r"\d of \d closed", page) and "in its own session</li>" in page and "<details>" in page
485
+ assert 'href="/lab/missions/#M1"' in site.get("").main # Now's mission line links to it
486
+ lab(root, "mission", "close", "M1", "Done for now.")
487
+ page = Provider(root).get("missions").main
488
+ assert "Closed" in page and "Current" not in page and "1 current" not in str(Provider(root).rail())
File without changes
File without changes
File without changes
File without changes
File without changes