lab-kit-cli 1.1.0__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/CHANGELOG.md +16 -0
  2. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/PKG-INFO +1 -1
  3. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/docs/model.md +16 -5
  4. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/pyproject.toml +1 -1
  5. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/skills/lab-talk/SKILL.md +6 -0
  6. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/skills/lab-work/SKILL.md +2 -0
  7. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/src/lab_kit/__init__.py +1 -1
  8. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/src/lab_kit/checks.py +6 -1
  9. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/src/lab_kit/history.py +4 -3
  10. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/src/lab_kit/record.py +22 -4
  11. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/src/lab_kit/site.py +4 -1
  12. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/src/lab_kit/views.py +6 -2
  13. lab_kit_cli-1.2.0/tests/test_order.py +85 -0
  14. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/tests/test_parked.py +1 -1
  15. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/.github/workflows/ci.yml +0 -0
  16. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/.github/workflows/policy.yml +0 -0
  17. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/.github/workflows/release.yml +0 -0
  18. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/.gitignore +0 -0
  19. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/AGENTS.md +0 -0
  20. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/CLAUDE.md +0 -0
  21. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/CONTRIBUTING.md +0 -0
  22. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/LICENSE +0 -0
  23. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/README.md +0 -0
  24. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/agents/reviewer.md +0 -0
  25. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/method/METHOD.md +0 -0
  26. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/skills/lab-review/SKILL.md +0 -0
  27. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/skills/lab-set-up/SKILL.md +0 -0
  28. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/src/lab_kit/cli.py +0 -0
  29. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/src/lab_kit/runs.py +0 -0
  30. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/src/lab_kit/supervise.py +0 -0
  31. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/src/lab_kit/write.py +0 -0
  32. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/tests/test_flow.py +0 -0
  33. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/tests/test_held.py +0 -0
  34. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/tests/test_integrity.py +0 -0
  35. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/tests/test_needs.py +0 -0
  36. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/tests/test_refusals.py +0 -0
  37. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/tests/test_site.py +0 -0
  38. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/tests/test_vocabulary.py +0 -0
  39. {lab_kit_cli-1.1.0 → lab_kit_cli-1.2.0}/tools/import_run.py +0 -0
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0
4
+
5
+ The order of the work can be agreed with the operator and recorded by a decision. Before, `lab now` and the
6
+ site listed next steps in the order of the tree, and an agreed order lived only as prose in a lab's
7
+ `AGENTS.md`, where a new session could miss it. The skills `lab-work` and `lab-talk` changed: run `lab init` in
8
+ a lab after upgrading, or `lab check` reports that they differ from the installed kit.
9
+
10
+ - A decision card may carry `order: [<ids>]`: goals, questions and steps, first to last. Once the decision is
11
+ settled, "Yours next" and "Not yours to move yet" in `lab now`, and Next and the idle line on the site's Now
12
+ page, list steps in that order. A step takes its own place if the order names it, else its question's, else
13
+ its goal's; steps sharing a place, and steps not named, keep the tree's order, the unnamed after the named.
14
+ The last settled decision, by number, that carries an `order:` has the say. An open decision orders nothing.
15
+ - `lab now` says which decision set the order; `lab show <decision>` and the decision's page list the order.
16
+ - `lab check` reports an `order:` that names something other than a goal, a question or a step, or names one
17
+ twice. A settled decision's `order:` is held against the lab's history, like its `about:`.
18
+
3
19
  ## 1.1.0
4
20
 
5
21
  A question can be parked: set aside by a decision, not dropped, and brought back only by another. Before, a
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: lab-kit-cli
3
- Version: 1.1.0
3
+ Version: 1.2.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
@@ -246,12 +246,22 @@ that parks or brings back a question has the say. An open decision parks nothing
246
246
  never come back, with `dropped: <why>` on its card; park one that may. A goal is closed by `reached: true` or
247
247
  `dropped: <why>`, and a dropped goal drops every question under it.
248
248
 
