mkschreder123 commited on
Commit
c3a45c0
·
verified ·
1 Parent(s): 0296bfa

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -1,5 +1,6 @@
1
  *.7z filter=lfs diff=lfs merge=lfs -text
2
  *.arrow filter=lfs diff=lfs merge=lfs -text
 
3
  *.bin filter=lfs diff=lfs merge=lfs -text
4
  *.bz2 filter=lfs diff=lfs merge=lfs -text
5
  *.ckpt filter=lfs diff=lfs merge=lfs -text
@@ -8,6 +9,8 @@
8
  *.h5 filter=lfs diff=lfs merge=lfs -text
9
  *.joblib filter=lfs diff=lfs merge=lfs -text
10
  *.lfs.* filter=lfs diff=lfs merge=lfs -text
 
 
11
  *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
  *.model filter=lfs diff=lfs merge=lfs -text
13
  *.msgpack filter=lfs diff=lfs merge=lfs -text
@@ -33,3 +36,25 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  *.7z filter=lfs diff=lfs merge=lfs -text
2
  *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.avro filter=lfs diff=lfs merge=lfs -text
4
  *.bin filter=lfs diff=lfs merge=lfs -text
5
  *.bz2 filter=lfs diff=lfs merge=lfs -text
6
  *.ckpt filter=lfs diff=lfs merge=lfs -text
 
9
  *.h5 filter=lfs diff=lfs merge=lfs -text
10
  *.joblib filter=lfs diff=lfs merge=lfs -text
11
  *.lfs.* filter=lfs diff=lfs merge=lfs -text
12
+ *.lz4 filter=lfs diff=lfs merge=lfs -text
13
+ *.mds filter=lfs diff=lfs merge=lfs -text
14
  *.mlmodel filter=lfs diff=lfs merge=lfs -text
15
  *.model filter=lfs diff=lfs merge=lfs -text
16
  *.msgpack filter=lfs diff=lfs merge=lfs -text
 
36
  *.zip filter=lfs diff=lfs merge=lfs -text
37
  *.zst filter=lfs diff=lfs merge=lfs -text
38
  *tfevents* filter=lfs diff=lfs merge=lfs -text