249
+ **The order of the work.** What the agent takes up first is agreed with you, and a settled decision records
250
+ it: `order:` lists goals, questions and steps, first to last. `lab now` ("Yours next", "Not yours to move yet")
251
+ and the site's Now page list steps in that order. A step takes the place of its own id where the order names it,
252
+ else of its question's, else of its goal's; steps that share a place, and every step the order does not name,
253
+ keep the order of the tree, the unnamed ones after the named. The last settled decision, by number, that carries
254
+ an `order:` has the say; an open decision orders nothing yet. The order only sorts: it moves nothing a step's
255
+ state holds, and a step under a parked or dropped question stays off the list wherever the order puts it. Each
256
+ id is a goal, a question or a step of the lab, named once. A step never carries its own place: the order is
257
+ worked out from the decision, never written on a card.
258
+
249
259
  You may also decide something nobody raised: add, change or drop an experiment or a build, reorder the
250
- work, stop a run. Say it, and the agent records it as a decision and follows it. Two things hold for
260
+ work (a decision with a new `order:`), stop a run. Say it, and the agent records it as a decision and follows it. Two things hold for
251
261
  you as for the agent: a locked plan is changed by a new experiment that replaces it, and an outcome is
252
262
  worked out from the results, not decided.
253
263
 
254
- **A settled decision stays as it was settled.** Its `decided:`, its `about:`, its `parks:`, its `unparks:` and its Decided text never
264
+ **A settled decision stays as it was settled.** Its `decided:`, its `about:`, its `parks:`, its `unparks:`, its `order:` and its Decided text never
255
265
  change once committed; a change of mind is a new decision. `lab check` holds this against the lab's
256
266
  history. So a decision cannot be made, afterwards, to be about something it never discussed.
257
267
 
@@ -389,7 +399,8 @@ the same briefing as text, which is what the agent says in chat when asked what
389
399
  and the answer in chat cannot differ. An experiment's page is the evidence behind one step.
390
400
 
391
401
  **Now** is read top to bottom in the order the operator asks: what is happening at this moment and
392
- how fresh the record is; what there is to discuss with you; what is next and who moves it; where each
402
+ how fresh the record is; what there is to discuss with you; what is next and who moves it, in the agreed
403
+ order of the work and naming the decision that set it; where each
393
404
  question stands (what is known so far, and nothing else); the latest events; what is left of each
394
405
  resource. Nothing on it is static text except one line per goal.
395
406
 
@@ -458,7 +469,7 @@ and its sealed runs across as what they were.
458
469
  **A card** is front matter, then its description as a paragraph, then `## Slot` sections. It never
459
470
  holds an id, a state or an outcome. Every file of a lab is UTF-8 text; line ends of either kind
460
471
  read the same, and so hash the same where a review is bound to a file. The front matter sits between
461
- the first two lines that are exactly `---`. A key that holds a list (`needs`, `uses`, `see`, `about`, `holds`, `parks`, `unparks`, `commits`,
472
+ the first two lines that are exactly `---`. A key that holds a list (`needs`, `uses`, `see`, `about`, `holds`, `parks`, `unparks`, `order`, `commits`,
462
473
  `tests`) is written as one, `[a, b]`; every other key holds one value.
463
474
 
464
475
  | Card | Front matter | Slots (word budget) |
@@ -468,7 +479,7 @@ the first two lines that are exactly `---`. A key that holds a list (`needs`, `u
468
479
  | `experiment.md` | `title:`, `needs:`, `uses:` (resources), `override: {resource: cap}`, `cost:`, `replaces:` with `because:` (one sentence), `waiting_on:`, `dropped: <why>` | description (70), Compares: the comparison in a sentence (80), Arms (260), Cases (100), Confirmed if (150), Refuted if (110), Outcomes (200), Limits (120), Found (180), Means (150) |
469
480
  | `reading.md` | `title:`, `needs:`, `dropped: <why>` | description (70), Looks at: what, and where it is (110), Seen (320), Suggests (150) |
470
481
  | `build.md` | `title:`, `needs:`, `commits:`, `tests:`, `dropped: <why>` | description (60), How it works (200), Works when (80) |
471
- | `D<n>-<slug>.md` | `title:`, `about:` (the goals, questions, experiments or resources it concerns), `date:`, `holds:`; `parks:` and `unparks:` (questions, each also under `about:`); `decided: {date, with}` is written by `lab decide` | Seen (120), Options: a list, one option an item (200), Recommendation (80), Decided (120) |
482
+ | `D<n>-<slug>.md` | `title:`, `about:` (the goals, questions, experiments or resources it concerns), `date:`, `holds:`; `parks:` and `unparks:` (questions, each also under `about:`); `order:` (goals, questions and steps, first to last); `decided: {date, with}` is written by `lab decide` | Seen (120), Options: a list, one option an item (200), Recommendation (80), Decided (120) |
472
483
 
473
484
  Any card may carry `see:`, a list of pages that explain it: pages of the lab's own library, and pages
474
485
  of another library its charter names, written as folio writes them (`pier-folio:/content/readings/...`),
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
5
5
  [project]
6
6
  dynamic = ["readme"]
7
7
  name = "lab-kit-cli"
8
- version = "1.1.0"
8
+ version = "1.2.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" }]
@@ -63,6 +63,12 @@ clear. To park, list the question under `parks:` and `about:` on the decision be
63
63
  the Decided text why and what would bring it back. To bring one back, a new decision lists it under
64
64
  `unparks:`. To close a goal, put `reached: true` or `dropped: <why>` on its card, out of a decision.
65
65
 
66
+ When they agree an order of work ("this first, then these side by side"), record it on the decision as
67
+ `order: [<ids>]`, first to last: goals, questions or steps, each once. A question or a goal stands for every
68
+ step under it; a step named on its own takes its own place. Steps not named follow, in the tree's order. Say
69
+ the order in the Decided text too. To change it, a new decision with a new `order:`; never edit a settled one,
70
+ and never write the order anywhere else (not in `AGENTS.md`, not on a step).
71
+
66
72
  ## Rules
67
73
 
68
74
  - Never copy the operator's messages into the lab. The record says what was decided and why.
@@ -17,6 +17,8 @@ discussion, recorded as a decision. What a decision settled needs no further yes
17
17
 
18
18
  `lab now`. If something is under **To discuss with the operator** and they are here, bring it to them
19
19
  first (the lab-talk skill). Otherwise take the first line under **Yours next**: it says what to do.
20
+ When a decision has set the order of the work, **Yours next** is already in that order and says which
21
+ decision set it; follow it, and bring a change of order to the operator rather than skipping ahead.
20
22
  `lab show <id>` before you touch anything.
21
23
 
22
24
  Then say what you are on, before the first edit: `lab log <id> doing "<what you are starting on>"
@@ -1,2 +1,2 @@
1
1
  """lab-kit: a research lab's record, its method, and the command that keeps both."""
2
- __version__ = "1.1.0"
2
+ __version__ = "1.2.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", "dropped", "see"},
13
13
  "reading": {"title", "needs", "dropped", "see"},
14
- "decision": {"title", "about", "date", "holds", "parks", "unparks", "decided", "see"},
14
+ "decision": {"title", "about", "date", "holds", "parks", "unparks", "order", "decided", "see"},
15
15
  }
16
16
 
17
17
 
@@ -131,6 +131,11 @@ def run(lab, rederive=True):
131
131
  bad("links", d["path"], f"{key} names {i}, which is not under `about:`: a decision that parks a question or brings it back is about it")
132
132
  for i in sorted(set(d["parks"]) & set(d["unparks"])):
133
133
  bad("links", d["path"], f"both parks and unparks {i}")
134
+ for i in d["order"]: # the order of the work names what it orders: goals, questions and steps, each once
135
+ if nodes.get(i, {}).get("type") not in ("goal", "question") + R.STEPS:
136
+ bad("links", d["path"], f"order names {i!r}, which is not a goal, a question or a step of the lab")
137
+ for i in sorted({i for i in d["order"] if d["order"].count(i) > 1}):
138
+ bad("links", d["path"], f"order names {i} more than once: each has one place")
134
139
  done = d["decided"]
135
140
  if done and not ({"date", "with"} <= set(done) and R.flat(d["slots"].get("Decided", ""))):