39
+ # Audio files - uncompressed
40
+ *.pcm filter=lfs diff=lfs merge=lfs -text
41
+ *.sam filter=lfs diff=lfs merge=lfs -text
42
+ *.raw filter=lfs diff=lfs merge=lfs -text
43
+ # Audio files - compressed
44
+ *.aac filter=lfs diff=lfs merge=lfs -text
45
+ *.flac filter=lfs diff=lfs merge=lfs -text
46
+ *.mp3 filter=lfs diff=lfs merge=lfs -text
47
+ *.ogg filter=lfs diff=lfs merge=lfs -text
48
+ *.wav filter=lfs diff=lfs merge=lfs -text
49
+ # Image files - uncompressed
50
+ *.bmp filter=lfs diff=lfs merge=lfs -text
51
+ *.gif filter=lfs diff=lfs merge=lfs -text
52
+ *.png filter=lfs diff=lfs merge=lfs -text
53
+ *.tiff filter=lfs diff=lfs merge=lfs -text
54
+ # Image files - compressed
55
+ *.jpg filter=lfs diff=lfs merge=lfs -text
56
+ *.jpeg filter=lfs diff=lfs merge=lfs -text
57
+ *.webp filter=lfs diff=lfs merge=lfs -text
58
+ # Video files - compressed
59
+ *.mp4 filter=lfs diff=lfs merge=lfs -text
60
+ *.webm filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,407 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ license: cc-by-4.0
5
+ language:
6
+ - en
7
+ pretty_name: Knowledge
8
+ tags:
9
+ - knowledge-base
10
+ - agents
11
+ - procedures
12
+ ---
13
+ # Knowledge
14
+
15
+ A small, human-reviewable collection of working knowledge for agents: principles, step-by-step
16
+ procedures, one worked example per page and the mistakes to avoid. It covers how to work a task
17
+ with tools, exact calculation with money and dates, bookkeeping, contract work, support-desk
18
+ casework and the application of short written rules.
19
+
20
+ It teaches method. It is not an answer key for any task collection, and every figure, name and
21
+ date in its examples is invented.
22
+
23
+ Swedish Embedded AB implements solutions for teaching small language-model agents professional
24
+ procedures from written, reviewable knowledge for its clients. If your team needs expertise in
25
+ agent knowledge bases and their evaluation then you can procure our services by sending an email
26
+ to info@swedishembedded.com.
27
+
28
+ **Status: version 0.3, not yet reviewed by a human domain expert.** The reviewer index below
29
+ lists what to check.
30
+
31
+ ## How an agent uses it
32
+
33
+ The collection is a directory of plain Markdown. An agent needs only its location and ordinary
34
+ tools (`ls`, `grep`, `cat`, a file reader):
35
+
36
+ 1. read `index.md` at the top, which maps what a task asks for to a page;
37
+ 2. or read a folder's `index.md`, or `grep` for a word of the task;
38
+ 3. read the one or two pages that apply, and state each rule in its own words before acting.
39
+
40
+ Mount it **read-only, outside the task workspace, without a `.git` directory**. The pages refer
41
+ to each other as `/knowledge/<folder>/<page>.md`; `tools/kb.py export --mount-path <path>`
42
+ rewrites that prefix for another mount point. `README.md`, `tools/` and `.git` are for
43
+ maintainers and are not part of what an agent should see: mount an export, not the clone.
44
+
45
+ ## Conventions (followed here; nothing depends on them)
46
+
47
+ Any knowledge collection is interchangeable with this one as long as it is a directory an agent
48
+ can traverse. The conventions this collection follows:
49
+
50
+ - an `index.md` in every folder, written as "when the task asks X, read this page";
51
+ - plain Markdown that is easy to `grep`, ASCII punctuation, lowercase file names;
52
+ - optional YAML front-matter (here: SPDX line, copyright, `title`, `tiers`);
53
+ - every page in one order: **Rule**, **Procedure** (numbered steps), **Worked example**,
54
+ **Common mistakes**;
55
+ - a first rule on every page that the task's own files and stated rules win over the page;
56
+ - every page between about 600 and one thousand tokens, the root index at most about twelve hundred;
57
+ - rules written so that a reader can restate each one in a sentence or two;
58
+ - no page tells the reader to cite a file or a path.
59
+
60
+ No harness, examiner or learner may rely on these folder names, the front-matter or the tiers.
61
+
62
+ ## Tiers (an experiment convenience)
63
+
64
+ Each section of a page is preceded by a marker `<!-- tier: N -->`:
65
+
66
+ | Tier | Sections | Meaning |
67
+ |---|---|---|
68
+ | 1 | Rule | principles only |
69
+ | 2 | Procedure, Common mistakes | plus procedures and self-checks |
70
+ | 3 | Worked example | plus worked examples |
71
+
72
+ An experiment that wants a subset builds a filtered copy; agents and harnesses never parse
73
+ tiers:
74
+
75
+ ```sh
76
+ python3 tools/kb.py export --out /path/to/copy # everything (the default use)
77
+ python3 tools/kb.py export --out /path/to/copy --max-tier 1 # rules only
78
+ python3 tools/kb.py export --out /path/to/copy --max-tier 2 # rules, procedures, mistakes
79
+ ```
80
+
81
+ ## Maintenance checks
82
+
83
+ ```sh
84
+ python3 tools/kb.py lint # headers, sections, links, index coverage, token budgets
85
+ python3 tools/kb.py audit DIR... # leakage self-audit against practice-instance text
86
+ ```
87
+
88
+ - **Token budget.** Tokens are approximated as whitespace-separated words x 1.3. This undercounts
89
+ code blocks and tables somewhat; a tokenizer-exact check belongs to whoever mounts the
90
+ collection for a specific model.
91
+ - **Leakage self-audit.** `audit` compares every page with text a student sees in practice
92
+ instances (requests and workspace files): numbers with more than three digits before the
93
+ decimal point, identifiers, ISO dates, names the instances never write in lower case, and any
94
+ shared sequence of eight words. It is a self-check by the author. It cannot see sealed
95
+ examination material, and it is not the examiner's contamination audit.
96
+
97
+ ## Provenance
98
+
99
+ - **Written** on 20 November 2026 by an AI assistant (Claude, Anthropic) working as a domain author under
100
+ the direction of Martin Schröder. No human domain expert has reviewed it yet.
101
+ - **Inputs that were allowed and used:** the public task documentation and READMEs of the task
102
+ collections it was first written for; practice instances drawn by the author, of which only
103
+ the request and the workspace files a student sees were read; recorded practice attempts of a
104
+ small model, of which only the agent's side (requests, tool calls, answers) and the pass or
105
+ fail status of a whole attempt were read; general domain knowledge.
106
+ - **Inputs that were forbidden and not opened:** verifier, oracle and grader code; generators'
107
+ answer logic; reference solutions; sealed examinations and anything in an examiner's private
108
+ directories; seed files; per-check verification results.
109
+ - **Consequence:** the pages are grounded in what the tasks ask and in the mistakes actually
110
+ observed, but no page was checked against a grader. Where a page takes a position that a
111
+ grader might score differently, it is marked `REVIEW:` below.
112
+ - **Version 0.2** reworded three phrases that matched public task instruction text (found by
113
+ the examiner's audit; no content change).
114
+ - **Version 0.3 (20 November 2026)** makes every page defer to the task. Evidence, train-side
115
+ only: a practice measurement in which preloading the bookkeeping and calculation pages lowered
116
+ the pass rate on VAT and accrued-cost tasks, and the agent side of those practice attempts.
117
+ What the attempts showed, in general terms:
118
+ 1. the worked example was read as a description of the task: the model expected the task's
119
+ file to have the example's mix of cases, "saw" a date in an empty field, and reduced its
120
+ answer to the example's single expense account;
121
+ 2. a generic rule about cents and currency made the model decide that plainly decimal input
122
+ amounts were in another unit and rescale them;
123
+ 3. "amount x rate" on the page met a rate table in percent, and the model divided by 100 twice
124
+ or doubted its correct result;
125
+ 4. a page covering three kinds of adjustment made the model look for the two kinds the task
126
+ had no inputs for;
127
+ 5. restating a rule the request already states gave the model two sources to reconcile, and
128
+ the attempts with pages took about two to four times as many steps, many of them ending
129
+ without an answer.
130
+ Changes: a first rule on every page ("The task's own files and stated rules always win over
131
+ this page; use this page only for what the task leaves open"); the same in the index and the
132
+ workflow page; a fixed disclaimer above every worked example; the period-end page split into
133
+ three single-purpose pages whose examples show several accounts and mixed cases; the money and
134
+ VAT pages rewritten around "use the request's method as written"; default counting rules on
135
+ the dates and limits pages marked as applying only where the task is silent; mistake lists
136
+ shortened to keep the token budget.
137
+ - **Direction of information.** An examiner may read this collection freely. Nothing from an
138
+ examiner's oracles, seeds or item-level results may flow into it. Revisions are made only from
139
+ train-side evidence, and each revision gets a new version tag.
140
+
141
+ ## Reviewer index
142
+
143
+ For each file: the real-world authority it summarises, the claims a human should check
144
+ (`REVIEW:`), and the resources that would strengthen it. Sizes are from `tools/kb.py lint`.
145
+
146
+ ### `agent-workflow/workflow.md` (how to work any task with tools)
147
+
148
+ - **Authority:** engineering practice for tool-using agents; no formal standard.
149
+ - REVIEW: the rule "never clean or reset the repository" and "delete your helper files" assume a
150
+ workspace graded by its final file state. Confirm for each harness.
151
+ - REVIEW: the budget rule (write an answer when half the steps are gone) is a heuristic.
152
+ - REVIEW: "never search the repository history" matches the examiner's anti-probing rule as
153
+ publicly documented; confirm the exact boundary (is `git status` acceptable?).
154
+ - **Resources wanted:** the harness's tool definitions and step and token limits, so the page
155
+ can be checked against them; the examiner's public statement of what counts as probing.
156
+
157
+ ### `agent-workflow/answer-file.md` (JSON answer files)
158
+
159
+ - **Authority:** RFC 8259 (JSON); Python `json` and `decimal` documentation.
160
+ - REVIEW: writing money as a JSON number through `float()` is safe for two-decimal values only
161
+ if the grader compares in whole cents. Confirm, or prescribe numeric strings.
162
+ - **Resources wanted:** the answer-format conventions of each task collection.
163
+
164
+ ### `agent-workflow/missing-information.md` (abstaining correctly)
165
+
166
+ - **Authority:** professional scepticism in auditing (ISA 200, ISA 500 on sufficiency of
167
+ evidence); burden-of-proof reasoning in law.
168
+ - REVIEW: "a total over an unknown line is unknown" follows the task wording seen in practice; a
169
+ different collection may want partial totals.
170
+ - **Resources wanted:** an audit-evidence standard extract; internal rules on incomplete
171
+ filings.
172
+
173
+ ### `calculation/money.md`
174
+
175
+ - **Authority:** IEEE 754 (why binary floats misround); the EU VAT Directive 2006/112/EC
176
+ (output and input tax); national VAT rounding guidance; commercial rounding ("round half up").
177
+ - REVIEW: since version 0.3 the page states no default rounding or unit: "use the task's
178
+ formula, rounding and units as written", "take input amounts as they stand", "a percent rate
179
+ is divided by 100 exactly once". The cents-against-currency rule was removed from this page
180
+ (it stays on the support pages, where records really are in cents).
181
+ - REVIEW: the interest formula uses simple interest over a stated year length; check against
182
+ the applicable interest act (in Sweden, Rantelagen 1975:635: reference rate plus eight
183
+ percentage points, actual days).
184
+ - **Resources wanted:** Skatteverket guidance on VAT calculation and rounding; the interest act
185
+ and the current reference rate.
186
+
187
+ ### `calculation/dates.md`
188
+
189
+ - **Authority:** conventions of period computation, for example Regulation (EEC, Euratom)
190
+ 1182/71 on periods, dates and time limits; in Sweden, lagen (1930:173) om berakning av
191
+ lagstadgad tid; the ISO date notation.
192
+ - REVIEW: "a period starts the day after its trigger" and "month periods end on the same day
193
+ number, clamped" are the common rules; some statutes differ.
194
+ - REVIEW: rolling to the next business day is stated as conditional on the task; real law
195
+ usually rolls performance deadlines and not limitation periods, but there are exceptions.
196
+ - REVIEW: the notice-period convention (count from the first day of the following month) is a
197
+ contractual convention, not a general rule.
198
+ - **Resources wanted:** the period-computation statute that applies; the organisation's own
199
+ business-day calendar rules.
200
+
201
+ ### `calculation/limits.md`
202
+
203
+ - **Authority:** legal drafting conventions for thresholds; contract practice on liquidated
204
+ damages per commenced week.
205
+ - REVIEW: "within N" is treated as inclusive of day N; confirm for the governing drafting style.
206
+ - REVIEW: the look-back window is taken as inclusive at both ends.
207
+ - REVIEW: "a threshold stated in weeks is tested in days as weeks x 7" follows the rule table
208
+ seen in practice; a contract may define it differently.
209
+ - **Resources wanted:** a drafting manual (for example a government legislative drafting guide)
210
+ for threshold wording.
211
+
212
+ ### `accounting/bank-reconciliation.md`
213
+
214
+ - **Authority:** standard bank-reconciliation practice as taught in introductory financial
215
+ accounting; internal-control guidance (COSO) on reconciliations.
216
+ - REVIEW: the page assumes the bank is right when amounts differ (transpositions are book
217
+ errors). Bank errors exist in practice and are not covered.
218
+ - REVIEW: "a duplicate is reported as the later entry" is a task convention.
219
+ - REVIEW: matching by description rather than date assumes descriptions carry a reference.
220
+ - **Resources wanted:** an accounting textbook chapter on bank reconciliation; the company's
221
+ reconciliation procedure.
222
+
223
+ ### `accounting/vat.md`
224
+
225
+ - **Authority:** EU VAT Directive 2006/112/EC; Mervardesskattelagen (2023:200); Skatteverket
226
+ guidance.
227
+ - REVIEW: the page teaches rate-by-category-and-date lookup only. It omits reverse charge, the
228
+ place-of-supply rules, partial deduction and the tax point (the invoice date is assumed to
229
+ decide the rate).
230
+ - REVIEW: gross-to-net by division then subtraction is the statutory method; confirm rounding.
231
+ - **Resources wanted:** the current rate table and its change history from the tax authority;
232
+ guidance on which date decides the rate.
233
+
234
+ ### `accounting/journal-errors.md`
235
+
236
+ - **Authority:** double-entry bookkeeping; Bokforingslagen (1999:1078) on vouchers as the basis
237
+ of entries; the "divisible by 9" test for transpositions (standard audit technique).
238
+ - REVIEW: the fault kinds and "report the later duplicate" are task conventions.
239
+ - REVIEW: the corrected trial balance is built from the documents alone, assuming every
240
+ transaction has exactly one document with one debit and one credit account.
241
+ - **Resources wanted:** the BAS chart of accounts; an auditing text on error detection.
242
+
243
+ ### `accounting/accrued-costs.md`, `accounting/prepaid-costs.md`, `accounting/depreciation.md`
244
+
245
+ One page per kind of period-end adjustment since version 0.3 (before: one page for all three).
246
+
247
+ - **Authority:** accrual basis of accounting (IAS 1; in Sweden Arsredovisningslagen 1995:1554
248
+ and BFN guidance K2/K3); IAS 16 on depreciation.
249
+ - REVIEW: each page now says "if the request states the method, apply it as written" and gives
250
+ its own rules only as explanation. Check that the explanations never read as a second method.
251
+ - REVIEW: "invoiced after the period end counts as not invoiced" is the correct cut-off rule but
252
+ ignores materiality thresholds that K2 allows.
253
+ - REVIEW: prepaid costs are spread over the invoice's own service period in the unit and
254
+ rounding order the request names; daily proration is equally common in practice.
255
+ - REVIEW: the first month of depreciation is "the one the request names"; many policies start
256
+ the month after acquisition, or prorate.
257
+ - REVIEW: "only what the task gives inputs for" (no prepaid or depreciation entries in a task
258
+ that has only deliveries) is a task-scoping rule, not an accounting rule.
259
+ - **Resources wanted:** BFNAR 2016:10 (K2) and BFNAR 2012:1 (K3) sections on accruals and
260
+ depreciation; the company's accounting manual.
261
+
262
+ ### `accounting/consolidation.md`
263
+
264
+ - **Authority:** IFRS 10 (consolidated financial statements); K3 chapter 9; acquisition method
265
+ in IFRS 3.
266
+ - REVIEW: the page eliminates the investment against the subsidiaries' share capital only and
267
+ lets their retained earnings add up. This matches the simplified task rules; real
268
+ consolidation eliminates all pre-acquisition equity and recognises goodwill.
269
+ - REVIEW: goods in transit are booked as a purchase at the buyer, as the task prescribes; real
270
+ practice books inventory in transit and eliminates unrealised internal profit.
271
+ - REVIEW: wholly owned subsidiaries only; no non-controlling interests.
272
+ - **Resources wanted:** IFRS 10 and IFRS 3 extracts or a group-accounting textbook; the group's
273
+ consolidation manual.
274
+
275
+ ### `legal/contract-review.md`
276
+
277
+ - **Authority:** contract-drafting practice (for example K. Adams, *A Manual of Style for
278
+ Contract Drafting*); general principles of contract interpretation.
279
+ - REVIEW: "a definition anywhere in the agreement counts, also after first use" is standard
280
+ drafting practice; confirm.
281
+ - REVIEW: what counts as a defined-term use (capitalised, used repeatedly) is a heuristic.
282
+ - REVIEW: precision is weighted like recall here because the tasks penalise false reports; a
283
+ real review would flag doubtful items with a note.
284
+ - **Resources wanted:** the firm's contract-review checklist and drafting style guide.
285
+
286
+ ### `legal/deadlines.md`
287
+
288
+ - **Authority:** Koplagen (1990:931) on complaints; Rantelagen (1975:635); Preskriptionslagen
289
+ (1981:130) on limitation (ten years, three years for claims against consumers); CISG articles
290
+ 38-39 on examination and notice.
291
+ - REVIEW: the page deliberately gives no periods; it sends the reader to the contract and the
292
+ rule table. Confirm this division of sources.
293
+ - REVIEW: "where a clause gives two limits the earlier governs" matches the rule table seen in
294
+ practice and CISG article 39(2)-style long-stop clauses.
295
+ - **Resources wanted:** the statutes named above; the standard terms in use (for example
296
+ NL 17, Orgalim S 2022).
297
+
298
+ ### `legal/breach.md`
299
+
300
+ - **Authority:** sale-of-goods law on delay and defects (Koplagen sections 22-40; CISG articles
301
+ 45-52 and 74-77); contract practice on liquidated damages and limitation of liability.
302
+ - REVIEW: **"a late complaint removes the remedy but not the breach"** is the legally sound
303
+ position and the page teaches it firmly; a grader could instead treat the case as no breach.
304
+ This is the single most consequential unverified claim in the collection.
305
+ - REVIEW: the damages ceiling is taken from the general limitation-of-liability clause and not
306
+ from the cap on liquidated damages.
307
+ - REVIEW: "evidence is only the decisive documents" (which documents count as decisive for each
308
+ breach type is left to the reader).
309
+ - **Resources wanted:** a commentary on Koplagen or CISG remedies; the firm's breach-assessment
310
+ template.
311
+
312
+ ### `support/tickets.md`
313
+
314
+ - **Authority:** service-desk practice (ITIL 4 incident and request handling); internal-control
315
+ principle of acting only through the system of record.
316
+ - REVIEW: "exactly one outcome per ticket" and "first applicable rule decides" follow the policy
317
+ seen in practice; other desks allow combined outcomes.
318
+ - REVIEW: the advice to avoid quotation marks and special letters in messages trades natural
319
+ language for shell safety.
320
+ - **Resources wanted:** the organisation's support policy and tool manual.
321
+
322
+ ### `support/refunds.md`
323
+
324
+ - **Authority:** consumer-return practice; Distansavtalslagen (2005:59) and the EU Consumer
325
+ Rights Directive 2011/83/EU on withdrawal; Konsumentkoplagen (2022:260) on defects; card-scheme
326
+ chargeback rules.
327
+ - REVIEW: the screening order (abuse, order identified, already refunded, kind of claim, agent
328
+ limit) mirrors the policy seen in practice and is presented as "usual", not as universal.
329
+ - REVIEW: "over the agent's limit means no refund by you" (no partial payment).
330
+ - REVIEW: windows are counted inclusive of the last day, from delivery to the system date.
331
+ - **Resources wanted:** the real refund and fraud policy; consumer-law summaries for the markets
332
+ served.
333
+
334
+ ### `support/procurement.md`
335
+
336
+ - **Authority:** purchasing practice (CIPS guidance on supplier selection); for public buyers,
337
+ Directive 2014/24/EU award criteria.
338
+ - REVIEW: "the choice is fixed before the limit is tested" (no switching to a cheaper or dearer
339
+ quote to stay under the approval limit).
340
+ - REVIEW: lowest total as the sole award criterion.
341
+ - **Resources wanted:** the organisation's procurement policy and approval matrix.
342
+
343
+ ### `compiled/apply-rules.md`
344
+
345
+ - **Authority:** statutory interpretation: rule, exception, burden; lex posterior for
346
+ amendments.
347
+ - REVIEW: **the three-way distinction** (right exists; right barred by an exception; condition
348
+ never met) and the instruction to test the condition before the exception. Practice attempts
349
+ suggest this is where most points were lost, but which label a grader expects when both the
350
+ condition fails and an exception would apply was inferred, not confirmed.
351
+ - REVIEW: "an exception to one right does not touch another unless the text says so".
352
+ - **Resources wanted:** an introduction to statutory interpretation; the organisation's rule
353
+ authoring guide, if rules are written in-house.
354
+
355
+ ### `compiled/which-document-wins.md`
356
+
357
+ - **Authority:** hierarchy-of-norms principles (lex superior, lex posterior); document-control
358
+ practice (ISO 9001 clause 7.5 on controlled documents).
359
+ - REVIEW: precedence order authority, then date, then version, is taken from the task request
360
+ and presented as "common".
361
+ - REVIEW: "an amendment replaces only the statements it restates".
362
+ - REVIEW: "give the value exactly as written, with its unit".
363
+ - **Resources wanted:** the organisation's document-control procedure.
364
+
365
+ ### `compiled/deadlines-and-drafts.md`
366
+
367
+ - **Authority:** as for `calculation/dates.md` and `calculation/limits.md`.
368
+ - REVIEW: chained deadlines are computed without rolling or business-day rules unless the
369
+ material states them.
370
+ - REVIEW: a draft item equal to a maximum is treated as allowed.
371
+ - **Resources wanted:** none beyond those above.
372
+
373
+ ### Every page (since version 0.3)
374
+
375
+ - REVIEW: the deference rule and the example disclaimer are untested: they were written from the
376
+ failure analysis above, and no measurement has yet shown that they remove the harm. The
377
+ with-pages against without-pages comparison on bookkeeping tasks must be repeated.
378
+ - REVIEW: whether worked examples should be mounted at all for a small model when pages are
379
+ preloaded rather than looked up (the tier-2 export leaves them out).
380
+ - REVIEW: mistake lists were shortened for the token budget; check nothing important was lost.
381
+
382
+ ### `index.md` and the folder `index.md` files
383
+
384
+ - REVIEW: every trigger phrase should use words a task would actually use; check against real
385
+ task requests of each new collection the knowledge is used with.
386
+
387
+ ## What the user could supply to strengthen it
388
+
389
+ In order of expected value:
390
+
391
+ 1. A domain expert's read of the `REVIEW:` items marked in bold above (breach versus remedy; the
392
+ three-way outcome distinction).
393
+ 2. The organisation's own handbooks where the pages now say "usual": accounting manual
394
+ (cut-off, proration, depreciation start), support and refund policy, procurement policy and
395
+ approval matrix, contract-review checklist.
396
+ 3. Standards and statutes named per file: K2/K3, IFRS 10 and 3, IAS 16, the VAT act and
397
+ Skatteverket rounding guidance, Rantelagen, Preskriptionslagen, Koplagen, CISG, the
398
+ period-computation statute.
399
+ 4. The harness facts the workflow page depends on: tool names and parameters, step and token
400
+ limits, and the examiner's definition of probing.
401
+ 5. Textbook chapters for depth where a 4B reader lacks the prerequisite: bank reconciliation,
402
+ error detection in journals, group accounts.
403
+
404
+ ## Licence
405
+
406
+ Creative Commons Attribution 4.0 International (CC-BY-4.0).
407
+ Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>.
accounting/accrued-costs.md ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Accrued costs at period end
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Accrued costs at period end
8
+
9
+ For period-end tasks that give deliveries (goods or services received) with their invoice dates
10
+ and ask for the adjusting entries.
11
+
12
+ <!-- tier: 1 -->
13
+ ## Rule
14
+
15
+ **The task's own files and stated rules always win over this page; use this page only for what
16
+ the task leaves open.**
17
+
18
+ 1. If the request states which deliveries are accrued and which accounts to use, apply that
19
+ sentence as written. The points below only explain it.
20
+ 2. **Accrual principle:** a cost belongs to the period in which the goods or service were
21
+ received, whatever the date of the invoice.
22
+ 3. **Decide row by row, from the row's own fields.** Read each delivery's dates exactly as the
23
+ file gives them. An empty invoice field is empty; never fill it in.
24
+ 4. **Each accrued row is debited to the expense account in that row** and credited to the
25
+ accrual account the request names. Rows can use different expense accounts; the answer then
26
+ has one line for each of them.
27
+ 5. **Only what the task gives inputs for.** A task with only deliveries has only accrued costs:
28
+ no prepaid costs, no depreciation.
29
+ 6. **The entries balance:** debits positive, credits negative, all accounts sum to zero.
30
+
31
+ <!-- tier: 2 -->
32
+ ## Procedure
33
+
34
+ 1. Note the period end date and the accrual account from the request.
35
+ 2. Read the deliveries file. For every row write down: delivered date, invoice date (or
36
+ "empty"), amount, expense account.
37
+ 3. Test every row against the request's condition. The common condition is: received no
38
+ later than the closing date, and no invoice dated up to that date. Then a row is accrued
39
+ when it was delivered no later than the period end and its invoice date is empty or after
40
+ it.
41
+ 4. In a script: for each accrued row add its amount to its own expense account and subtract it
42
+ from the accrual account. Use the amounts as they stand in the file; nothing is rounded or
43
+ rescaled.
44
+ 5. Drop accounts whose net is zero, if the request says to omit them.
45
+ 6. Check: the number of accrued rows matches your row-by-row list; every expense account of an
46
+ accrued row appears; the total is exactly zero; the answer has the shape of the request,
47
+ including its outer key.
48
+
49
+ <!-- tier: 3 -->
50
+ ## Worked example
51
+
52
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
53
+ expected result from this example.
54
+
55
+ Period ends on the last day of April. The request's accrual account is called Accruals here.
56
+
57
+ | Row | Delivered | Invoiced | Amount | Expense account | Accrued? |
58
+ |---|---|---|---|---|---|
59
+ | 1 | 12 April | 3 May | 800.00 | Consumables | yes: invoiced after the period end |
60
+ | 2 | 20 April | empty | 150.00 | Freight | yes: not invoiced |
61
+ | 3 | 8 April | 22 April | 500.00 | Consumables | no: invoiced within the period |
62
+ | 4 | 2 May | empty | 300.00 | Freight | no: delivered after the period end |
63
+ | 5 | 27 April | empty | 90.00 | Consumables | yes: not invoiced |
64
+
65
+ Net adjustment per account: Consumables +890.00 (rows 1 and 5), Freight +150.00 (row 2),
66
+ Accruals -1040.00. Sum: 890.00 + 150.00 - 1040.00 = 0.
67
+
68
+ In another file every row might be accrued, or none; there might be one expense account or
69
+ five. The file decides, not this table.
70
+
71
+ <!-- tier: 2 -->
72
+ ## Common mistakes
73
+
74
+ - Expecting the task's file to look like an example, and "seeing" an invoice date in a row whose
75
+ invoice field is empty.
76
+ - Putting all accrued rows on one expense account although the rows name different accounts.
77
+ - Leaving out an accrued row.
78
+ - Treating any filled invoice date as "invoiced", although the date is after the period end.
79
+ - Accruing a delivery made after the period end.
80
+ - Adding prepaid or depreciation entries that the task gave no inputs for, or spending many
81
+ steps wondering about them.
82
+ - Reversed signs: the expense is the debit (positive), the accrual account the credit.
83
+ - Rescaling or reformatting the amounts. They go into the answer as they stand.
84
+ - Dropping the outer key of the answer shape, or listing an account with 0.0 that should be
85
+ omitted.
accounting/bank-reconciliation.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Bank reconciliation
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Bank reconciliation
8
+
9
+ For tasks that compare a bank statement with the company's own cash ledger and ask for the true
10
+ cash balance and the differences.
11
+
12
+ <!-- tier: 1 -->
13
+ ## Rule
14
+
15
+ **The task's own files and stated rules always win over this page; use this page only for what
16
+ the task leaves open.**
17
+
18
+ 1. **Two records describe the same money.** The bank statement is the bank's record; the cash
19
+ ledger is the company's. They differ only for a few reasons, and each difference belongs to
20
+ exactly one class.
21
+ 2. **Outstanding item:** correctly in the ledger, not yet on the statement (a payment or deposit
22
+ the bank has not processed). It adjusts the **bank** side.
23
+ 3. **Bank-only item:** on the statement, missing from the ledger (a fee, interest). The bank
24
+ balance already contains it. It adjusts the **ledger** side.
25
+ 4. **Book error:** a ledger entry that is wrong. A *transposition* has two neighbouring digits
26
+ swapped compared with the bank's amount; the difference is always divisible by 9. A
27
+ *duplicate* is one item entered twice; the later entry is the faulty one. An erroneous entry
28
+ is still matched to its bank line; it is an error, not an outstanding or bank-only item.
29
+ 5. **The adjusted balance is reached from both sides and must agree:**
30
+ bank closing + outstanding items (with their signs) = ledger closing + bank-only items (with
31
+ their signs) + corrections of book errors.
32
+ 6. **Signs:** money in is positive, money out negative. An outstanding payment lowers the bank
33
+ side; an outstanding deposit raises it.
34
+
35
+ <!-- tier: 2 -->
36
+ ## Procedure
37
+
38
+ 1. Read both files and the opening and closing balances. Note the sign convention.
39
+ 2. Match each bank line to a ledger line by what it is (the counterparty and reference in the
40
+ description) and its amount. Do not match on dates: the bank usually books a day or more
41
+ later.
42
+ 3. For a bank line and a ledger line with the same description but different amounts, test for
43
+ a transposition: same digits, two neighbours swapped. If so, it is a book error and the pair
44
+ is matched.
45
+ 4. Two ledger lines for one bank line with the same description and amount: the later ledger
46
+ entry is a duplicate.
47
+ 5. Ledger lines left unmatched: outstanding items. Bank lines left unmatched: bank-only items.
48
+ 6. Compute the adjusted balance from the bank side. Compute it again from the ledger side: add
49
+ the bank-only items, replace each transposed amount by the bank's amount, remove each
50
+ duplicate. Both results must be equal. If they are not, a line is misclassified: go back to
51
+ step 2.
52
+ 7. Report identifiers in the lists the request names: ledger ids for outstanding items and book
53
+ errors, statement references for bank-only items. Empty lists where there are none.
54
+
55
+ <!-- tier: 3 -->
56
+ ## Worked example
57
+
58
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
59
+ expected result from this example.
60
+
61
+ Invented month. Bank closing 4420.00. Ledger closing 4240.00.
62
+
63
+ | Finding | Class | Effect |
64
+ |---|---|---|
65
+ | Ledger has a supplier payment of -300.00 that is not on the statement | outstanding | bank side -300.00 |
66
+ | Statement has a bank fee of -30.00 that is not in the ledger | bank-only | ledger side -30.00 |
67
+ | A customer receipt is 450.00 at the bank and 540.00 in the ledger | transposition (difference 90 = 9 x 10) | ledger side -90.00 |
68
+
69
+ Bank side: 4420.00 - 300.00 = 4120.00.
70
+ Ledger side: 4240.00 - 30.00 - 90.00 = 4120.00.
71
+ Both agree: the adjusted cash balance is 4120.00.
72
+
73
+ The receipt appears only under book errors. It is not outstanding (the bank has it) and not
74
+ bank-only (the ledger has it, with a wrong amount).
75
+
76
+ <!-- tier: 2 -->
77
+ ## Common mistakes
78
+
79
+ - Applying a bank fee to the bank balance. The bank already deducted it; it corrects the ledger.
80
+ - Subtracting every outstanding item. Outstanding deposits are added, outstanding payments
81
+ subtracted: use the signed amounts.
82
+ - Listing one item in two classes (a transposed entry also as outstanding or bank-only).
83
+ - Matching by date and so calling an item outstanding that the bank booked two days later.
84
+ - Missing a small transposition in the cents (a difference of 0.09, 0.90 or 1.80 is still
85
+ divisible by 9).
86
+ - Reporting the earlier entry of a duplicate pair instead of the later.
87
+ - Not computing the second side. The two-sided check is what catches a wrong class.
accounting/consolidation.md ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Group consolidation
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Group consolidation
8
+
9
+ For tasks that give the trial balances of a parent and its subsidiaries and ask for the
10
+ consolidated trial balance, the group result and goods in transit.
11
+
12
+ <!-- tier: 1 -->
13
+ ## Rule
14
+
15
+ **The task's own files and stated rules always win over this page; use this page only for what
16
+ the task leaves open.**
17
+
18
+ 1. **A group reports as if it were one company.** Everything the group companies owe to, own of,
19
+ sell to or buy from each other is removed (eliminated). What remains is the group's dealings
20
+ with the outside world.
21
+ 2. **Start by adding up:** consolidated balance of an account = the sum of that account's net
22
+ balance (debit minus credit) in every entity.
23
+ 3. **Eliminate only what the request lists**, pair against pair: the parent's investment against
24
+ the subsidiaries' share capital; intercompany receivables against payables; intercompany
25
+ sales against purchases. Other accounts, such as each company's retained earnings, simply add
26
+ up.
27
+ 4. **An eliminated pair must be equal before it is removed.** If the seller has recorded more
28
+ intercompany sales than the buyer has recorded purchases, goods are in transit. The buyer
29
+ first records the missing purchase as the request prescribes; the difference is reported.
30
+ 5. **After elimination the intercompany accounts are zero** and do not appear in the result.
31
+ 6. **The consolidated trial balance sums to zero.**
32
+ 7. **Group result** = minus the sum of the consolidated income and expense accounts (income is a
33
+ credit, so a profit comes out positive). Compute it after the in-transit entry and the
34
+ eliminations.
35
+
36
+ <!-- tier: 2 -->
37
+ ## Procedure
38
+
39
+ 1. Read the group file: who is parent, who is subsidiary, who sells to whom.
40
+ 2. Read each trial balance into net balances (debit minus credit). Check each sums to zero.
41
+ 3. For each seller and buyer pair the request names: compare the seller's intercompany sales
42
+ with the buyer's intercompany purchases. If sales are larger, the difference is in transit:
43
+ book it in the buyer (debit intercompany purchases, credit intercompany payable) and note
44
+ from, to and amount.
45
+ 4. Add the entities account by account.
46
+ 5. Check the pairs now cancel: receivables + payables = 0, sales + purchases = 0, investment +
47
+ share capital of the subsidiaries = 0. Then set those accounts to zero. If a pair does not
48
+ cancel, stop and find out why; do not force it.
49
+ 6. Remove zero accounts. Check the total is 0.00.
50
+ 7. Group result = minus the sum of the accounts in the income-statement range the request names.
51
+ 8. Write the answer; the in-transit list is empty only if every pair agreed in step 3.
52
+
53
+ <!-- tier: 3 -->
54
+ ## Worked example
55
+
56
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
57
+ expected result from this example.
58
+
59
+ Invented group, net balances (credits negative).
60
+
61
+ | Account | Parent | Sub |
62
+ |---|---|---|
63
+ | Bank | 400 | 180 |
64
+ | Investment in sub | 500 | |
65
+ | Intercompany receivable | 120 | |
66
+ | Intercompany payable | | -80 |
67
+ | Share capital | -600 | -500 |
68
+ | Retained earnings | -200 | -60 |
69
+ | External sales | -937 | -300 |
70
+ | Intercompany sales | -120 | |
71
+ | Intercompany purchases | | 80 |
72
+ | Other costs | 837 | 680 |
73
+
74
+ Each column sums to zero. The parent sold 120 to the sub; the sub recorded 80: 40 is in transit
75
+ from parent to sub. Book in the sub: intercompany purchases +40 (now 120), intercompany payable
76
+ -40 (now -120). The sub still sums to zero.
77
+
78
+ Add up and eliminate: investment 500 against the sub's share capital -500; receivable 120
79
+ against payable -120; sales -120 against purchases 120.
80
+
81
+ Consolidated: Bank 580; Share capital -600 (the parent's); Retained earnings -260; External
82
+ sales -1237; Other costs 1517. Sum: 580 - 600 - 260 - 1237 + 1517 = 0.
83
+ Group result = -(-1237 + 1517) = -280: a loss of 280.
84
+
85
+ <!-- tier: 2 -->
86
+ ## Common mistakes
87
+
88
+ - Eliminating the intercompany balances without first booking the goods in transit, so the pairs
89
+ do not cancel and the trial balance does not sum to zero.
90
+ - Dropping the subsidiaries' retained earnings. Only the listed pairs are eliminated.
91
+ - Removing all share capital. Only the subsidiaries' share capital goes against the investment;
92
+ the parent's stays.
93
+ - Wrong sign of the result: income accounts are credits, so a profit is the negative of their
94
+ sum with the costs.
accounting/depreciation.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Depreciation for the period
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Depreciation for the period
8
+
9
+ For period-end tasks that give a list of fixed assets and ask for the period's depreciation
10
+ entry.
11
+
12
+ <!-- tier: 1 -->
13
+ ## Rule
14
+
15
+ **The task's own files and stated rules always win over this page; use this page only for what
16
+ the task leaves open.**
17
+
18
+ 1. If the request states the method, the first month, the rounding and the accounts, apply that
19
+ as written. The points below only explain it.
20
+ 2. **Straight-line depreciation** charges the same amount in every month of the asset's useful
21
+ life: monthly amount = cost / life in months.
22
+ 3. **The life has a first and a last month.** The request says which month is the first (often
23
+ the month of acquisition, counted as a full month). The last is the first plus the life
24
+ minus one. Outside that span nothing is charged: not before the first month, not after the
25
+ last.
26
+ 4. **Charge only what the request asks for**, usually this period's one month, not the
27
+ accumulated amount since acquisition.
28
+ 5. **One entry:** debit the depreciation expense account, credit the accumulated depreciation
29
+ account, both named in the request, for the sum over all assets that are charged.
30
+ 6. Only what the task gives inputs for: a task with only assets has only depreciation.
31
+
32
+ <!-- tier: 2 -->
33
+ ## Procedure
34
+
35
+ 1. Note the period's month, the accounts and the rounding from the request.
36
+ 2. For each asset read: acquisition date, cost, life in months.
37
+ 3. Month number of the period within the life = (period year - first year) x 12 + (period month
38
+ - first month) + 1, where the first month is the one the request names.
39
+ 4. If the month number is between 1 and the life (both included): the asset is charged its
40
+ monthly amount, rounded as the request says. Otherwise it is charged nothing.
41
+ 5. Add the charges of all assets in a script. Debit the expense, credit accumulated
42
+ depreciation.
43
+ 6. Check: the two lines are equal and opposite; assets with a month number of zero or less, or
44
+ above their life, contributed nothing; the answer has the request's shape and outer key.
45
+
46
+ <!-- tier: 3 -->
47
+ ## Worked example
48
+
49
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
50
+ expected result from this example.
51
+
52
+ The period is April of year 5. The request says: depreciation starts in the month of
53
+ acquisition, monthly amount rounded half up.
54
+
55
+ | Asset | Acquired | Cost | Life | Month number in April of year 5 | Charge |
56
+ |---|---|---|---|---|---|
57
+ | Machine | November, year 4 | 9500.00 | 36 | 6 | 263.89 |
58
+ | Van | March, year 2 | 21600.00 | 36 | 38 | none: life used up in February of year 5 |
59
+ | Press | April, year 5 | 4800.00 | 48 | 1 | 100.00 |
60
+ | Printer | May, year 5 | 1200.00 | 24 | 0 | none: not acquired yet |
61
+
62
+ Machine: 9500.00 / 36 = 263.888..., rounded 263.89.
63
+ Total charge: 263.89 + 100.00 = 363.89.
64
+ Net adjustment: Depreciation expense +363.89; Accumulated depreciation -363.89.
65
+
66
+ <!-- tier: 2 -->
67
+ ## Common mistakes
68
+
69
+ - Charging an asset whose life is already used up.
70
+ - Charging an asset acquired after the period.
71
+ - Skipping an asset acquired in the period's own month when the request counts that month in
72
+ full.
73
+ - Charging all months since acquisition instead of this period's month.
74
+ - Counting the month number one too high or one too low; test it on the acquisition month,
75
+ which must give 1 when the request starts there.
76
+ - Rounding the total instead of each asset's monthly amount, when the request rounds per asset.
77
+ - Reversed signs: the expense is the debit (positive).
78
+ - Adding accrued or prepaid entries the task gave no inputs for.
79
+ - Dropping the outer key of the answer shape.
accounting/index.md ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Bookkeeping
5
+ ---
6
+ # Bookkeeping
7
+
8
+ Bookkeeping and period-end work on ledgers, journals and invoices. Each page: rule, procedure, worked example, common mistakes.
9
+
10
+ - Reconcile a bank statement with a cash ledger; adjusted cash balance; outstanding items; bank fees; ledger errors: `/knowledge/accounting/bank-reconciliation.md`
11
+ - VAT return: VAT per invoice from a rate table, output and input VAT, VAT payable: `/knowledge/accounting/vat.md`
12
+ - Journal checked against source documents: transposition, missing line, duplicate, wrong account; corrected trial balance: `/knowledge/accounting/journal-errors.md`
13
+ - Closing a period from deliveries not yet invoiced: accrued costs: `/knowledge/accounting/accrued-costs.md`
14
+ - Closing a period from supplier invoices with a service period: prepaid costs: `/knowledge/accounting/prepaid-costs.md`
15
+ - Closing a period from a list of fixed assets: depreciation: `/knowledge/accounting/depreciation.md`
16
+ - Group accounts: parent and subsidiaries, intercompany eliminations, goods in transit, group result: `/knowledge/accounting/consolidation.md`
accounting/journal-errors.md ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Journal errors and the trial balance
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Journal errors and the trial balance
8
+
9
+ For tasks that give a journal, the source documents behind it and a chart of accounts, and ask
10
+ which entries are faulty and what the trial balance should be.
11
+
12
+ <!-- tier: 1 -->
13
+ ## Rule
14
+
15
+ **The task's own files and stated rules always win over this page; use this page only for what
16
+ the task leaves open.**
17
+
18
+ 1. **Double entry:** every transaction is posted as equal debits and credits. So all debits of a
19
+ journal equal all credits, and the net balances of all accounts sum to zero.
20
+ 2. **The source document is the truth.** It says the amount, the account to debit and the
21
+ account to credit. The journal is checked against it, not the other way round.
22
+ 3. **Each document is posted exactly once.**
23
+ 4. **Kinds of fault, each found by a different comparison:**
24
+ - *transposition*: a posted amount is the document's amount with two neighbouring digits
25
+ swapped (the difference is divisible by 9);
26
+ - *missing line*: only one side (debit or credit) was posted;
27
+ - *duplicate*: one document appears as two postings; the later entry is the faulty one;
28
+ - *wrong account*: a line went to an account other than the one the document names.
29
+ 5. **The corrected trial balance is what the documents say.** Net balance of an account = its
30
+ debits minus its credits; a credit balance is negative. Leave out accounts that net to zero
31
+ if the request says so.
32
+
33
+ <!-- tier: 2 -->
34
+ ## Procedure
35
+
36
+ 1. Read the documents: for each, amount, debit account, credit account.
37
+ 2. Read the journal and group its lines by the document they refer to, and within that by entry.
38
+ 3. For each document, compare in this order:
39
+ - how many entries refer to it (two entries: the later one is a duplicate);
40
+ - whether the entry has both a debit line and a credit line (one side only: missing line);
41
+ - whether the accounts are the document's accounts (otherwise: wrong account);
42
+ - whether each amount equals the document's amount (digits swapped: transposition).
43
+ 4. Do every comparison in a script, for every document. Do not stop at the first kind you find;
44
+ a journal can hold several kinds.
45
+ 5. Report each faulty entry once, with its kind.
46
+ 6. Build the corrected trial balance **from the documents**: for each document add its amount to
47
+ the debit account and subtract it from the credit account.
48
+ 7. Check: the balances sum to exactly zero; every reported entry id exists in the journal.
49
+
50
+ <!-- tier: 3 -->
51
+ ## Worked example
52
+
53
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
54
+ expected result from this example.
55
+
56
+ Invented documents and journal.
57
+
58
+ | Document | Amount | Debit | Credit |
59
+ |---|---|---|---|
60
+ | D1 | 250.00 | Rent | Bank |
61
+ | D2 | 480.00 | Bank | Sales |
62
+ | D3 | 75.00 | Supplies | Payables |
63
+ | D4 | 120.00 | Bank | Receivables |
64
+
65
+ | Entry | Lines | Document |
66
+ |---|---|---|
67
+ | E1 | Rent debit 250.00; Bank credit 250.00 | D1 |
68
+ | E2 | Bank debit 840.00; Sales credit 840.00 | D2 |
69
+ | E3 | Supplies debit 75.00 | D3 |
70
+ | E4 | Bank debit 120.00; Receivables credit 120.00 | D4 |
71
+ | E5 | Bank debit 120.00; Receivables credit 120.00 | D4 |
72
+
73
+ Findings: E2 transposition (840 against 480; difference 360 = 9 x 40). E3 missing line (no
74
+ credit). E5 duplicate (D4 posted twice; E5 is the later).
75
+
76
+ Corrected trial balance from the documents:
77
+ Bank = -250.00 + 480.00 + 120.00 = 350.00; Rent 250.00; Supplies 75.00; Sales -480.00;
78
+ Payables -75.00; Receivables -120.00. Sum: 350 + 250 + 75 - 480 - 75 - 120 = 0.
79
+
80
+ Note that E2 balances in itself (debit equals credit). A balanced journal can still be wrong;
81
+ only the comparison with the document shows it.
82
+
83
+ <!-- tier: 2 -->
84
+ ## Common mistakes
85
+
86
+ - Finding the duplicates and stopping, so that transpositions, missing lines and wrong accounts
87
+ are never looked for.
88
+ - Comparing only totals. Compare each entry with its document.
89
+ - Building the trial balance from the faulty journal instead of from the documents.
90
+ - Reporting the first entry of a duplicate pair instead of the later.
91
+ - Writing a credit balance as a positive number.
92
+ - Adding an extra field (a suggested correction) that the answer shape does not have.
accounting/prepaid-costs.md ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Prepaid costs at period end
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Prepaid costs at period end
8
+
9
+ For period-end tasks that give supplier invoices with a service period and ask which part is
10
+ prepaid.
11
+
12
+ <!-- tier: 1 -->
13
+ ## Rule
14
+
15
+ **The task's own files and stated rules always win over this page; use this page only for what
16
+ the task leaves open.**
17
+
18
+ 1. If the request states how the amount is spread, how it is rounded and which accounts to use,
19
+ apply that as written. The points below only explain it.
20
+ 2. **A prepaid cost** is the part of an already booked expense whose service period lies after
21
+ the period end. It is moved out of the expense: debit the prepaid account, credit the expense
22
+ account of that invoice.
23
+ 3. **An invoice that is not booked yet has nothing to move.** Requests usually state that an invoice
24
+ dated later than the closing date is still unbooked.
25
+ 4. **Spread over the invoice's own service period**, in the unit the request names (usually
26
+ whole calendar months): amount per month = amount / number of months of that invoice.
27
+ 5. **Count the months after the period end**, all of them, also those in a later year.
28
+ 6. **Each invoice credits its own expense account.** Only what the task gives inputs for: a task
29
+ with only such invoices has only prepaid entries.
30
+ 7. **The entries balance:** debits positive, credits negative, sum zero.
31
+
32
+ <!-- tier: 2 -->
33
+ ## Procedure
34
+
35
+ 1. Note the period end, the prepaid account and the rounding from the request.
36
+ 2. For each invoice read: invoice date, amount, expense account, service start, service end.
37
+ 3. Skip invoices the request says are not booked (dated after the period end).
38
+ 4. Months in the service period = (end year - start year) x 12 + (end month - start month) + 1.
39
+ 5. Monthly amount = amount / months, rounded as the request says.
40
+ 6. Months after = the months of the service period later than the period's month. A service
41
+ period ending on or before the period end has none.
42
+ 7. Prepaid part = monthly amount x months after. Debit the prepaid account, credit the
43
+ invoice's expense account.
44
+ 8. Sum per account in a script. Check: the total is exactly zero; every invoice was either
45
+ skipped for a stated reason or handled; the answer has the request's shape and outer key.
46
+
47
+ <!-- tier: 3 -->
48
+ ## Worked example
49
+
50
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
51
+ expected result from this example.
52
+
53
+ Period ends on the last day of April of year 1. The request says: spread evenly per month,
54
+ monthly amount rounded half up.
55
+
56
+ | Invoice | Dated | Amount | Expense | Service period | Months | After April | Prepaid |
57
+ |---|---|---|---|---|---|---|---|
58
+ | A | 2 March | 3600.00 | Insurance | March to August, year 1 | 6 | 4 | 2400.00 |
59
+ | B | 5 February | 700.00 | Rent | February to April, year 1 | 3 | 0 | 0.00 |
60
+ | C | 4 May | 900.00 | Licences | May to July, year 1 | - | - | skipped: not booked yet |
61
+ | D | 10 January | 1000.00 | Licences | November of year 0 to January of year 2 | 15 | 9 | 600.03 |
62
+
63
+ D: 1000.00 / 15 = 66.666..., rounded 66.67 a month; after April of year 1 come May to December
64
+ (8 months) and January of year 2 (1 month): 9 x 66.67 = 600.03.
65
+
66
+ Net adjustment: Prepaid costs +3000.03; Insurance -2400.00; Licences -600.03. Sum zero.
67
+
68
+ <!-- tier: 2 -->
69
+ ## Common mistakes
70
+
71
+ - Dividing by 12, or by another fixed number, instead of by the months of the invoice's own
72
+ service period.
73
+ - Counting only the months of the next year and forgetting those left in this year, or the
74
+ reverse.
75
+ - Counting the months before the period end.
76
+ - Moving an invoice that is dated after the period end.
77
+ - Multiplying the unrounded monthly amount when the request rounds the monthly amount first (or
78
+ the reverse). Follow the request's order.
79
+ - Crediting one expense account for all invoices.
80
+ - Wrong signs: the prepaid account is the debit (positive).
81
+ - Adding accrued or depreciation entries the task gave no inputs for.
82
+ - Dropping the outer key of the answer shape.
accounting/vat.md ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: VAT return from invoices
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # VAT return from invoices
8
+
9
+ For tasks that give sales and purchase invoices and a rate table and ask for the VAT per invoice
10
+ and the return totals.
11
+
12
+ <!-- tier: 1 -->
13
+ ## Rule
14
+
15
+ **The task's own files and stated rules always win over this page; use this page only for what
16
+ the task leaves open.**
17
+
18
+ 1. **The request states the method: use it word for word.** Which rate applies, how net and
19
+ gross amounts are treated, how to round, and what the totals are. The points below only
20
+ explain the usual meaning of those sentences.
21
+ 2. **The rate comes from the task's rate table**: the row for the invoice's own category whose
22
+ validity range contains the invoice date. Read the request for whether a range's last day
23
+ is included.
24
+ 3. **A rate given in percent is divided by 100 once** before it is used as a factor.
25
+ 4. **Amounts are used as they stand in the file.** Never rescale them.
26
+ 5. **Net basis:** VAT = net x rate. **Gross basis:** net = gross / (1 + rate), VAT = gross -
27
+ net.
28
+ 6. **Output VAT** is the VAT on sales; **input VAT** is the VAT on purchases. **Payable =
29
+ output - input**, negative when input is larger.
30
+ 7. **Every invoice gets a line**, also one whose VAT is 0.00.
31
+ 8. If an invoice lacks what the method needs, see
32
+ `/knowledge/agent-workflow/missing-information.md`.
33
+
34
+ <!-- tier: 2 -->
35
+ ## Procedure
36
+
37
+ 1. Read the request's method sentence and the answer shape. Read the rate table and the
38
+ invoices completely.
39
+ 2. Write one script file that, for each invoice: finds the table row by category and date;
40
+ turns the percent into a factor; computes the VAT by the invoice's basis; rounds as the
41
+ request says, with exact decimals.
42
+ 3. In the same script: sum the VAT of sales into output VAT and of purchases into input VAT;
43
+ payable = output - input; print every line and the three totals.
44
+ 4. Estimate one line by hand to catch a slip of rate or scale. If the script's line is a
45
+ hundred times off, the slip is in the script.
46
+ 5. Let the script write the answer in the request's shape: a list of lines if the shape shows a
47
+ list, numbers where it shows numbers.
48
+ 6. Check once: number of lines = number of invoices; output + input = sum of all lines; the
49
+ sign of payable. Then finish.
50
+
51
+ <!-- tier: 3 -->
52
+ ## Worked example
53
+
54
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
55
+ expected result from this example.
56
+
57
+ Rate table (percent): `general` 20 throughout; `print` 10 up to and including 30 June and 5
58
+ from 1 July; `export` 0. The request says: half up to 0.01; gross means net = gross / (1 +
59
+ rate).
60
+
61
+ | Invoice | Date | Direction | Category | Amount | Basis | Rate | VAT |
62
+ |---|---|---|---|---|---|---|---|
63
+ | A | 30 June | sale | print | 300.00 | net | 10 | 30.00 |
64
+ | B | 1 July | sale | print | 300.00 | net | 5 | 15.00 |
65
+ | C | 3 July | purchase | general | 600.00 | gross | 20 | 100.00 |
66
+ | D | 5 July | sale | export | 950.00 | net | 0 | 0.00 |
67
+ | E | 9 July | purchase | print | 210.00 | gross | 5 | 10.00 |
68
+
69
+ A and B are one day apart; the rate changed between them. C: net = 600.00 / 1.20 = 500.00, VAT
70
+ = 100.00 (not 600.00 x 0.20). E: net = 210.00 / 1.05 = 200.00, VAT = 10.00.
71
+
72
+ Output VAT = 30.00 + 15.00 + 0.00 = 45.00. Input VAT = 100.00 + 10.00 = 110.00.
73
+ Payable = 45.00 - 110.00 = -65.00.
74
+
75
+ <!-- tier: 2 -->
76
+ ## Common mistakes
77
+
78
+ - Replacing the request's stated method by another, or debating it at length.
79
+ - Using the wrong side of a rate change on its boundary dates.
80
+ - Dividing the percent by 100 twice, or deciding the amounts are in another unit.
81
+ - Computing VAT on a gross amount as gross x rate.
82
+ - Counting a purchase in output VAT, or leaving an invoice out of a total.
83
+ - Writing payable as a positive number when input VAT is larger.
84
+ - Writing the lines as an object keyed by invoice where the shape shows a list.
agent-workflow/answer-file.md ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Writing a JSON answer file with a script
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Writing a JSON answer file with a script
8
+
9
+ For tasks that ask for `answer.json` or any other structured answer file.
10
+
11
+ <!-- tier: 1 -->
12
+ ## Rule
13
+
14
+ **The task's own files and stated rules always win over this page; use this page only for what
15
+ the task leaves open.**
16
+
17
+ 1. **The shape in the request is exact.** Same key names, same nesting, same value types. Add no
18
+ key, drop no key, rename no key.
19
+ 2. **A label must be one the request lists**, spelled as the request spells it.
20
+ 3. **"Nothing" has three spellings that are not interchangeable:** an empty list `[]`, the JSON
21
+ value `null` without quotes, or a word the request gives. Use the one the request states for
22
+ that field.
23
+ 4. **The file holds the answer only:** no explanation, no reasoning, no markup, no code fence.
24
+ 5. **Let a script write the file with a JSON library.** Then it is always valid JSON.
25
+ 6. **A program goes into a script file, not into a quoted command line.**
26
+
27
+ <!-- tier: 2 -->
28
+ ## Procedure
29
+
30
+ 1. Copy the example shape from the request into your notes. Mark for each field: its type
31
+ (number, text, list, object, null allowed?) and its allowed values.
32
+ 2. Write the program to a file with the file-writing tool, as plain text.
33
+ 3. In the program: read the inputs, compute, **print** the intermediate values, build the answer
34
+ as a dictionary in the request's shape, write it with the JSON library.
35
+ 4. Run it with one short command. If it fails, read the last line of the error, fix that line in
36
+ the file, run again. If it failed three times, make it smaller: one result at a time.
37
+ 5. Money as a JSON number: convert the exact decimal at the very end. Money as text with two
38
+ decimals: format it with two decimals. Follow the request.
39
+ 6. Read the answer file back with a one-line parse. Compare its keys with the request's shape.
40
+ 7. Delete the program file.
41
+
42
+ <!-- tier: 3 -->
43
+ ## Worked example
44
+
45
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
46
+ expected result from this example.
47
+
48
+ Invented request: write `answer.json` as
49
+
50
+ ```json
51
+ {"status": "ok", "late_items": ["X0"], "fee": 0.0, "waiver": null}
52
+ ```
53
+
54
+ with `status` one of `ok` or `blocked`, `late_items` empty if none, `waiver` `null` if none.
55
+
56
+ Program file `calc.py`:
57
+
58
+ ```python
59
+ import csv
60
+ import json
61
+ from decimal import ROUND_HALF_UP, Decimal
62
+
63
+ rows = list(csv.DictReader(open("items.csv")))
64
+ late = [r["id"] for r in rows if r["state"] == "late"]
65
+ fee = sum(Decimal(r["fee"]) for r in rows if r["state"] == "late")
66
+ fee = fee.quantize(Decimal("0.01"), ROUND_HALF_UP)
67
+ print("rows", len(rows), "late", late, "fee", fee)
68
+ answer = {"status": "ok", "late_items": late, "fee": float(fee), "waiver": None}
69
+ json.dump(answer, open("answer.json", "w"), indent=1)
70
+ ```
71
+
72
+ Run `python3 calc.py`, then check:
73
+ `python3 -c "import json; print(json.load(open('answer.json')))"`.
74
+
75
+ The library writes Python `None` as JSON `null` and an empty list as `[]`.
76
+
77
+ Wrong versions of the same answer and why they fail:
78
+
79
+ | Written | Problem |
80
+ |---|---|
81
+ | `"late_items": null` | the request said an empty list |
82
+ | `"waiver": "null"` | a four-letter text, not the JSON value |
83
+ | `"fee": "12.50"` | text where the shape shows a number |
84
+ | `"status": "OK"` | not spelled as the request lists it |
85
+ | `{'status': 'ok'}` | single quotes are not JSON |
86
+ | an added `"note"` key | the shape has no such key |
87
+ | `{"late": [...]}` | a renamed key |
88
+ | a bare list where the shape shows an object with a list inside | the wrapper key is missing |
89
+
90
+ <!-- tier: 2 -->
91
+ ## Common mistakes
92
+
93
+ - Writing the file with a shell echo and losing or mixing the quotes.
94
+ - Dropping the outer wrapper key and writing only its content.
95
+ - Returning an object keyed by id where the shape shows a list of objects, or the reverse.
96
+ - Giving a date where an amount was asked, or an amount where a date was asked.
97
+ - Leaving out a line for an item the request said to list ("one line per invoice").
98
+ - Reporting totals that are not the sum of the lines written in the same file.
99
+ - Writing a correct file, then rewriting it again and again. Parse it once; if it matches the
100
+ shape, stop.
101
+ - Believing a write failed because the tool's confirmation looked unusual. Read the file back
102
+ instead of writing it again.
agent-workflow/index.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: How to work a task
5
+ ---
6
+ # How to work a task
7
+
8
+ Working method for every task, whatever the subject. Each page: rule, procedure, worked example, common mistakes.
9
+
10
+ - For every task: explore, read the request fully, use tools, compute with a script, check, stop: `/knowledge/agent-workflow/workflow.md`
11
+ - When the task asks for `answer.json` or another JSON answer file, or you need to run a script: `/knowledge/agent-workflow/answer-file.md`
12
+ - When the task says "do not guess" or "may be incomplete", or something you need is missing: `/knowledge/agent-workflow/missing-information.md`
agent-workflow/missing-information.md ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: When information is missing - do not guess
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # When information is missing: do not guess
8
+
9
+ For tasks that say the data "may be incomplete", say "do not guess", ask you to name what is
10
+ missing, or let you answer with the fact you need.
11
+
12
+ <!-- tier: 1 -->
13
+ ## Rule
14
+
15
+ **The task's own files and stated rules always win over this page; use this page only for what
16
+ the task leaves open.**
17
+
18
+ 1. **A conclusion needs every fact its rule uses.** If one of those facts is absent, the honest
19
+ result is "cannot be determined", together with the name of what is missing.
20
+ 2. **Missing is not zero, not "no", and not the usual value.** A blank category is not the
21
+ standard category. An absent document is not proof that nothing happened.
22
+ 3. **Abstain only about what truly depends on the gap.** Everything that can be determined
23
+ without the missing fact is still computed and reported.
24
+ 4. **Anything built on an unknown is unknown.** A total over lines of which one is unknown is
25
+ unknown; write it as the request says (usually `null`), not as the sum of the known lines.
26
+ 5. **Name the missing thing in the task's own words**: the record it belongs to and the field or
27
+ document type, chosen from the names the request offers.
28
+ 6. **Do not abstain when nothing is missing.** If every needed fact is present, decide.
29
+
30
+ <!-- tier: 2 -->
31
+ ## Procedure
32
+
33
+ 1. Write down the rule you must apply and list the facts it needs (inputs of the rule).
34
+ 2. Tick each fact off against the task's files. A fact can be present under a slightly different
35
+ wording; look before you call it missing.
36
+ 3. For each fact not found, decide whether the outcome really depends on it: would two different
37
+ values of that fact give two different answers? If not, it is not decisive.
38
+ 4. If nothing decisive is missing: solve the task normally.
39
+ 5. If something decisive is missing:
40
+ - set the status the request prescribes for an incomplete case;
41
+ - list each gap once, with the record and field names the request prescribes;
42
+ - give the dependent results as the request prescribes for unknown values;
43
+ - still compute every independent line and report it.
44
+ 6. In a system where you ask a person (a ticket, a request): ask for exactly the missing field,
45
+ say its name plainly in the message, and change nothing else while you wait.
46
+
47
+ <!-- tier: 3 -->
48
+ ## Worked example
49
+
50
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
51
+ expected result from this example.
52
+
53
+ Invented task: compute a handling fee per parcel from a fee table by parcel class, and the total.
54
+ "If a parcel lacks what the table needs, give its fee as `null`, list it under `missing`, set
55
+ `status` to `incomplete` and the total to `null`."
56
+
57
+ Parcels: P1 class `small`, P2 class blank, P3 class `bulky`.
58
+
59
+ 1. Rule inputs: the parcel's class and the table's fee for that class.
60
+ 2. P1 and P3 have a class. P2 does not. Would P2's fee change with its class? Yes: decisive.
61
+ 3. Result:
62
+
63
+ ```json
64
+ {
65
+ "status": "incomplete",
66
+ "missing": [{"record": "P2", "field": "class"}],
67
+ "lines": [
68
+ {"parcel": "P1", "fee": 4.5},
69
+ {"parcel": "P2", "fee": null},
70
+ {"parcel": "P3", "fee": 12.0}
71
+ ],
72
+ "total": null
73
+ }
74
+ ```
75
+
76
+ P1 and P3 are computed. P2 is `null`. The total is `null`, not 16.5: the sum of the known lines would hide
77
+ an unknown one.
78
+
79
+ A second situation: a case file should decide whether goods arrived late, but the document that
80
+ records the arrival date is not in the file. Do not reason "no record, so probably on time". The
81
+ decisive document is missing: name its type, and leave the conclusions that depend on it open.
82
+
83
+ <!-- tier: 2 -->
84
+ ## Common mistakes
85
+
86
+ - Filling a blank with the most common value and computing as if it were given.
87
+ - Setting the status to incomplete but still reporting totals as numbers.
88
+ - Reporting nothing at all, although most lines could be determined.
89
+ - Naming the gap in your own words instead of the record and field names the request offers.
90
+ - Listing as missing something that is present, or that does not affect the outcome.
91
+ - Abstaining as a safe default: when every needed fact is there, an abstention is a wrong answer.
92
+ - Deciding the outcome although the one fact that separates two outcomes is not in the case.
agent-workflow/workflow.md ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: How to work any task with tools
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # How to work any task with tools
8
+
9
+ For every task, whatever the subject.
10
+
11
+ <!-- tier: 1 -->
12
+ ## Rule
13
+
14
+ **The task's own files and stated rules always win over this page; use this page only for what
15
+ the task leaves open.**
16
+
17
+ 1. **Only a real tool call acts.** Text that looks like a tool call inside your reasoning runs
18
+ nothing. If no tool result came back, you did not call a tool: call it now.
19
+ 2. **The request is the specification.** It fixes the deliverable: file name, place, field names,
20
+ value formats, and what you must not do. The task's files are the only source of rules.
21
+ 3. **Read every input the request names before you conclude anything.**
22
+ 4. **Compute with a script, never in your head.** Dates, sums, percentages and rounding go through
23
+ a short script. If your head and a correct script disagree, the script is right.
24
+ 5. **Never send the same failing call twice.** Change what the error message points at.
25
+ 6. **A command that changes state runs once, alone, and is then checked.**
26
+ 7. **Never search for the answer** in the repository history, hidden directories or elsewhere on
27
+ the machine. It voids the result and the answer is not there. Never clean or reset the
28
+ repository: that deletes your own answer.
29
+ 8. **The deliverable must exist, in the right place and shape.** Write a first version early.
30
+ 9. **Check once, then stop.**
31
+
32
+ <!-- tier: 2 -->
33
+ ## Procedure
34
+
35
+ 1. Read the whole request. Note the goal, the deliverable, the inputs, and every "do not".
36
+ 2. List the working directory once. Stay in it: relative paths in the request start there, and
37
+ "repository root" means this directory.
38
+ 3. Read every input file the request names, reference tables and policies included. If you read
39
+ several files in one turn, match each result to its file by its content; results can come back
40
+ in another order.
41
+ 4. If the request states a rule or method, apply it as written. Use a knowledge page only for
42
+ what the request leaves open.
43
+ 5. Put the calculation in a script file, run it, and read its output.
44
+ 6. Write the deliverable exactly as the request shapes it. Use the tool's exact parameter names;
45
+ when an error names the right parameter, use it in the next call.
46
+ 7. Re-read the request. Check the deliverable against it: exists, parses, same keys, allowed
47
+ labels, numbers from the script, inputs untouched.
48
+ 8. Delete your helper files. Say in one or two sentences what you delivered. End.
49
+
50
+ Budget: if half of your steps are gone and nothing is written, write your best answer now and
51
+ improve it afterwards.
52
+
53
+ You are in a loop when the last two calls or the last two errors were the same, or when you
54
+ re-check an answer that already passed. Then: read the error word by word and fix exactly that;
55
+ or switch to the simplest method (write a file, run it); or, if the answer is written and
56
+ checked, end the task.
57
+
58
+ <!-- tier: 3 -->
59
+ ## Worked example
60
+
61
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
62
+ expected result from this example.
63
+
64
+ Invented task: "Report the total of `items.csv` in `result.json` as `{"total": 0.0}`. Do not
65
+ change the input."
66
+
67
+ 1. Read the request: deliverable `result.json` in the working directory, one key `total`, a
68
+ number.
69
+ 2. List the directory: `items.csv` is there. Read it: four rows with an `amount` column.
70
+ 3. Write `sum.py`: read the CSV, add the amounts as exact decimals, print the rows and the total,
71
+ write the JSON file with a JSON library.
72
+ 4. Run `python3 sum.py`. Output: 4 rows, total 61.40.
73
+ 5. Read `result.json` back: `{"total": 61.4}`. One key, a number, parses.
74
+ 6. Delete `sum.py`. Final message: "Wrote result.json with the total of the four rows." End.
75
+
76
+ <!-- tier: 2 -->
77
+ ## Common mistakes
78
+
79
+ - Arguing at length between a page and the task. The task wins; decide and move on.
80
+ - Writing the tool call as text in the reasoning, so nothing runs and the task ends empty.
81
+ - Writing the answer in another directory than the one the task started in.
82
+ - Resending a broken command unchanged, three, five, ten times.
83
+ - Putting a long program inside one quoted command line; the quoting breaks. Use a script file.
84
+ - Doing sums or date counts mentally and being off by a digit, a day or a month.
calculation/dates.md ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Dates - days, business days, months, years, rolling
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Dates: days, business days, months, years, rolling
8
+
9
+ For any day count or deadline. The task's own rule table and holiday list decide.
10
+
11
+ <!-- tier: 1 -->
12
+ ## Rule
13
+
14
+ **The task's own files and stated rules always win over this page; use this page only for what
15
+ the task leaves open.**
16
+
17
+ 1. **Always compute dates in a script.** Mental calendar arithmetic and remembered weekdays are
18
+ unreliable.
19
+ 2. **Unless the task says otherwise, a period starts the day after its trigger.** "Within N days after X" ends on X + N; that
20
+ last day is still in time. It is never X - N.
21
+ 3. **Calendar days** count every day. **Business days** are what the task defines; usually
22
+ Monday to Friday except the holidays in the task's list.
23
+ 4. **N business days after X:** step forward a day at a time, count only business days, stop at
24
+ the N-th. The trigger day is not counted.
25
+ 5. **N months after X:** the same day number N months later, or the month's last day if it has no
26
+ such day. **N years after X:** same month and day, N years later; not N x 365 days.
27
+ 6. **Rolling:** a deadline falling on a non-business day is carried forward to the following business day, but only for
28
+ the kinds of deadline the task says roll. A date that is a fact (a payment, a delivery) never
29
+ rolls.
30
+ 7. **Days between** two dates = later minus earlier.
31
+ 8. **"Today"** is the date the task gives (case date, as-of date, period end), never the
32
+ machine's clock.
33
+ 9. **Write full dates with the year.** A period that passes December changes the year.
34
+
35
+ <!-- tier: 2 -->
36
+ ## Procedure
37
+
38
+ 1. Read from the task: the trigger date, the length of the period, its unit (days, business
39
+ days, months, years), and whether this kind of deadline rolls.
40
+ 2. Load the task's holiday list into a set of dates. Check what its columns are before parsing.
41
+ 3. Compute with the helper that fits the unit (see the example).
42
+ 4. Roll only if the task says so for this kind of deadline.
43
+ 5. Print the result with its weekday name. If it must be a business day, confirm that it is.
44
+ 6. For each new question start again from that question's own dates.
45
+
46
+ A notice period "counted from the first day of the following month": month 1 is the month after
47
+ the notice date; the period ends on the last day of month N.
48
+
49
+ <!-- tier: 3 -->
50
+ ## Worked example
51
+
52
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
53
+ expected result from this example.
54
+
55
+ ```python
56
+ import calendar
57
+ from datetime import date, timedelta
58
+ closed_days = {date(2031, 3, 10)}
59
+ def is_business(d):
60
+ return d not in closed_days and d.weekday() < 5
61
+ def add_business_days(d, n):
62
+ while n > 0:
63
+ d += timedelta(days=1)
64
+ if is_business(d):
65
+ n -= 1
66
+ return d
67
+ def roll(d):
68
+ while not is_business(d):
69
+ d += timedelta(days=1)
70
+ return d
71
+ def add_months(d, n):
72
+ m = d.month - 1 + n
73
+ y, m = d.year + m // 12, m % 12 + 1
74
+ return date(y, m, min(d.day, calendar.monthrange(y, m)[1]))
75
+ def end_of_month(y, m):
76
+ return date(y, m, calendar.monthrange(y, m)[1])
77
+ ```
78
+
79
+ - **5 business days after Thursday 2031-03-06:** Fri 7 (1), weekend skipped, Mon 10 skipped
80
+ (holiday), Tue 11 (2), Wed 12 (3), Thu 13 (4), Fri 14 (5). Answer 2031-03-14.
81
+ - **10 days after Wednesday 2031-10-08, rolling:** 2031-10-18, a Saturday; rolled to Monday
82
+ 2031-10-20.
83
+ - **1 month after 2031-01-31:** 2031-02-28.
84
+ - **3 years after 2031-04-12:** 2034-04-12.
85
+ - **Notice of 3 months given 2031-11-20, counted from the next month:** month 1 December 2031,
86
+ month 2 January 2032, month 3 February 2032; ends 2032-02-29 (a leap year, and a Sunday). If
87
+ the task says the end of a notice period does not roll, it stays.
88
+ - **Days late:** due 2031-06-02, paid 2031-06-16: 14 days.
89
+
90
+ <!-- tier: 2 -->
91
+ ## Common mistakes
92
+
93
+ - Counting the trigger day as day 1.
94
+ - Subtracting the period from the trigger instead of adding it.
95
+ - Treating "N days" as business days, or "N business days" as calendar days.
96
+ - Rolling a kind of deadline the task exempts, or rolling a date that is a fact.
97
+ - Not rolling a due date that the task does roll, and then counting days late from the wrong day.
98
+ - Adding 365 x N days for N years.
calculation/index.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Numbers and dates
5
+ ---
6
+ # Numbers and dates
7
+
8
+ Exact money arithmetic, date counting and comparisons with limits, for every subject. Each page: rule, procedure, worked example, common mistakes.
9
+
10
+ - Round money, VAT or tax, net and gross, percent, interest, cents against currency: `/knowledge/calculation/money.md`
11
+ - Count days, business days, months or years; due dates; holidays; rolling to the next business day: `/knowledge/calculation/dates.md`
12
+ - "More than", "at most", "within", caps, "per commenced week", "in the last N days", whole months: `/knowledge/calculation/limits.md`
calculation/limits.md ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Limits - thresholds, caps, windows, whole months
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Limits: thresholds, caps, windows, whole months
8
+
9
+ For comparisons with a limit, capped amounts, "in the last N days" counts and whole months.
10
+
11
+ <!-- tier: 1 -->
12
+ ## Rule
13
+
14
+ **The task's own files and stated rules always win over this page; use this page only for what
15
+ the task leaves open.**
16
+
17
+ 1. **The wording of a limit decides whether the boundary value counts.**
18
+
19
+ | Wording | Test | Is exactly N included? |
20
+ |---|---|---|
21
+ | at most N, up to N, no more than N, within N | value <= N | yes |
22
+ | at least N, N or more | value >= N | yes |
23
+ | more than N, exceeds N, over N, above N | value > N | no |
24
+ | less than N, under N, below N | value < N | no |
25
+
26
+ 2. **A limit is a bound, not a target.** Staying under a maximum is fine.
27
+ 3. **A rate with a cap** ("x per day, at most y") is the smaller of the computed amount and the
28
+ cap. The cap is the answer only when the computed amount reaches it.
29
+ 4. **"Per commenced" unit:** any started week or month counts as a whole one. Count = days /
30
+ unit length, rounded up.
31
+ 5. **A threshold stated in weeks**, where the task tests it in days, is weeks x 7 days of that
32
+ threshold, not the number of commenced weeks.
33
+ 6. **Two limits on one thing** ("within N days of discovery and in any event within M months of
34
+ delivery"): the earlier date governs.
35
+ 7. **A look-back window** "in the last N days" covers dates from today - N up to today, where
36
+ today is the task's date, unless the task words the window differently.
37
+ 8. **Whole calendar months** from the first of one month to the end of another:
38
+ (end year - start year) x 12 + (end month - start month) + 1.
39
+
40
+ <!-- tier: 2 -->
41
+ ## Procedure
42
+
43
+ Comparing with a limit:
44
+
45
+ 1. Copy the limit's wording from the task. Find it in the table above.
46
+ 2. Put both values in the same unit.
47
+
48
+ A capped amount:
49
+
50
+ 1. Count the units (round up for "commenced").
51
+ 2. Computed = base x rate x units. Cap = base x cap rate (or the fixed cap).
52
+ 3. Result = the smaller. Round half up at the end.
53
+
54
+ A look-back count:
55
+
56
+ 1. Window start = today - N days.
57
+ 2. Keep the events dated from window start to today.
58
+ 3. Count them in the script; compare with the threshold by its wording.
59
+
60
+ Months of a span after a period end:
61
+
62
+ 1. Total months of the span (rule 8). Monthly amount = amount / total months.
63
+ 2. Months after = months of the span later than the period's own month. A span ending on or
64
+ before the period end has none.
65
+ 3. Amount after = monthly amount x months after.
66
+
67
+ <!-- tier: 3 -->
68
+ ## Worked example
69
+
70
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
71
+ expected result from this example.
72
+
73
+ **Capped penalty.** Order value 52000.00. Penalty 0.5 percent per commenced week, at most 6
74
+ percent. Delay 17 days. Weeks = 17 / 7 rounded up = 3. Computed = 52000.00 x 0.005 x 3 = 780.00.
75
+ Cap = 3120.00. Result 780.00.
76
+
77
+ **Threshold in weeks.** "May end the contract if the delay exceeds 5 weeks": needs more than 35
78
+ days. 17 days: no. Exactly 35 days: still no. 36 days: yes.
79
+
80
+ **Boundary.** "A full refund within 14 days of delivery." Day 14: yes. Day 15: no.
81
+
82
+ **Look-back.** "At least 4 complaints in the last 60 days." Today is 2031-09-20, so the window
83
+ starts 2031-07-22. Complaint dates: 07-10, 07-30, 08-15, 09-01, 09-18. The first is outside.
84
+ Four remain: the rule applies. With "more than 4" it would not.
85
+
86
+ **Months after a period end.** A cost of 3600.00 covers 2031-03-01 to 2031-08-31: 6 months,
87
+ 600.00 each. Period end 2031-04-30. Months after: May to August = 4. Amount after: 2400.00.
88
+
89
+ <!-- tier: 2 -->
90
+ ## Common mistakes
91
+
92
+ - Reading "more than N" as "N or more", or "within N" as "less than N".
93
+ - Reporting the cap as the amount although the computed amount is below it.
94
+ - Testing a weeks threshold with the commenced-week count instead of days against weeks x 7.
95
+ - Taking the later of two limits where the earlier governs.
calculation/money.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Money - exact arithmetic, rounding, tax, interest
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Money: exact arithmetic, rounding, tax, interest
8
+
9
+ For computing an amount of money: a tax line, a penalty, interest, a total.
10
+
11
+ <!-- tier: 1 -->
12
+ ## Rule
13
+
14
+ **The task's own files and stated rules always win over this page; use this page only for what
15
+ the task leaves open.**
16
+
17
+ 1. **Use the task's formula, rounding and units as written.** If the request says how an amount
18
+ is computed and rounded, that sentence is the method; do not replace it with another.
19
+ 2. **Take input amounts as they stand.** A number in a task file is in the unit that file or the
20
+ request states. Never rescale, convert or "correct" an input because it looks unusual.
21
+ 3. **A rate given in percent is divided by 100 exactly once.** A table value of 25 means a
22
+ factor of 0.25. A value already written as 0.25 is not divided again.
23
+ 4. **Compute exactly.** Use a decimal type built from text, or whole cents as integers. Binary
24
+ floating point stores most decimal fractions slightly off, so a value that should end in
25
+ exactly half a cent can round the wrong way.
26
+ 5. **"Round half up"** means a value exactly halfway goes up. Many programming languages round
27
+ half to even by default; that is a different rule.
28
+ 6. **Round where the task says**, not earlier and not later. Do not round where it says nothing
29
+ and the arithmetic is exact.
30
+ 7. **Net and gross.** Tax on a net amount = net x rate. From a gross amount: net = gross / (1 +
31
+ rate), tax = gross - net. Tax is never gross x rate.
32
+ 8. **Keep the sign.** "A minus B" is negative when B is larger.
33
+
34
+ <!-- tier: 2 -->
35
+ ## Procedure
36
+
37
+ 1. Copy the task's sentence about computing and rounding into your notes. Underline: the
38
+ formula, the rounding step, the unit.
39
+ 2. Find the rate in the task's own table, for this item's category and date. Convert percent to
40
+ a factor once.
41
+ 3. Compute each line in a script with exact decimals, in the order the task's formula gives.
42
+ 4. Round at the step the task names. Keep the rounded line.
43
+ 5. Add lines with the script. For a derived figure (A minus B) use the totals and keep the
44
+ sign.
45
+ 6. Interest for days, when the task asks for it: amount x yearly rate x days / the year length
46
+ the task states; round once at the end.
47
+ 7. Sanity check one line by estimate: is it the right order of magnitude? A tax line a hundred
48
+ times too large or too small means a rate or unit slip in your script, not in the task's
49
+ data.
50
+
51
+ <!-- tier: 3 -->
52
+ ## Worked example
53
+
54
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
55
+ expected result from this example.
56
+
57
+ **Percent once.** A table gives the rate as 6 (percent). Net 33.25: tax = 33.25 x 6 / 100 =
58
+ 1.995 exactly; with "round half up to 0.01" that is 2.00.
59
+
60
+ ```python
61
+ from decimal import ROUND_HALF_UP, Decimal
62
+ def money(x):
63
+ return x.quantize(Decimal("0.01"), ROUND_HALF_UP)
64
+ rate = Decimal("6") / 100 # percent to factor, once
65
+ print(money(Decimal("33.25") * rate)) # 2.00
66
+ print(round(33.25 * 0.06, 2)) # 1.99, wrong: binary float
67
+ ```
68
+
69
+ **Gross to net.** Gross 199.00 at 6 percent, with "net rounded half up, tax = gross - net":
70
+ net = 199.00 / 1.06 = 187.7358..., rounded 187.74; tax = 199.00 - 187.74 = 11.26.
71
+ (199.00 x 0.06 = 11.94 would be wrong.)
72
+
73
+ **Totals and sign.** Tax on sales 13.26, tax on purchases 40.00: payable = 13.26 - 40.00 =
74
+ -26.74. The minus sign stays.
75
+
76
+ **Estimate.** 6 percent of about 200 is about 12. A script that prints 1194.00 or 0.12 for
77
+ that line has a slip in the rate; the input amount is not the problem.
78
+
79
+ <!-- tier: 2 -->
80
+ ## Common mistakes
81
+
82
+ - Following a habit or another document's method where the task states its own formula or
83
+ rounding.
84
+ - Deciding that the task's amounts must be in another unit and rescaling them by a hundred.
85
+ - Dividing a percent rate by 100 twice, or not at all.
86
+ - Using floating point and `round()`, and landing one cent off on a half-cent value.
87
+ - Computing tax on a gross amount as gross x rate.
88
+ - Rounding too early or too late against the stated rule.
89
+ - Dropping the minus sign of a negative difference.
compiled/apply-rules.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Applying written rules to a case
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Applying written rules to a case
8
+
9
+ For tasks that give short materials (sections of an act, a protocol, a manual) and a case, and
10
+ ask for the outcome and the amounts due.
11
+
12
+ <!-- tier: 1 -->
13
+ ## Rule
14
+
15
+ **The task's own files and stated rules always win over this page; use this page only for what
16
+ the task leaves open.**
17
+
18
+ 1. **The material rules, not your memory.** Its numbers may differ from similar real rules.
19
+ 2. **Use the version in force.** An amendment replaces the section it amends; the replaced
20
+ number is still printed in the older document and is wrong for the case. See
21
+ `/knowledge/compiled/which-document-wins.md`.
22
+ 3. **A rule has a condition and a consequence.** The consequence follows only if the condition
23
+ is met by the case facts, read with the condition's exact wording ("more than" is not "at
24
+ least").
25
+ 4. **An exception removes a consequence that would otherwise follow.** It matters only when the
26
+ rule's own condition is met. So there are three different situations, and the outcome labels
27
+ on offer usually distinguish them:
28
+ - the condition is met and no exception applies: the right exists;
29
+ - the condition is met but an exception applies: the right is taken away;
30
+ - the condition is not met: nothing happens at all; the exception is not even reached.
31
+ 5. **Each consequence has its own rule.** An exception to one right does not touch another. An
32
+ amount can be due although a right to act is not, and the reverse.
33
+ 6. **An amount is computed exactly as the section words it**, including any cap, and reported
34
+ under the name the request gives.
35
+ 7. **If the deciding fact is missing from the case, never invent it.** See
36
+ `/knowledge/agent-workflow/missing-information.md`.
37
+
38
+ <!-- tier: 2 -->
39
+ ## Procedure
40
+
41
+ 1. Read every document in the materials, with its header. Decide which statements are in force.
42
+ 2. Read the case facts. Read the outcome labels and amount names the request offers.
43
+ 3. For each consequence the request asks about (a right, an amount), find its section. Write it
44
+ as: IF condition THEN consequence, EXCEPT IF exception.
45
+ 4. Test the condition with the case facts. Write the comparison out: "delay 9, threshold more
46
+ than 12: not met".
47
+ 5. Only if the condition is met, test the exception.
48
+ 6. Choose the outcome label that matches the situation in rule 4. Pick by meaning,
49
+ not by which sounds most cautious.
50
+ 7. Compute each amount with a script, following its own section: base, rate, count, cap. An
51
+ exception applies to it only if the text says so.
52
+ 8. Write outcome and amounts in the request's shape; amounts in the format it shows.
53
+
54
+ <!-- tier: 3 -->
55
+ ## Worked example
56
+
57
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
58
+ expected result from this example.
59
+
60
+ Invented material, a library statute.
61
+
62
+ > Section 4.1. A member who returns an item more than 12 days after the due date loses
63
+ > borrowing rights for a month.
64
+ > Section 4.2. Section 4.1 does not apply if the library was closed on the due date.
65
+ > Section 4.3. For each day of delay a fee of 0.2 percent of the item's value is charged, at
66
+ > most 3 percent of its value.
67
+ > Amendment (later date, same authority): Section 4.1 (amended): ... more than 20 days ...
68
+
69
+ Labels offered: `rights_suspended`, `nothing_happens`, `suspension_barred`. Amount: `fee`.
70
+
71
+ **Case A.** Value 450.00, 16 days late, library open on the due date.
72
+ In force: 20 days (the amendment). 16 is not more than 20: condition not met. The exception is
73
+ not reached. Outcome: nothing happens. Fee: 16 x 0.2 = 3.2 percent, capped at 3 percent: 13.50.
74
+
75
+ **Case B.** Value 450.00, 25 days late, library closed on the due date.
76
+ 25 is more than 20: condition met. Exception applies: the suspension is barred. Fee: section
77
+ 4.2 exempts only section 4.1, so the fee is still due: capped, 13.50.
78
+
79
+ **Case C.** Value 450.00, 6 days late, library closed on the due date.
80
+ Condition not met: nothing happens (not "barred": there was nothing to bar). Fee: 6 x 0.2 = 1.2
81
+ percent = 5.40, below the cap of 13.50, so 5.40.
82
+
83
+ <!-- tier: 2 -->
84
+ ## Common mistakes
85
+
86
+ - Choosing the "right is taken away" label whenever the answer is negative, although the
87
+ condition was never met.
88
+ - Reporting the cap as the amount when the computed amount is lower; or ignoring the cap when it
89
+ is higher.
compiled/deadlines-and-drafts.md ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Deadlines of a material and drafts that break its limits
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Deadlines of a material and drafts that break its limits
8
+
9
+ For tasks that ask on which date a deadline of the material falls in a case, and for tasks that
10
+ give a draft (a plan, a list of items) and ask which of its items go beyond what the material
11
+ allows.
12
+
13
+ <!-- tier: 1 -->
14
+ ## Rule
15
+
16
+ **The task's own files and stated rules always win over this page; use this page only for what
17
+ the task leaves open.**
18
+
19
+ 1. **A deadline is a trigger date plus a period.** The section names both: "within N days after
20
+ the invoice date" has the invoice date as trigger and N days as period. The deadline is the
21
+ trigger **plus** N. The last day is still in time.
22
+ 2. **Deadlines can chain.** If one deadline's trigger is another deadline (a reminder "within N
23
+ days after the due date", where the due date is itself "M days after the invoice date"),
24
+ compute the first, then count the second from it.
25
+ 3. **Use the unit the section states** (days, business days, months) and the section in force
26
+ (an amendment replaces the older number).
27
+ 4. **A limit in the material is a bound.** "Within N days", "at most N", "no later than": an
28
+ item breaks it only by going beyond. An item below a maximum is fine. For a minimum ("at
29
+ least N") an item breaks it only by staying below.
30
+ 5. **Match each draft item to its own limit** by what it is about. Different items have
31
+ different limits; do not test one item against another item's limit.
32
+ 6. **Report exactly the items that break a limit**: no more, no fewer. If none does, the list is
33
+ empty.
34
+
35
+ Counting rules: `/knowledge/calculation/dates.md`. Wording of limits: `/knowledge/calculation/limits.md`.
36
+
37
+ <!-- tier: 2 -->
38
+ ## Procedure
39
+
40
+ Deadline question:
41
+
42
+ 1. Read all materials; decide which sections are in force.
43
+ 2. Find the section that defines the deadline asked for. Note the trigger event, the period, the
44
+ unit.
45
+ 3. Find the trigger's date in the case facts. If the trigger is itself a deadline, compute that
46
+ one first.
47
+ 4. Compute trigger + period in a script. Print the date.
48
+ 5. Write the date under the deadline's name as the request spells it, as a full ISO date.
49
+
50
+ Draft review:
51
+
52
+ 1. Read all materials. List every limit: what it is about, the number, the unit, and whether it
53
+ is a maximum or a minimum.
54
+ 2. Read the draft. For each numbered item: what is it about, what value does it state?
55
+ 3. Pair each item with the limit about the same thing.
56
+ 4. Test: maximum broken if value > limit; minimum broken if value < limit. Equal to the limit is
57
+ allowed for "within", "at most", "at least".
58
+ 5. Collect the numbers of the broken items, in the request's shape.
59
+
60
+ <!-- tier: 3 -->
61
+ ## Worked example
62
+
63
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
64
+ expected result from this example.
65
+
66
+ Invented material, a lending code.
67
+
68
+ > Section 2.1. A loan is due 21 days after the lending date.
69
+ > Section 2.2. An overdue notice must be sent within 5 days after the due date.
70
+ > Section 2.6. An appeal must be filed within 40 days after the notice.
71
+
72
+ **Deadline.** Case: lending date 2031-08-18. Asked: the overdue-notice deadline.
73
+ Due date = 2031-08-18 + 21 days = 2031-09-08. Notice deadline = 2031-09-08 + 5 days =
74
+ 2031-09-13. (Not 2031-09-03: "within 5 days after" counts forward from the due date.)
75
+
76
+ **Draft.** A draft procedure states:
77
+
78
+ 1. days allowed for sending the overdue notice: 7
79
+ 2. days allowed for filing an appeal: 25
80
+
81
+ Item 1 is about the notice; its limit is a maximum of 5 days; 7 > 5: broken.
82
+ Item 2 is about the appeal; its limit is a maximum of 40 days; 25 is under it: fine. (It is not
83
+ broken for "not being 40".)
84
+ Answer: item 1 only.
85
+
86
+ <!-- tier: 2 -->
87
+ ## Common mistakes
88
+
89
+ - Subtracting the period from the trigger: "within N days after X" read as X minus N.
90
+ - Counting from the wrong trigger (the lending date instead of the due date).
91
+ - Skipping the first link of a chain and counting the second period from the first trigger.
92
+ - Treating a maximum as a required exact value and flagging every item that differs from it.
93
+ - Testing an item against the limit of a different subject.
compiled/index.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Short rule materials
5
+ ---
6
+ # Short rule materials
7
+
8
+ Tasks that give short materials (acts, manuals, protocols, posts, each with a header of authority, version and date) plus a case, a question or a draft. Each page: rule, procedure, worked example, common mistakes.
9
+
10
+ - Decide the outcome of a case under the material; exceptions; amounts due: `/knowledge/compiled/apply-rules.md`
11
+ - Answer a question when documents disagree or one amends another: `/knowledge/compiled/which-document-wins.md`
12
+ - The date a deadline falls on; draft items that break a limit: `/knowledge/compiled/deadlines-and-drafts.md`
compiled/which-document-wins.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Answering from documents that disagree
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Answering from documents that disagree
8
+
9
+ For tasks that ask a question whose answer stands in the materials, where several documents
10
+ state different values, or one document amends another.
11
+
12
+ <!-- tier: 1 -->
13
+ ## Rule
14
+
15
+ **The task's own files and stated rules always win over this page; use this page only for what
16
+ the task leaves open.**
17
+
18
+ 1. **Every document has a rank, given in its header.** The request states the order of
19
+ precedence. The common order is: higher authority first; among equal authority the later
20
+ date; among equal dates the higher version.
21
+ 2. **Compare in that order and stop at the first difference.** A newer date never beats a higher
22
+ authority. "The newest document wins" is wrong whenever authorities differ.
23
+ 3. **An amendment replaces what it amends**, for the statement it restates. Statements of the
24
+ amended document that the amendment does not restate stay in force.
25
+ 4. **Only documents that answer the question compete.** A high-ranking document about something
26
+ else does not matter; an informal post about the right thing competes, and usually loses.
27
+ 5. **Same subject, same attribute.** Two values conflict only if they are about the same
28
+ attribute of the same thing. A manual may give several attributes of one device; a post may
29
+ give one attribute of another model.
30
+ 6. **Give the value exactly as the winning document writes it**, complete with its unit or
31
+ wording. Do not shorten, convert or paraphrase.
32
+
33
+ <!-- tier: 2 -->
34
+ ## Procedure
35
+
36
+ 1. Read the question. Underline the thing and the attribute asked for.
37
+ 2. Read **every** document in the materials, each whole, header included. Keep each header
38
+ attached to its text: read one file per call, or print all files with their names in one
39
+ listing. Do not trust the order in which several results return.
40
+ 3. Search all documents for the thing and the attribute (a text search for the key words finds
41
+ statements you overlooked).
42
+ 4. Make a table of the candidate statements: document, authority, date, version, the value.
43
+ 5. Discard candidates about another thing or another attribute.
44
+ 6. If one candidate amends another, remove the amended one.
45
+ 7. Rank the rest by the request's order of precedence. Take the top one.
46
+ 8. Copy its value exactly, with unit. Write the answer in the request's shape, with no added
47
+ fields.
48
+
49
+ <!-- tier: 3 -->
50
+ ## Worked example
51
+
52
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
53
+ expected result from this example.
54
+
55
+ | Document | Authority | Date | Version | Says |
56
+ |---|---|---|---|---|
57
+ | Boiler handbook | 3 | 2030-02-01 | 1 | "The test pressure of the Larch boiler 2 is 6 bar." "The flush interval of the Larch boiler 2 is 18 months." |
58
+ | Boiler handbook, older edition | 3 | 2027-05-02 | 1 | "The flush interval of the Larch boiler 2 is 12 months." |
59
+ | Installer forum post | 1 | 2031-03-15 | 1 | "The test pressure of the Larch boiler 2 is 8 bar." |
60
+ | Fee schedule | 3 | 2031-01-02 | 2 | (nothing about boilers) |
61
+
62
+ **Question 1: What is the test pressure of the Larch boiler 2?**
63
+ Candidates: handbook (authority 3) says 6 bar; forum post (authority 1) says 8 bar. Authority is
64
+ compared first: 3 beats 1. The post's later date plays no part. Answer: `6 bar`.
65
+
66
+ **Question 2: What is the flush interval of the Larch boiler 2?**
67
+ Candidates: handbook, 18 months; older edition, 12 months. Equal authority; the later date wins.
68
+ Answer: `18 months`.
69
+
70
+ The fee schedule has the highest version and a late date, but says nothing on either question:
71
+ it is not a candidate.
72
+
73
+ Answers that would be wrong: `8 bar` (newest wins), `6` (unit dropped), `12 months` (older
74
+ edition), `{"value": "6 bar", "source": "handbook"}` (an added field).
75
+
76
+ <!-- tier: 2 -->
77
+ ## Common mistakes
78
+
79
+ - Preferring the newest document although its authority is lower.
80
+ - Mixing up which text belongs to which file after reading several at once, and concluding that
81
+ the authoritative document "does not mention" the attribute.
82
+ - Not reading every document, so the winning statement was never seen.
83
+ - Answering with the value of a neighbouring attribute or of a different model.
84
+ - Using the number an amendment replaced.
85
+ - Dropping the unit, changing the wording, or converting the unit.
86
+ - Adding explanation fields to the answer.
87
+ - Answering from general knowledge when the material states another value.
index.md ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Knowledge index
5
+ ---
6
+ # Knowledge: start here
7
+
8
+ This collection explains **how** to do a kind of work. It never holds the answer to a task.
9
+
10
+ - The task's own files and stated rules always win over any page here. Use a page only for
11
+ what the task leaves open. If the request already states a rule, apply it as written.
12
+ - The examples here are illustrations with invented data. Your task's data looks different;
13
+ never take a fact, a count or an expected result from an example.
14
+ - Open the workflow page first, then the one or two pages below that match your task.
15
+ - Before a decision, say the rule you apply in your own words. Then act.
16
+
17
+ ## First, for every task
18
+
19
+ - How to work any task with tools, write the answer and stop: `/knowledge/agent-workflow/workflow.md`
20
+
21
+ ## When the task asks you to ...
22
+
23
+ **Write a file or handle missing data**
24
+
25
+ - write `answer.json` or another JSON answer, or run a script to compute it: `/knowledge/agent-workflow/answer-file.md`
26
+ - "do not guess", "may be incomplete", name what is missing, or answer with what you need: `/knowledge/agent-workflow/missing-information.md`
27
+
28
+ **Compute a number or a date**
29
+
30
+ - round money, compute VAT or tax, net and gross, percent, interest, cents: `/knowledge/calculation/money.md`
31
+ - count days, business days, months or years, find a due date or last day, holidays, weekends: `/knowledge/calculation/dates.md`
32
+ - compare with a limit: "more than", "at most", "within", "exceeds", a cap, "per commenced week", "in the last N days": `/knowledge/calculation/limits.md`
33
+
34
+ **Bookkeeping (CSV ledgers, invoices, journals)**
35
+
36
+ - reconcile a bank statement with a cash ledger, adjusted cash balance, outstanding items, bank fees: `/knowledge/accounting/bank-reconciliation.md`
37
+ - prepare a VAT return, VAT per invoice, output and input VAT, a rate table: `/knowledge/accounting/vat.md`
38
+ - check a journal against source documents, faulty entries, transposition, duplicate, trial balance: `/knowledge/accounting/journal-errors.md`
39
+ - close a period from `deliveries.csv`: goods or services received but not yet invoiced, accrued costs: `/knowledge/accounting/accrued-costs.md`
40
+ - close a period from supplier invoices with a service period: prepaid costs: `/knowledge/accounting/prepaid-costs.md`
41
+ - close a period from a list of fixed assets: depreciation: `/knowledge/accounting/depreciation.md`
42
+ - consolidate a group: parent and subsidiaries, intercompany items, goods in transit: `/knowledge/accounting/consolidation.md`
43
+
44
+ **Contracts (an agreement, clauses, a rule table, a case file)**
45
+
46
+ - review an agreement for defects: undefined term, wrong cross-reference, conflicting clauses, missing clause: `/knowledge/legal/contract-review.md`
47
+ - answer deadline questions under a contract: complaint, cure, payment due, late interest, notice period, limitation: `/knowledge/legal/deadlines.md`
48
+ - assess a breach: late delivery, defective goods, evidence, remedies, liquidated damages, damages cap: `/knowledge/legal/breach.md`
49
+
50
+ **Support desk (a ticket, a command-line case system, a policy)**
51
+
52
+ - work any ticket through the command-line tool; resolve, escalate or ask the customer: `/knowledge/support/tickets.md`
53
+ - decide a return, a refund, a defect claim, fraud review or the agent limit: `/knowledge/support/refunds.md`
54
+ - source a purchase request from supplier quotes, place a purchase order: `/knowledge/support/procurement.md`
55
+
56
+ **Short materials (acts, manuals, protocols, posts with a header of authority, version, date)**
57
+
58
+ - decide the outcome of a case under the material and compute amounts due: `/knowledge/compiled/apply-rules.md`
59
+ - answer a question from documents that disagree, or where one amends another: `/knowledge/compiled/which-document-wins.md`
60
+ - give the date a deadline of the material falls on, or list draft items that break a limit: `/knowledge/compiled/deadlines-and-drafts.md`
61
+
62
+ ## How every page is built
63
+
64
+ Rule, then Procedure (numbered steps), then one Worked example, then Common mistakes. Read the
65
+ rule and the procedure before you act; check the mistakes list before you finish.
legal/breach.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Assessing a breach - facts, remedies, evidence
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Assessing a breach: facts, remedies, evidence
8
+
9
+ For tasks that ask, from an agreement, a rule table and a case file, if the supplier is
10
+ in breach and which remedies the buyer has on the case date.
11
+
12
+ <!-- tier: 1 -->
13
+ ## Rule
14
+
15
+ **The task's own files and stated rules always win over this page; use this page only for what
16
+ the task leaves open.**
17
+
18
+ 1. **Breach and remedy are separate questions.** A breach is a fact: the goods came late, or did
19
+ not conform. A remedy is what the buyer may still do about it on the case date. Losing a
20
+ remedy (a late complaint, a defect already cured) does not undo the breach.
21
+ 2. **Late delivery** is measured from the agreed delivery date (in the confirmation of the
22
+ order) to the actual delivery date (in the delivery record).
23
+ 3. **A defect claim lives or dies by the notice.** A timely notice (within the inspection
24
+ period) opens a cure period. While it runs, only cure is available. If the defect is remedied
25
+ within it, the matter ends. Only after it ends without remedy do the further remedies arise.
26
+ An untimely notice gives no remedy.
27
+ 4. **Each remedy has its own condition and its own clause.** Test each one separately on the
28
+ case date.
29
+ 5. **Two different caps.** The cap on liquidated damages for delay limits that one amount. The
30
+ general limitation of liability is the ceiling for damages overall. Do not mix them.
31
+ 6. **Evidence is the documents that establish the decisive facts**, and no others.
32
+
33
+ If a decisive document is absent from the file, see
34
+ `/knowledge/agent-workflow/missing-information.md`.
35
+
36
+ <!-- tier: 2 -->
37
+ ## Procedure
38
+
39
+ 1. Read the rule table and the contract. Note every period, percentage and threshold.
40
+ 2. Build the timeline from the case file: order (quantity, price, order value), agreed and
41
+ actual delivery dates, defects noted, notice of defect, supplier's reply or replacement.
42
+ 3. Delay: days = actual minus agreed. More than zero: late delivery.
43
+ 4. Defect: do the documents show non-conforming goods? If so: defective goods, whatever happened
44
+ afterwards.
45
+ 5. Breach type = which of the two occurred (none, one, or both).
46
+ 6. Remedies for delay: liquidated damages by the contract rate, per unit of delay as the rule
47
+ table counts it, up to its own cap; a right to terminate only if the delay exceeds the
48
+ contract's threshold.
49
+ 7. Remedies for a defect: compute the end of the inspection period; is the notice on or before
50
+ it? If not: no remedy. If yes: compute the end of the cure period. Case date on or before it:
51
+ cure only. Remedied in time: nothing further. Case date after it, not remedied: the further
52
+ remedies, each under its own condition.
53
+ 8. Amounts by script.
54
+ 9. Damages ceiling from the limitation of liability clause, if there is a breach.
55
+ 10. Clauses: those whose conditions you applied. Evidence: the documents that gave the decisive
56
+ dates and quantities.
57
+
58
+ <!-- tier: 3 -->
59
+ ## Worked example
60
+
61
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
62
+ expected result from this example.
63
+
64
+ Invented contract: penalty 0.5 percent of the order value per commenced week of delay, at most 6
65
+ percent; termination if the delay exceeds 5 weeks; defects to be notified within 5 Business Days
66
+ after delivery; cure period 10 days; price reduction if not cured; total liability limited to 50
67
+ percent of the order value.
68
+
69
+ Case file: order of 100 units at 520.00 (order value 52000.00); confirmation with delivery date
70
+ 2031-04-07; delivery record dated 2031-04-25 noting 8 damaged units; notice of defect dated
71
+ 2031-05-12; a letter about a new telephone number. Case date 2031-06-02.
72
+
73
+ - Delay: 18 days: late delivery. Commenced weeks 3: penalty 780.00 (cap 3120.00 not reached).
74
+ Termination needs more than 35 days: no.
75
+ - Defect: 8 damaged units: defective goods. Inspection period: 5 business days after
76
+ 2031-04-25 ends 2031-05-02; the notice of 2031-05-12 is late: no defect remedy.
77
+ - Breach: yes, late delivery and defective goods. Remedies: liquidated damages only.
78
+ - Damages ceiling: 50 percent of 52000.00 = 26000.00.
79
+ - Evidence: the confirmation, the delivery record, the notice. Not the telephone letter.
80
+
81
+ <!-- tier: 2 -->
82
+ ## Common mistakes
83
+
84
+ - Answering "no breach" because the complaint was late or the defect was cured.
85
+ - Granting price reduction or termination while the cure period is still running, or after a
86
+ timely replacement.
87
+ - Giving the delay cap as the overall damages ceiling.
legal/contract-review.md ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Reviewing an agreement for drafting defects
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Reviewing an agreement for drafting defects
8
+
9
+ For tasks that give an agreement and ask you to report defects of listed kinds.
10
+
11
+ <!-- tier: 1 -->
12
+ ## Rule
13
+
14
+ **The task's own files and stated rules always win over this page; use this page only for what
15
+ the task leaves open.**
16
+
17
+ 1. **Report only the kinds the request lists, and only real ones.** A wrong report counts
18
+ against you as much as a missed defect. An agreement can be clean; then the list is empty.
19
+ 2. **A defined term** is a capitalised term the agreement gives a meaning to, typically in
20
+ quotation marks followed by "means", or in brackets after a description: (the "Buyer"). A
21
+ definition anywhere in the agreement counts, also after the term's first use.
22
+ 3. **An undefined term** is a capitalised term used like a defined term for which no definition
23
+ exists anywhere. Not undefined: ordinary words at the start of a sentence, headings, names of
24
+ companies, places and laws, common abbreviations, and terms that are defined.
25
+ 4. **A wrong cross-reference** points to a clause number that is not in the agreement, or names a heading
26
+ or subject that is not what that clause is about.
27
+ 5. **Contradictory clauses** state different values for the same thing: two payment periods for
28
+ invoices, two notice periods for one kind of termination. Different values for different
29
+ things are not a contradiction.
30
+ 6. **A missing clause** defect means the agreement has no clause on that subject at all. If any
31
+ clause covers the subject, it is not missing.
32
+ 7. **Each defect is reported with a clause number that exists** in the agreement, or with the
33
+ value the request prescribes when no clause applies.
34
+
35
+ <!-- tier: 2 -->
36
+ ## Procedure
37
+
38
+ 1. Read the whole agreement once. Make a table: clause number, heading of its section.
39
+ 2. List every definition: the term and the clause that defines it.
40
+ 3. List every capitalised multi-use term in the body. For each, look it up in the list from
41
+ step 2. Search the full text for the term in quotation marks before calling it undefined.
42
+ 4. List every cross-reference ("under clause X", "clause X (Heading)"). For each, check that X
43
+ exists and that its section heading matches the words used.
44
+ 5. For each subject the request names (payment period, notice period for a kind of termination,
45
+ limitation of liability): collect every clause that states it. Two different values:
46
+ contradiction. No clause at all: missing.
47
+ 6. Go through your candidate list once more and delete every item you cannot prove with a clause
48
+ number and a quote from the text.
49
+ 7. Write the answer; an empty list if nothing survived.
50
+
51
+ <!-- tier: 3 -->
52
+ ## Worked example
53
+
54
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
55
+ expected result from this example.
56
+
57
+ Invented extract:
58
+
59
+ > 1.1 "Services" means the work described in a Work Order.
60
+ > 1.2 "Work Order" means the Client's written order.
61
+ > 3.1 The Client shall pay each invoice within 30 days.
62
+ > 3.4 Invoices are payable within 45 days of receipt.
63
+ > 5.2 The Provider shall deliver a Completion Report after the Services are finished.
64
+ > 6.1 Liability is limited as set out in clause 9 (Insurance).
65
+ > 7.1 "Restricted Material" means non-public information. Each party keeps it secret.
66
+ > 9. Limitation of Liability
67
+ > 9.1 Each party's liability is limited to the fees paid.
68
+
69
+ Findings:
70
+
71
+ - 3.1 and 3.4 give two payment periods for invoices: contradictory payment terms (report either
72
+ clause).
73
+ - "Completion Report" in 5.2 is used as a defined term and defined nowhere: undefined term.
74
+ - 6.1 refers to "clause 9 (Insurance)", but clause 9 is headed Limitation of Liability: wrong
75
+ cross-reference.
76
+
77
+ Not findings:
78
+
79
+ - "Client" and "Provider": defined in the opening line of a full agreement (assume so here).
80
+ - "Restricted Material": defined in 7.1, the clause that uses it.
81
+ - No missing limitation of liability: clause 9 is one.
82
+
83
+ <!-- tier: 2 -->
84
+ ## Common mistakes
85
+
86
+ - Reporting a common abbreviation or a company name as an undefined term.
87
+ - Reporting a term as undefined because its definition comes later in the text or inside another
88
+ section.
89
+ - Reporting a correct cross-reference as wrong without checking the target's heading.
90
+ - Missing an undefined term that sits inside a long clause far from the definitions.
91
+ - Padding the list "to be safe". Precision counts: when in doubt and unable to prove it, leave
92
+ it out.
legal/deadlines.md ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Deadline questions under a contract
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Deadline questions under a contract
8
+
9
+ For deadline questions under an agreement with a rule table and a holiday list.
10
+
11
+ <!-- tier: 1 -->
12
+ ## Rule
13
+
14
+ **The task's own files and stated rules always win over this page; use this page only for what
15
+ the task leaves open.**
16
+
17
+ 1. **Two sources, two jobs.** The contract gives the length of each period (how many days,
18
+ business days or months). The rule table gives how to count (when a period starts, what a
19
+ business day is, when a deadline rolls, the interest rate, limitation periods). Take each
20
+ from its source in this task; never from memory.
21
+ 2. **Each kind of question has its own trigger date and its own clause.** The request says what
22
+ the dates in a question mean. Find the clause for that kind of deadline before counting.
23
+ 3. **Units are literal.** "N days" is calendar days. "N Business Days" is business days. "N
24
+ months" is months.
25
+ 4. **Where a clause gives two limits, the earlier resulting date governs.**
26
+ 5. **Rolling applies only where the rule table says so.** Typical exemptions are limitation
27
+ periods and the end of a notice period. Check this task's table.
28
+ 6. **An interest question is answered with an amount, not a date.** The interest runs from the
29
+ due date (after any rolling) to the actual payment date.
30
+ 7. **Limitation periods are counted in years** from the date the claim fell due; the length can
31
+ depend on who claims.
32
+
33
+ How to count is on `/knowledge/calculation/dates.md`.
34
+
35
+ <!-- tier: 2 -->
36
+ ## Procedure
37
+
38
+ 1. Read the rule table completely: start of a period, business days, rolling and its
39
+ exemptions, interest, notice periods, limitation periods.
40
+ 2. Read the contract clauses on payment, inspection and complaints, cure, notice of termination.
41
+ Write down each period with its unit.
42
+ 3. Load the holiday list (look at its columns first).
43
+ 4. For each question, in a script:
44
+ - identify its kind and which of its dates is the trigger;
45
+ - take the period from the clause for that kind;
46
+ - count with the right helper (calendar days, business days, months, years);
47
+ - for a two-limit clause compute both dates and take the earlier;
48
+ - roll if, and only if, the table rolls this kind;
49
+ - for interest: compute the due date first, then days late, then the amount, rounded.
50
+ 6. Write one answer per question id, in the request's shape: dates as full ISO dates, amounts
51
+ with two decimals.
52
+
53
+ <!-- tier: 3 -->
54
+ ## Worked example
55
+
56
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
57
+ expected result from this example.
58
+
59
+ Invented contract: invoices payable within 20 days; visible defects to be notified within 5
60
+ Business Days after delivery; hidden defects within 5 Business Days after discovery and in any
61
+ event within 6 months after delivery; termination by 2 months' notice.
62
+ Invented table: periods start the day after the event; deadlines counted in days or months roll
63
+ to the next business day; notice periods run from the first day of the next month, end on the
64
+ last day of the last month, and do not roll; interest 9 percent a year over 365 days; one holiday,
65
+ 2031-03-10.
66
+
67
+ | Question | Work | Answer |
68
+ |---|---|---|
69
+ | Visible defect, delivery Thu 2031-03-06 | 5 business days, skipping the weekend and the holiday Mon 03-10 | 2031-03-14 |
70
+ | Payment due, invoice 2031-09-28 | + 20 days = Sat 2031-10-18, rolls to Monday | 2031-10-20 |
71
+ | Interest, same invoice, 4800.00, paid 2031-10-30 | days late = 10-30 minus 10-20 = 10; 4800.00 x 0.09 x 10 / 365 | 11.84 |
72
+ | Hidden defect, delivery 2031-01-15, discovered 2031-07-10 | 5 business days after discovery = 07-17; 6 months after delivery = 07-15; the earlier | 2031-07-15 |
73
+ | Notice end, notice given 2031-05-14 | month 1 June, month 2 July; no roll | 2031-07-31 |
74
+
75
+ <!-- tier: 2 -->
76
+ ## Common mistakes
77
+
78
+ - Taking the period from memory or from another clause instead of the clause for this kind.
79
+ - Counting business days by hand with wrong weekdays; missing a holiday on the first day.
80
+ - Rolling a limitation date or a notice end that the table exempts; not rolling a payment
81
+ deadline that it does roll.
82
+ - Computing interest from the invoice date or from the unrolled due date; rolling the payment
83
+ date.
84
+ - Reading "limitation" as the limitation of liability clause and answering with a percentage.
legal/index.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Contracts
5
+ ---
6
+ # Contracts
7
+
8
+ Work on an agreement, its clauses, a rule table and a case file. Each page: rule, procedure, worked example, common mistakes.
9
+
10
+ - Review an agreement for defects: undefined term, wrong cross-reference, conflicting clauses, missing clause: `/knowledge/legal/contract-review.md`
11
+ - Deadline questions: complaint, cure, payment due, late interest, notice period, limitation: `/knowledge/legal/deadlines.md`
12
+ - Breach assessment: late delivery, defective goods, evidence, remedies, liquidated damages, damages cap: `/knowledge/legal/breach.md`
support/index.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Support desk
5
+ ---
6
+ # Support desk
7
+
8
+ Working a ticket in a command-line case system under a written policy. Each page: rule, procedure, worked example, common mistakes.
9
+
10
+ - Any ticket: read the policy, look up the facts, apply the rules in order, change state once, check: `/knowledge/support/tickets.md`
11
+ - Returns, refunds, defect claims, fraud review, the agent's refund limit: `/knowledge/support/refunds.md`
12
+ - Purchase requests: eligible supplier quotes, cheapest choice, purchase order, approval limit: `/knowledge/support/procurement.md`
support/procurement.md ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Sourcing a purchase request from supplier quotes
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Sourcing a purchase request from supplier quotes
8
+
9
+ For tickets that ask you to choose among supplier quotes for a purchase request and place an
10
+ order, escalate, or ask for missing information.
11
+
12
+ <!-- tier: 1 -->
13
+ ## Rule
14
+
15
+ **The task's own files and stated rules always win over this page; use this page only for what
16
+ the task leaves open.**
17
+
18
+ 1. **First complete, then eligible, then cheapest, then allowed.** That is the usual order of a
19
+ sourcing policy; follow the order your policy states.
20
+ 2. **A request that lacks a required figure cannot be sourced.** Ask the requester for exactly
21
+ that field and order nothing.
22
+ 3. **A quote is eligible only if it passes every condition**: the supplier's status, the
23
+ required certification, the price against the budget, the lead time against the latest
24
+ acceptable one. Failing one condition is enough to exclude it.
25
+ 4. **Among eligible quotes the lowest total wins.** Ties are broken as the policy says, in the
26
+ order it says.
27
+ 5. **No eligible quote: order nothing** and resolve the ticket with the resolution the policy
28
+ names for that case.
29
+ 6. **A choice above the agent's ordering limit is not ordered.** Escalate to the queue the
30
+ policy names. Do not pick a cheaper ineligible quote, and do not pick a dearer one to dodge
31
+ the rule: the choice is fixed before the limit is tested.
32
+ 7. **Exactly one order, for the chosen quote of this request.**
33
+
34
+ <!-- tier: 2 -->
35
+ ## Procedure
36
+
37
+ 1. Show the request: item, quantity, budget, latest lead time, required certification. If a
38
+ required figure is empty: ask for it by its field name. Stop.
39
+ 2. List the quotes of this request and the suppliers. Read the complete output.
40
+ 3. Make a table, one row per quote: supplier, status, certifications held, total, lead time.
41
+ Put money in one unit.
42
+ 4. Add four yes/no columns: status approved? holds the required certification (the exact one,
43
+ not another)? total within budget? lead time within the limit? Use the policy's wording for
44
+ the boundaries ("at most" includes the boundary value).
45
+ 5. Eligible = four times yes. Cross out the others and write the reason beside each.
46
+ 6. None eligible: resolve with the no-supplier resolution. Stop.
47
+ 7. Pick the lowest total; apply the tie-breakers in the policy's order.
48
+ 8. Compare the chosen total with the agent's ordering limit, same unit. Above: escalate with a
49
+ message, order nothing. Stop.
50
+ 9. Create the order for the chosen quote, once. Resolve the ticket with the ordering resolution.
51
+ 10. Show the ticket and check: one order, the right quote, the right final status.
52
+
53
+ <!-- tier: 3 -->
54
+ ## Worked example
55
+
56
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
57
+ expected result from this example.
58
+
59
+ Invented policy: supplier must be approved and hold the required certification; total at most
60
+ the budget; lead time at most the requested days; lowest total wins, ties to the shorter lead
61
+ time; agent orders up to 2000.00, above that escalate to `buying`.
62
+
63
+ Request: budget 1800.00, lead time at most 10 days, certification `food-safe`.
64
+
65
+ | Quote | Supplier status | Certifications | Total | Lead days | Eligible? |
66
+ |---|---|---|---|---|---|
67
+ | Q1 | approved | food-safe | 1650.00 | 9 | yes |
68
+ | Q2 | approved | fire-safe | 1200.00 | 5 | no: wrong certification |
69
+ | Q3 | blocked | food-safe | 1100.00 | 4 | no: blocked |
70
+ | Q4 | approved | food-safe, fire-safe | 1650.00 | 7 | yes |
71
+ | Q5 | approved | food-safe | 1480.00 | 12 | no: too slow |
72
+ | Q6 | approved | food-safe | 1810.00 | 3 | no: over budget |
73
+
74
+ Eligible: Q1 and Q4, both 1650.00. Tie: the shorter lead time wins: Q4.
75
+ 1650.00 is within the agent's 2000.00: order Q4 once, resolve as ordered.
76
+
77
+ The three cheapest quotes are all traps. The cheapest eligible quote is not the cheapest quote.
78
+
79
+ <!-- tier: 2 -->
80
+ ## Common mistakes
81
+
82
+ - Choosing the cheapest quote without testing eligibility.
83
+ - Accepting a supplier that holds a different certification than the one required.
84
+ - Comparing cents with currency and so "finding" that a small total exceeds the limit, or that a
85
+ large one fits the budget.
86
+ - Excluding a quote that sits exactly on a limit worded "at most".
87
+ - Ordering although the request has no budget, instead of asking for it.
88
+ - Ordering and escalating both, or placing two orders.
support/refunds.md ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Deciding returns, refunds, defect claims and escalations
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Deciding returns, refunds, defect claims and escalations
8
+
9
+ For refund and return tickets. The policy of your task gives every window, percentage and
10
+ limit.
11
+
12
+ <!-- tier: 1 -->
13
+ ## Rule
14
+
15
+ **The task's own files and stated rules always win over this page; use this page only for what
16
+ the task leaves open.**
17
+
18
+ 1. **Screening rules come before refund rules.** A policy usually tests, in order: signs of
19
+ abuse, whether the order is identified, whether it was already refunded, and only then what
20
+ refund the request deserves, and last whether the agent may pay that amount.
21
+ 2. **An abuse rule with "or" has independent parts.** "N refunds within D days, or any
22
+ chargeback": one chargeback is enough on its own; the refund count needs N inside the window.
23
+ 3. **Count only what the rule counts:** this customer's own events, of the named kind, dated
24
+ inside the window that ends on the system's date.
25
+ 4. **Windows are counted from the date the policy names** (usually delivery) to the system's
26
+ date. "At most N days" includes day N.
27
+ 5. **The kind of ticket selects the rule.** A defect claim and an ordinary return have different
28
+ windows, different amounts and different preconditions (a defect claim may need proof).
29
+ 6. **The amount is what the policy names:** the item price, with or without shipping, in full or
30
+ a percentage. Never more than the order cost, and never again for what was already refunded.
31
+ 7. **Over the agent's limit means no refund by you.** Escalate; do not pay part, do not pay all.
32
+ 8. **A denial is a resolution too.** Outside every window, or an excluded category: resolve as
33
+ denied under the policy, pay nothing.
34
+
35
+ <!-- tier: 2 -->
36
+ ## Procedure
37
+
38
+ 1. Collect the ticket, the customer's chargebacks and dated refunds, the order's price,
39
+ shipping, category, delivery date and refunds, the system's date and the policy values.
40
+ 2. Abuse test: window start = system date minus D days. Count this customer's refunds dated in
41
+ the window, in a script. Test the count and, separately, the chargebacks. If met: do what the
42
+ policy says (typically flag and escalate) and nothing else.
43
+ 3. Order identified? If the ticket names none and the customer has several: ask which.
44
+ 4. Already refunded? Add the order's existing refunds; if they cover the item price, resolve as
45
+ already refunded.
46
+ 5. Defect claim: proof attached? If not, ask for it. If yes, days since delivery against the
47
+ defect window; inside: refund what the policy grants for defects; outside: deny.
48
+ 6. Ordinary return: excluded category: deny. Otherwise days since delivery: first window, full
49
+ item price; second window, the stated percentage, rounded half up; later: deny.
50
+ 7. Compare the refund amount with the agent's limit, in the same unit. Above: escalate to the
51
+ queue the policy names, refund nothing.
52
+ 8. Otherwise create the refund once (right order, amount in the unit the command expects, the
53
+ reason the policy names), then resolve the ticket.
54
+
55
+ <!-- tier: 3 -->
56
+ ## Worked example
57
+
58
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
59
+ expected result from this example.
60
+
61
+ Invented policy: abuse = at least 4 refunds in the last 60 days or any chargeback; returns in
62
+ full within 14 days of delivery, half within 45 days, nothing later; shipping never refunded on
63
+ returns; agent limit 800.00.
64
+
65
+ System date 2031-09-20. Return request for an order delivered 2031-09-02, item price 74.50,
66
+ shipping 6.00, category ordinary. Customer: no chargebacks; refunds dated 2031-05-03,
67
+ 2031-06-11, 2031-07-10 and 2031-09-01; no refund on this order.
68
+
69
+ - Abuse: window starts 2031-07-22. Inside: only 2031-09-01. One is not at least 4. No
70
+ chargeback. Rule does not apply.
71
+ - Order named: yes. Already refunded: no.
72
+ - Return: 18 days since delivery. Not within 14; within 45: half of 74.50 = 37.25. Shipping is
73
+ not refunded.
74
+ - Limit: 37.25 is under 800.00.
75
+ - Changes: one refund of 37.25 with the late-return reason; resolve as refunded.
76
+
77
+
78
+ <!-- tier: 2 -->
79
+ ## Common mistakes
80
+
81
+ - Counting refunds older than the window, or "about three months" of them, and escalating an
82
+ honest customer.
83
+ - Reading "or any chargeback" as needing the refund count too, and missing a real abuse case.
84
+ - Refunding shipping where the policy excludes it, or forgetting it where the policy grants it.
85
+ - Refunding an amount over the agent's limit, or escalating and refunding as well.
support/tickets.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ title: Working a ticket through a command-line case system
5
+ tiers: rule 1, procedure 2, example 3, mistakes 2
6
+ ---
7
+ # Working a ticket through a command-line case system
8
+
9
+ For tasks where you work one ticket under a written policy, and the result is the state you
10
+ leave in the case system.
11
+
12
+ <!-- tier: 1 -->
13
+ ## Rule
14
+
15
+ **The task's own files and stated rules always win over this page; use this page only for what
16
+ the task leaves open.**
17
+
18
+ 1. **The policy decides; the tool does not.** The tool carries out whatever you type, allowed or
19
+ not. Checking the policy is your job.
20
+ 2. **Policy rules are tried in their written order, and the first rule that applies decides.**
21
+ Later rules are not applied once an earlier one has decided.
22
+ 3. **A ticket ends in exactly one outcome:** resolved (with a stated resolution), escalated to
23
+ one queue, or waiting for the customer after you asked for a named missing field. Never two.
24
+ 4. **Look first, act last.** Gather every fact with read-only commands, decide the whole outcome,
25
+ and only then change anything.
26
+ 5. **Every change goes through the tool, once.** Changes cannot be taken back; there may be no
27
+ delete. A repeated command makes a duplicate.
28
+ 6. **Touch only this ticket and its own customer.** Other customers' data appears in listings as
29
+ a trap.
30
+ 7. **"Today" is the date the system reports**, not the ticket's date and not the machine clock.
31
+ 8. **Money units differ between commands.** Records may show whole cents while a command takes
32
+ currency with decimals. Check before entering an amount.
33
+
34
+ <!-- tier: 2 -->
35
+ ## Procedure
36
+
37
+ 1. Read the policy file completely. Run the tool's `--help`.
38
+ 2. Show the ticket. Note its kind, customer, order, attachments, text.
39
+ 3. Show the policy values the system reports, including its as-of date.
40
+ 4. Show the customer and the order or request the ticket names. Read the full output; do not
41
+ cut it with line filters.
42
+ 5. Walk the policy rules from the first: for each, state the facts it needs and whether it
43
+ applies. Stop at the first that applies. Compute day counts with a script
44
+ (`/knowledge/calculation/dates.md`).
45
+ 6. Write down the changes that outcome needs, in order. Typically one to three commands.
46
+ 7. Run `--help` for each sub-command you will use, before using it. Do not guess names.
47
+ 8. Run each change as its own call. Read the reply: an error means nothing changed, so fix the
48
+ command; success means never run it again.
49
+ 9. Keep message texts plain: letters, digits, spaces, commas, full stops. No quotation marks,
50
+ apostrophes or special letters inside the message. When asking for something, say the field's
51
+ name in the message.
52
+ 10. Show the ticket once more. Compare with step 6: nothing missing, nothing extra, nothing
53
+ twice. End.
54
+
55
+ <!-- tier: 3 -->
56
+ ## Worked example
57
+
58
+ Illustration only, with invented data. Your task's data differs: take no fact, count or
59
+ expected result from this example.
60
+
61
+ Invented system `desk` and invented policy: "(1) A customer on the blocked list gets no service:
62
+ escalate to the `review` queue. (2) A warranty claim without a serial number: ask the customer
63
+ for `serial_number`. (3) A warranty claim within 24 months of purchase: approve a repair."
64
+
65
+ Ticket K7: a warranty claim, customer U3, product bought 30 months before the system date, no
66
+ serial number given. U3 is on the blocked list.
67
+
68
+ Walk the rules: rule 1 applies (blocked). Stop. Rules 2 and 3 are not reached, although the
69
+ serial number is indeed missing and the warranty has indeed expired.
70
+
71
+ Changes needed: one.
72
+
73
+ 1. `desk ticket escalate --help` (read the options)
74
+ 2. `desk ticket escalate K7 --queue review --message "Customer is on the blocked list, sent for review"`
75
+ 3. `desk ticket show K7`: status escalated, queue review, nothing else changed.
76
+
77
+ Had U3 not been blocked, rule 2 would decide: ask for the serial number, saying "serial number"
78
+ in the message, and do nothing else.
79
+
80
+ <!-- tier: 2 -->
81
+ ## Common mistakes
82
+
83
+ - Applying a later rule although an earlier one already applied, or the reverse: stopping at an
84
+ early rule whose condition was not really met.
85
+ - Giving two outcomes: refunding and then escalating; asking and also resolving.
86
+ - Chaining several changing commands in one line; one fails on quoting, the rest still run.
87
+ - Running a changing command twice and leaving two identical flags or refunds.
88
+ - Trying to "undo" a wrong change with another change (a zero amount, a second resolution).
89
+ - Acting on another customer's order that appeared in a listing.
tools/kb.py ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # SPDX-License-Identifier: CC-BY-4.0
3
+ # Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>
4
+ """Maintenance tool of the knowledge base: lint, export a mountable copy, leakage self-audit.
5
+
6
+ kb.py lint structure, headers, links and token budgets
7
+ kb.py export --out DIR [--max-tier N] [--mount-path /knowledge]
8
+ the pages an agent sees: no README, tools or .git;
9
+ sections above tier N removed
10
+ kb.py audit SOURCE_DIR... compares every page with practice-instance text
11
+ (requests and workspace files a student sees)
12
+
13
+ Token counts are approximated as whitespace-separated words x 1.3.
14
+ """
15
+ import argparse
16
+ import pathlib
17
+ import re
18
+ import sys
19
+
20
+ ROOT = pathlib.Path(__file__).resolve().parent.parent
21
+ INDEX_MAX, PAGE_MIN, PAGE_MAX = 1200, 600, 1000
22
+ SECTIONS = [("## Rule", 1), ("## Procedure", 2), ("## Worked example", 3), ("## Common mistakes", 2)]
23
+ SPDX = "# SPDX-License-Identifier: CC-BY-4.0"
24
+ COPYRIGHT = "# Copyright (c) 2026 Martin Schröder <info@swedishembedded.com>"
25
+ LINK = re.compile(r"`/knowledge/([a-z0-9/-]+\.md)`")
26
+
27
+
28
+ def pages():
29
+ """Every knowledge page: one directory level below the root; a folder's index.md is not a page."""
30
+ return sorted(p for p in ROOT.glob("*/*.md") if p.parent.name not in ("tools", ".git") and p.name != "index.md")
31
+
32
+
33
+ def indexes():
34
+ """The root index and one index per folder."""
35
+ return [ROOT / "index.md"] + sorted(ROOT.glob("*/index.md"))
36
+
37
+
38
+ def tokens(text):
39
+ return round(len(text.split()) * 1.3)
40
+
41
+
42
+ def split_sections(text):
43
+ """Returns (head, [(tier, section text)]): head is front matter, title and introduction."""
44
+ marks = [(m.start(), int(m.group(1))) for m in re.finditer(r"^<!-- tier: (\d) -->\n", text, re.M)]
45
+ if not marks:
46
+ return text, []
47
+ out = []
48
+ for i, (pos, tier) in enumerate(marks):
49
+ end = marks[i + 1][0] if i + 1 < len(marks) else len(text)
50
+ out.append((tier, text[pos:end]))
51
+ return text[: marks[0][0]], out
52
+
53
+
54
+ def lint(_args):
55
+ bad = []
56
+ index = (ROOT / "index.md").read_text()
57
+ for p in indexes():
58
+ n = tokens(p.read_text())
59
+ rel = p.relative_to(ROOT).as_posix()
60
+ print(f"{n:5d} tokens {rel} (max {INDEX_MAX})")
61
+ if n > INDEX_MAX:
62
+ bad.append(f"{rel}: {n} tokens > {INDEX_MAX}")
63
+ for d in sorted({p.parent for p in pages()}):
64
+ folder_index = d / "index.md"
65
+ if not folder_index.exists():
66
+ bad.append(f"{d.name}: no index.md")
67
+ continue
68
+ listed = set(LINK.findall(folder_index.read_text()))
69
+ for p in pages():
70
+ if p.parent == d and p.relative_to(ROOT).as_posix() not in listed:
71
+ bad.append(f"{d.name}/index.md: does not list {p.name}")
72
+ linked = set(LINK.findall(index))
73
+ for p in indexes() + pages():
74
+ rel = p.relative_to(ROOT).as_posix()
75
+ text = p.read_text()
76
+ lines = text.split("\n")
77
+ if lines[0] != "---" or lines[1] != SPDX or lines[2] != COPYRIGHT:
78
+ bad.append(f"{rel}: front matter must start with the SPDX and copyright lines")
79
+ if rel != rel.lower():
80
+ bad.append(f"{rel}: file names are lowercase")
81
+ if not text.replace("Schröder", "Schroder").isascii():
82
+ bad.append(f"{rel}: non-ASCII character outside the copyright name")
83
+ for target in LINK.findall(text):
84
+ if not (ROOT / target).exists():
85
+ bad.append(f"{rel}: links to missing /knowledge/{target}")
86
+ if p.name == "index.md":
87
+ continue
88
+ n = tokens(text)
89
+ print(f"{n:5d} tokens {rel}")
90
+ if not PAGE_MIN <= n <= PAGE_MAX:
91
+ bad.append(f"{rel}: {n} tokens outside {PAGE_MIN}-{PAGE_MAX}")
92
+ if rel not in linked:
93
+ bad.append(f"{rel}: not linked from index.md")
94
+ _, sections = split_sections(text)
95
+ got = [(s.split("\n")[1].strip(), t) for t, s in sections]
96
+ if got != SECTIONS:
97
+ bad.append(f"{rel}: sections must be {SECTIONS}, each after its tier marker; found {got}")
98
+ if re.search(r"\b(cite|quote|mention|name) (the |this |a |its )?(file|path|page)\b", text, re.I):
99
+ bad.append(f"{rel}: a page must not tell the reader to cite files or paths")
100
+ for b in bad:
101
+ print("LINT:", b)
102
+ print("lint:", "FAIL" if bad else "ok", f"({len(pages())} pages)")
103
+ return 1 if bad else 0
104
+
105
+
106
+ def export(args):
107
+ out = pathlib.Path(args.out)
108
+ if out.exists() and any(out.iterdir()):
109
+ sys.exit(f"{out} is not empty")
110
+ for p in indexes() + pages():
111
+ head, sections = split_sections(p.read_text())
112
+ text = head + "".join(s for t, s in sections if t <= args.max_tier)
113
+ text = text.replace("`/knowledge/", f"`{args.mount_path.rstrip('/')}/")
114
+ dest = out / p.relative_to(ROOT)
115
+ dest.parent.mkdir(parents=True, exist_ok=True)
116
+ dest.write_text(text)
117
+ print(f"exported {len(pages()) + len(indexes())} files to {out} (tiers <= {args.max_tier})")
118
+ return 0
119
+
120
+
121
+ NUMBER = re.compile(r"(?<![\w.-])\d[\d,]*(?:\.\d+)?(?![\w-])")
122
+ IDENT = re.compile(r"\b[A-Z]{1,4}-?\d{2,}\b|\b[a-z]+(?:-[a-z0-9]+){2,}-\d+\b")
123
+ DATE = re.compile(r"\b\d{4}-\d{2}-\d{2}\b")
124
+ NAME = re.compile(r"\b[A-Z][a-z]{3,}\b")
125
+ # A name inside a sentence or a data field, so the first word of a sentence is not taken for one.
126
+ MID_NAME = re.compile(r"(?<=[a-z,;] )[A-Z][a-z]{3,}\b|(?<=,)[A-Z][a-z]{3,}\b")
127
+
128
+
129
+ # Month and weekday names, and the copyright holder's nationality adjective, are not instance names.
130
+ CALENDAR = set(
131
+ "January February March April June July August September October November December "
132
+ "Monday Tuesday Wednesday Thursday Friday Saturday Sunday Swedish".split()
133
+ )
134
+ YEAR = re.compile(r"^(19|20)\d\d$")
135
+
136
+
137
+ def features(text):
138
+ """What must not travel from an instance into a page: long numbers, ids, dates, sentences."""
139
+ numbers = set()
140
+ for m in NUMBER.findall(DATE.sub(" ", text)):
141
+ whole = m.replace(",", "").split(".")[0]
142
+ # A bare year is not an amount; full dates are compared separately.
143
+ if len(whole) > 3 and not YEAR.match(m):
144
+ numbers.add(m.replace(",", ""))
145
+ words = re.findall(r"[A-Za-z0-9.%-]+", text.lower())
146
+ grams = {" ".join(words[i : i + 8]) for i in range(len(words) - 7)}
147
+ return numbers, set(IDENT.findall(text)), set(DATE.findall(text)), grams
148
+
149
+
150
+ def audit(args):
151
+ src_text = []
152
+ for d in args.sources:
153
+ for p in sorted(pathlib.Path(d).rglob("*")):
154
+ keep = p.suffix in (".md", ".csv", ".txt") or p.name == "support"
155
+ if p.is_file() and ".git" not in p.parts and keep:
156
+ src_text.append(p.read_text(errors="replace"))
157
+ src = "\n".join(src_text)
158
+ s_num, s_id, s_date, s_gram = features(src)
159
+ # An instance name is a capitalised word the instances never write in lower case, so "Buyer",
160
+ # "Supplier" or "Rule" are not names, while a company or counterparty name is.
161
+ s_lower = set(re.findall(r"\b[a-z]{4,}\b", src))
162
+ s_names = {w for w in MID_NAME.findall(src) if w.lower() not in s_lower}
163
+ print(
164
+ f"sources: {len(src_text)} files, {len(s_num)} long numbers, {len(s_id)} ids, {len(s_date)} dates, "
165
+ f"{len(s_names)} names, {len(s_gram)} 8-word sequences"
166
+ )
167
+ hits = 0
168
+ for p in indexes() + [ROOT / "README.md"] + pages():
169
+ # The licence and copyright lines are not content.
170
+ text = "\n".join(l for l in p.read_text().split("\n") if "SPDX-License" not in l and "Copyright (c)" not in l)
171
+ rel = p.relative_to(ROOT).as_posix()
172
+ k_num, k_id, k_date, k_gram = features(text)
173
+ k_lower = set(re.findall(r"\b[a-z]{4,}\b", text))
174
+ found = {
175
+ "number": k_num & s_num,
176
+ "id": k_id & s_id,
177
+ "date": k_date & s_date,
178
+ "name": {w for w in set(NAME.findall(text)) & s_names if w.lower() not in k_lower} - CALENDAR,
179
+ "8-word sequence": k_gram & s_gram,
180
+ }
181
+ for kind, items in found.items():
182
+ for item in sorted(items):
183
+ hits += 1
184
+ print(f"AUDIT: {rel}: {kind} shared with a practice instance: {item!r}")
185
+ print("audit:", f"{hits} hit(s)" if hits else "clean")
186
+ return 1 if hits else 0
187
+
188
+
189
+ def main():
190
+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
191
+ sub = ap.add_subparsers(dest="cmd", required=True)
192
+ sub.add_parser("lint").set_defaults(fn=lint)
193
+ e = sub.add_parser("export")
194
+ e.add_argument("--out", required=True)
195
+ e.add_argument("--max-tier", type=int, default=3, choices=[1, 2, 3])
196
+ e.add_argument("--mount-path", default="/knowledge")
197
+ e.set_defaults(fn=export)
198
+ a = sub.add_parser("audit")
199
+ a.add_argument("sources", nargs="+")
200
+ a.set_defaults(fn=audit)
201
+ args = ap.parse_args()
202
+ sys.exit(args.fn(args))
203
+
204
+
205
+ if __name__ == "__main__":
206
+ main()
vim/vim-user-manual.md ADDED
The diff for this file is too large to render. See raw diff