136
141
  bad("cards", d["path"], "a settled decision holds when, with whom, and what was decided and why under Decided")
@@ -14,7 +14,7 @@ same place: what was committed under the old name is held under the new one.
14
14
  - A `results.tsv` that a review has passed keeps every committed row. Once a results review that passed is committed
15
15
  together with the rows it read, those rows stay, whatever the card and the file say later. Rows committed while
16
16
  the last passed review was of other rows, such as a draft row added after it, were never reviewed and are not held.
17
- - A settled decision keeps its `decided:`, its `about:`, its `parks:`, its `unparks:` and its Decided text as first committed.
17
+ - A settled decision keeps its `decided:`, its `about:`, its `parks:`, its `unparks:`, its `order:` and its Decided text as first committed.
18
18
  - A resource, once committed, is never removed. A metered resource's `granted`, `per_run` and `unit` change only together
19
19
  with `from`, which then names another settled decision that lists the resource. Its `other_use` rows only grow.
20
20
  - None of these files is deleted, and none changes its number.
@@ -141,7 +141,8 @@ def decisions(lab, versions=None, now=None):
141
141
  if not isinstance(fm, dict) or fm.get("decided") is None:
142
142
  return None
143
143
  ids = lambda v: sorted(str(i) for i in (v if isinstance(v, list) else [v] if v is not None else []))
144
- return str(fm.get("decided")), ids(fm.get("about")), ids(fm.get("parks")), ids(fm.get("unparks")), R.flat(slots.get("Decided", ""))
144
+ 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
145
+ return str(fm.get("decided")), ids(fm.get("about")), ids(fm.get("parks")), ids(fm.get("unparks")), order, R.flat(slots.get("Decided", ""))
145
146
 
146
147
  for where, commits in sorted(versions.items()):
147
148
  if not DECISION.fullmatch(commits[-1][1]):
@@ -154,7 +155,7 @@ def decisions(lab, versions=None, now=None):
154
155
  if was:
155
156
  mine = path if path in now[where] else now[where][0]
156
157
  if settled(R.read(os.path.join(root, mine))) != was:
157
- bad(mine, f"was settled in {c[:8]}" + ("" if mine == path else f", as {path}") + ", and what it parks or brings back, its `decided:`, its `about:` or its Decided text has changed since; a change of mind is a new decision")
158
+ bad(mine, f"was settled in {c[:8]}" + ("" if mine == path else f", as {path}") + ", and what it parks 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")
158
159
  break
159
160
  return problems
160
161
 
@@ -43,7 +43,7 @@ COLUMNS = {"results.tsv": ("name", "label", "value", "reads", "versus", "command
43
43
  HASH = 2 # how a folder is hashed in the locks and runs made now; one without the marker was made with the first way
44
44
  NUMBER = re.compile(r"[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?")
45
45
  LISTS = {"goal": ("see",), "question": ("needs", "see"), "experiment": ("needs", "uses", "see"), "build": ("needs", "commits", "tests", "see"),
46
- "reading": ("needs", "see"), "decision": ("about", "holds", "parks", "unparks", "see")} # the front matter keys that hold a list
46
+ "reading": ("needs", "see"), "decision": ("about", "holds", "parks", "unparks", "order", "see")} # the front matter keys that hold a list
47
47
  TEXTS = ("title", "asks", "from", "replaces", "because", "cost", "waiting_on", "dropped", "answered") # and those that hold one value
48
48
 
49
49
 
@@ -627,7 +627,7 @@ class Lab:
627
627
  out = []
628
628
  for n, path in self._numbered(f"{self.root}/decisions/D*.md", r"/D(\d+)-[^/]+\.md$", {}, "D<n>-<name>.md"):
629
629
  fm, slots = self._card(path, "decision")
630
- d = {"title": f"D{n}", "about": [], "holds": [], "parks": [], "unparks": [], "decided": None, "date": "", "see": [], **fm, "id": f"D{n}", "type": "decision", "slots": slots,
630
+ d = {"title": f"D{n}", "about": [], "holds": [], "parks": [], "unparks": [], "order": [], "decided": None, "date": "", "see": [], **fm, "id": f"D{n}", "type": "decision", "slots": slots,
631
631
  "path": self.rel(path), "dir": self.rel(os.path.dirname(path))}
632
632
  d["state"] = "decided" if d["decided"] else "open"
633
633
  out.append(d)
@@ -686,7 +686,25 @@ class Lab:
686
686
  """The steps still pursued: under a question that is neither parked nor dropped, of a goal still active. What was
687
687
  set aside waits on a decision, not on the work, and is listed apart."""
688
688
  keep = {q["id"] for q in self.live(self.questions) if self.nodes[q["goal"]]["state"] == "active"}
689
- return [x for x in self.items if x["question"] in keep]
689
+ return self.in_order([x for x in self.items if x["question"] in keep])
690
+
691
+ def ordered_by(self):
692
+ """The settled decision that sets the order of the work, or None: the last settled decision, by number, that
693
+ carries an `order:`. The order is agreed with the operator, so it comes only out of a decision."""
694
+ return next((d for d in reversed(self.decisions) if d["state"] == "decided" and d["order"]), None)
695
+
696
+ def in_order(self, steps):
697
+ """Steps in the agreed order of the work: each takes the place of its own id in the order, else of its question's,
698
+ else of its goal's; steps that share a place, and those the order does not name, keep the order of the tree,
699
+ the unnamed after the named."""
700
+ d = self.ordered_by()
701
+ if not d:
702
+ return list(steps)
703
+ place = {}
704
+ for i, ident in enumerate(d["order"]):
705
+ place.setdefault(ident, i)
706
+ rank = lambda x: next((place[i] for i in (x["id"], x["question"], x["goal"]) if i in place), len(d["order"]))
707
+ return sorted(steps, key=rank) # a stable sort: what shares a place keeps the order of the tree
690
708
 
691
709
  def set_aside(self):
692
710
  """What was set aside, for the page and the view that list it: parked and dropped questions, and goals that
@@ -1008,7 +1026,7 @@ class Lab:
1008
1026
 
1009
1027
  def yours(self):
1010
1028
  """Every experiment and build the agent can move now, with what is next on each."""
1011
- return [x for x in self.items if x["mine"]]
1029
+ return self.in_order([x for x in self.items if x["mine"]])
1012
1030
 
1013
1031
  def since(self, day=None):
1014
1032
  """What happened since the last decision was recorded, or since a day."""
@@ -434,6 +434,8 @@ def decision_box(lab, T, d, link=True, title=True):
434
434
  if done:
435
435
  rows.append((f'Decided {nice(d["decided"].get("date"))}', block(T, d["slots"].get("Decided", ""))))
436
436
  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]]
437
+ if d["order"]:
438
+ 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>"))
437
439
  rows += [(k, block(T, d["slots"][k])) for k in ("Seen", "Options", "Recommendation") if L.flat(d["slots"].get(k, ""))]
438
440
  if not done:
439
441
  held = lab.held_by(d)
@@ -647,7 +649,8 @@ def home(lab, T):
647
649
  nxt = [x for x in lab.yours() if x["id"] != busy]
648
650
  held = [x for x in lab.pursued() if x["state"] == "waiting" or (x["state"] == "planned" and not x["mine"] and x["next"])]
649
651
  if nxt or held:
650
- out.append('<h2>Next</h2><table class="t"><tr><th>What</th><th>Who moves it</th><th>What happens next</th></tr>' + "".join(
652
+ by = lab.ordered_by()
653
+ out.append('<h2>Next</h2>' + (f'<p class="muted" style="font:.84rem var(--sans)">In the order of the work set by {named(lab, by["id"])}.</p>' if by else "") + '<table class="t"><tr><th>What</th><th>Who moves it</th><th>What happens next</th></tr>' + "".join(
651
654
  f'<tr><td>{named(lab, x["id"])}</td><td>{"the agent" if x["mine"] else "waits"}</td><td>{("" if x["mine"] else "on ") + T(you(x["next"]))}</td></tr>' for x in nxt + held) + "</table>")
652
655
  out.append("<h2>Where each question stands</h2>")
653
656
  for g in lab.live(lab.goals):
@@ -26,6 +26,8 @@ def decision_text(lab, d):
26
26
  for key, verb in (("parks", "Parks"), ("unparks", "Brings back")):
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["order"]:
30
+ out += [("Orders the work" if d["decided"] else "Would order the work") + ", first to last: " + ", ".join(d["order"])]
29
31
  out += [f"{slot}. {R.flat(d['slots'][slot])}" for slot in ("Seen", "Options", "Recommendation", "Decided") if R.flat(d["slots"].get(slot, ""))]
30
32
  if d["state"] == "open":
31
33
  held = lab.held_by(d)
@@ -71,9 +73,11 @@ def _now(lab):
71
73
  out += [decision_text(lab, d), ""]
72
74
  going = [f"- {x['id']} {x['title']}: {r['id']}, started {r['started']}" for x in lab.experiments for r in x["runs"] + x["trials"] if r["state"] == "running" and not r["orphan"]]
73
75
  out += ["" if not waiting else None, "Running"] + (going or ["- nothing"])
74
- out += ["", "Yours next"] + ([f"- {x['id']} {x['title']} ({x['type']}): {x['next']}" for x in lab.yours()] or ["- nothing"])
76
+ by = lab.ordered_by()
77
+ order = f" (in the order {by['id']} set)" if by else ""
78
+ out += ["", "Yours next" + order] + ([f"- {x['id']} {x['title']} ({x['type']}): {x['next']}" for x in lab.yours()] or ["- nothing"])
75
79
  held = [f"- {x['id']} {x['title']}: on {x['next']}" for x in lab.pursued() if x["state"] == "waiting" or (x["state"] == "planned" and not x["mine"])]
76
- out += ["", "Not yours to move yet"] + (held or ["- nothing"])
80
+ out += ["", "Not yours to move yet" + order] + (held or ["- nothing"])
77
81
  out += ["", "Questions"]
78
82
  for q in lab.live(lab.questions):
79
83
  counts = {}
@@ -0,0 +1,85 @@
1
+ """The order of the work, agreed with the operator: set by a settled decision's `order:`, worked out into the order
2
+ `lab now` and the site list the steps in, and never edited once settled."""
3
+ import glob, re
4
+
5
+ from test_flow import describe, fill, front, git, lab, open_question
6
+
7
+
8
+ def three_steps(root):
9
+ """A build under the first question, then a second question with two builds: G1.Q1.1, G1.Q2.1, G1.Q2.2."""
10
+ lab(root, "new", "build", "G1.Q1", "A fair sampler")
11
+ lab(root, "new", "question", "G1", "Does the error fall on a biased coin?", "--from", "D1")
12
+ describe(glob.glob(f"{root}/goals/G1-*/Q2-*/question.md")[0], "The law for a coin that is not fair, which the sampler can also draw.")
13
+ lab(root, "new", "build", "G1.Q2", "A biased sampler")
14
+ lab(root, "new", "build", "G1.Q2", "A weight on heads")
15
+ for card in glob.glob(f"{root}/goals/G1-*/Q*/*/build.md"):
16
+ describe(card, "A sampler the questions need before anything is measured.")
17
+
18
+
19
+ def order(root, ids, title="The order of the work"):
20
+ out = lab(root, "new", "decision", title, "--about", "G1")
21
+ card = sorted(glob.glob(f"{root}/decisions/D*.md"))[-1]
22
+ fill(card, Seen="Both questions have work the agent can move.", Options="(a) The biased coin first. (b) The tree's order.", Recommendation="(a).")
23
+ front(card, order=f"[{', '.join(ids)}]")
24
+ return card, out.split()[1].rstrip(":")
25
+
26
+
27
+ def listed(text, section):
28
+ """The ids a section of `lab now` lists, in its order."""
29
+ body = text.split(section, 1)[1].split("\n\n", 1)[0]
30
+ return re.findall(r"^- (G\d+\.Q\d+\.\d+) ", body, flags=re.M)
31
+
32
+
33
+ def test_steps_are_listed_in_the_order_a_settled_decision_sets(tmp_path):
34
+ root = str(tmp_path)
35
+ open_question(root)
36
+ three_steps(root)
37
+ assert listed(lab(root, "now"), "Yours next") == ["G1.Q1.1", "G1.Q2.1", "G1.Q2.2"]
38
+ # a step named on its own takes its own place; its question's place holds the rest of the question
39
+ card, d2 = order(root, ["G1.Q2.2", "G1.Q1", "G1.Q2"])
40
+ assert listed(lab(root, "now"), "Yours next") == ["G1.Q1.1", "G1.Q2.1", "G1.Q2.2"] # an open decision orders nothing yet
41
+ assert "Would order the work, first to last: G1.Q2.2, G1.Q1, G1.Q2" in lab(root, "show", d2)
42
+ lab(root, "decide", d2, "--with", "Ada", "The weight on heads first, then the fair coin, then the rest of the biased coin.")
43
+ now = lab(root, "now")
44
+ assert f"Yours next (in the order {d2} set)" in now
45
+ assert listed(now, "Yours next") == ["G1.Q2.2", "G1.Q1.1", "G1.Q2.1"]
46
+ assert "Orders the work, first to last" in lab(root, "show", d2)
47
+ # the last settled decision that sets an order has the say; what it does not name follows in the tree's order
48
+ _, d3 = order(root, ["G1.Q2.1"], "The biased sampler first")
49
+ lab(root, "decide", d3, "--with", "Ada", "The biased sampler first; the rest as the tree has it.")
50
+ assert listed(lab(root, "now"), "Yours next") == ["G1.Q2.1", "G1.Q1.1", "G1.Q2.2"]
51
+ assert "the record is sound" in lab(root, "check", "--no-rederive")
52
+
53
+
54
+ def test_the_order_names_what_it_orders_once_and_stays_as_settled(tmp_path):
55
+ root = str(tmp_path)
56
+ open_question(root)
57
+ three_steps(root)
58
+ card, d2 = order(root, ["G1.Q2", "G1.Q9", "G1.Q2", "gpu"])
59
+ out = lab(root, "check", "--no-rederive", ok=False)
60
+ assert "order names 'G1.Q9', which is not a goal, a question or a step" in out and "order names 'gpu'" in out
61
+ assert "order names G1.Q2 more than once" in out
62
+ front(card, order="[G1.Q2, G1.Q1]")
63
+ lab(root, "decide", d2, "--with", "Ada", "The biased coin first.")
64
+ git(root, "init", "-q")
65
+ git(root, "add", ".")
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
68
+ assert "the order it sets" in lab(root, "check", "--no-rederive", ok=False)
69
+
70
+
71
+ def test_the_site_lists_next_in_the_agreed_order(tmp_path):
72
+ import pytest
73
+ pytest.importorskip("folio.views")
74
+ from lab_kit.site import Provider
75
+ root = str(tmp_path)
76
+ open_question(root)
77
+ three_steps(root)
78
+ _, d2 = order(root, ["G1.Q2.2", "G1.Q1", "G1.Q2"])
79
+ lab(root, "decide", d2, "--with", "Ada", "The weight on heads first, then the fair coin, then the rest of the biased coin.")
80
+ site = Provider(root)
81
+ home = site.get("").main
82
+ nxt = home.split("<h2>Next</h2>", 1)[1].split("</table>", 1)[0]
83
+ assert "In the order of the work set by" in nxt
84
+ assert nxt.index("A weight on heads") < nxt.index("A fair sampler") < nxt.index("A biased sampler")
85
+ assert "Orders the work" in site.get(d2).main
@@ -77,4 +77,4 @@ def test_parking_names_a_question_the_decision_is_about_and_stays_as_settled(tmp
77
77
  git(root, "add", ".")
78
78
  git(root, "commit", "-qm", "settled")
79
79
  front(card, parks="[]") # what a settled decision parked cannot be taken back by editing it
80
- assert "and what it parks or brings back, its `decided:`" in lab(root, "check", "--no-rederive", ok=False)
80
+ assert "and what it parks or brings back, the order it sets, its `decided:`" in lab(root, "check", "--no-rederive", ok=False)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes