@rt-tools/agent-kit 0.29.0 → 0.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/assets/checks/board-epic-plan.github.mjs +128 -9
  2. package/assets/checks/board-epics.github.mjs +6 -10
  3. package/assets/checks/board-folders.mjs +50 -0
  4. package/assets/checks/check-lib-layers.mjs +4 -2
  5. package/assets/checks/check-spec-coverage.mjs +65 -0
  6. package/assets/checks/check-work-steps.mjs +238 -0
  7. package/assets/checks/epic-table.github.mjs +15 -6
  8. package/assets/checks/lib-common.mjs +9 -4
  9. package/assets/checks/lib-domains.mjs +7 -4
  10. package/assets/checks/rt-kit-checks.config.mjs +1 -1
  11. package/assets/checks/task-new.github.mjs +6 -6
  12. package/assets/defaults/project.sh +15 -1
  13. package/assets/hooks/git-guard-delivery-epic.sh +8 -1
  14. package/assets/hooks/git-guard-delivery.sh +2 -1
  15. package/assets/hooks/git-guard-push-tests.sh +31 -8
  16. package/assets/hooks/grill-gate.sh +63 -2
  17. package/assets/hooks/prose-style-guard.sh +49 -3
  18. package/assets/hooks/turn-exit-epic.sh +39 -0
  19. package/assets/hooks/turn-exit-guard.sh +6 -4
  20. package/assets/hooks/turn-exit-patterns.sh +51 -0
  21. package/assets/hooks/turn-exit-verdict.sh +20 -1
  22. package/assets/hooks/waiting-turn-guard.sh +56 -1
  23. package/assets/hooks/write-targets.sh +23 -1
  24. package/assets/laws/work-conduct.md +22 -0
  25. package/assets/patterns/doc-style-human.md +6 -0
  26. package/assets/patterns/git-workflow-merge.md +1 -0
  27. package/assets/patterns/git-workflow-pr-body.github.md +10 -5
  28. package/assets/patterns/spec-driven-domain.md +4 -0
  29. package/assets/patterns/status-report-table.github.md +6 -0
  30. package/assets/patterns/task-flow-start.md +26 -22
  31. package/assets/patterns/testing-e2e.md +14 -0
  32. package/assets/pitfalls/turn-conduct.md +28 -0
  33. package/assets/rules/git-workflow.github.md +2 -1
  34. package/assets/rules/observability.needs-app.md +5 -0
  35. package/assets/rules/reuse-first.md +33 -11
  36. package/assets/rules/task-flow.md +30 -29
  37. package/assets/rules/testing.md +15 -0
  38. package/assets/rules/turn-conduct.md +44 -46
  39. package/assets/rules/typescript-conventions.md +8 -0
  40. package/assets/samples/tasks/_template/plan.md +7 -1
  41. package/assets/samples/tasks/_template/progress.md +13 -0
  42. package/lib/observations-cargo.d.ts +12 -0
  43. package/lib/observations-cargo.d.ts.map +1 -1
  44. package/lib/observations-cargo.js +18 -1
  45. package/lib/observations-cargo.js.map +1 -1
  46. package/package.json +1 -1
  47. package/rt-tools-agent-kit-0.29.1.tgz +0 -0
  48. package/rt-tools-agent-kit-0.29.0.tgz +0 -0
@@ -156,6 +156,11 @@ flowchart TD
156
156
  silently allows what the tree does not have, and the next reader takes it for a current
157
157
  explanation. Not every list has a dead-entry check, so it is removed by the same change that
158
158
  removes the place that caused it.
159
+ - **A new check's list is written together with the check for a dead entry in it.** The article
160
+ above leaves the removal to whoever removes the place, and it is kept by memory: an entry whose
161
+ place is gone silently allows what the tree no longer has. A check that reads its own list also
162
+ compares it with what it found and refuses on an entry nothing answers to — then a dead line
163
+ costs the same as a new violation and does not wait for a reader.
159
164
  - **Red has an assigned action, and a second rerun is not part of it.** Red comes in two kinds,
160
165
  and in the list of runs they look the same: a hosting refusal on the preparation step is cured
161
166
  by a rerun, a defect of the branch is not cured by it at all. The assigned action is one: first
@@ -176,11 +181,21 @@ flowchart TD
176
181
  them drifts from the original silently, and both sides stay green: one writes under its value,
177
182
  the other looks under its own. This is checked by a scenario that computes the value both ways
178
183
  and compares them, not by one scenario on each side.
184
+ - **A field of an answer the whole application shares is checked at the place of assembly, not
185
+ beside one operation.** A test next to an operation sees what that operation returned, while the
186
+ answer is built elsewhere: every such test stays green when the field reaches no answer at all.
187
+ The check goes where the body is assembled, or walks the whole set of operations at once.
179
188
  - **A test asserting absence is green even when it looks for the wrong thing.** There is no match
180
189
  for the right text, nor for a typo in the sample, nor for a renamed key — nothing tells them
181
190
  apart by the run's colour. So a negative assertion goes paired with a positive one: first it is
182
191
  checked that the place sought is found at all, and only then that it lacks what must not be
183
192
  there.
193
+ - **A test about a value's absence is built on a value that cannot exist, not on one that is
194
+ merely not filled in yet.** A test that took a real dictionary key as "the untranslated one" is
195
+ green only while nobody translates it: filling the dictionary turns the fallback assertion red,
196
+ and the red points at the fill, not at the test. The value for such a test is made up on the
197
+ spot and by shape cannot enter the set. It is cast into the key type at the call site: a full
198
+ record stays full, and the case keeps its meaning after any fill.
184
199
  - **A count taken over a run's output says nothing until the run is known to have reached the step
185
200
  counted.** A build, an install and a suite refuse at preparation steps of their own —
186
201
  configuration parsing, dependency resolution, path resolution — and such a refusal carries the
@@ -93,27 +93,24 @@ flowchart TD
93
93
  line about the price in the reply, not waiting; a decision the tree does not hold is asked as a
94
94
  question by the tool.
95
95
  - **A summary of someone else's step.** A run, the owner's review and a merge go on without the
96
- executor and are not sped up by watching. Such a summary the owner reads as work: full, with
97
- numbers and states, the emptiness behind it unseen. Someone else's step is named with one's own
98
- begun step, not instead of it.
96
+ executor and are not sped up by watching; the owner reads such a summary as work. Someone else's
97
+ step is named with one's own begun step, not instead of it.
99
98
  - **Someone else's step is of two kinds, and the second never ends by itself.** A run and a review
100
99
  end without the executor; a refused permission never ends — it is waited for. Work that hit a
101
100
  permission is finished without the part it opens; what was not passed is named in the PR body,
102
101
  where the reviewer reads it: a message lives until the next one, the PR body until the merge.
103
102
  - **One's own unclosed step is not handed to the owner.** A neat list of leftovers reads as an
104
- account of work, and the owner sorts out what the executor could have finished. A question's form
105
- does not fix this: a question is lawful only where neither the rules nor the tree answer it. The
106
- list is written after everything the executor could close is struck out.
103
+ account of work, and the owner sorts out what the executor could have finished. A question is
104
+ lawful only where neither the rules nor the tree answer it; the list is written after all the
105
+ executor could close is struck out.
107
106
  - **A menu under an assigned order.** A choice offered to the owner before the epic is over asks to
108
107
  assign the order anew. No work left in the epic — say so: the epic is over — not "what next".
109
108
  - **A declaration of intent.** "Taking the next task" is not taking it: the phrase lives to the end
110
109
  of the turn, and the work does not move. Only the done is named: the created task's number, the
111
110
  branch's name, the moved column.
112
111
  - **Work named as a command is run in the turn that names it.** The line "running it now" does not
113
- end a turn: either the run happened, or the turn is not over. A named command looks like begun
114
- work better than any promise — exact, visible, and done cannot be told from composed. The reply is
115
- written after the call, not instead of it: a message mid-turn is answered along with the begun
116
- action.
112
+ end a turn: either the run happened, or the turn is not over. The reply is written after the
113
+ call, not instead of it: a message mid-turn is answered along with the begun action.
117
114
  - **A word about one's own work is judged by what the same turn did.** "Not stopping — going on" is
118
115
  confirmed by the turn's end with work, not intent: otherwise the owner reads "promised — did not"
119
116
  as a lie. It is the requirement on a word about the tree, turned on oneself.
@@ -136,15 +133,12 @@ flowchart TD
136
133
  - **A stop is named in a message of its own.** Not in a line at the end of a report: there it drowns
137
134
  — the owner reads a report as an account of the done. Three things are named: what stands, what it
138
135
  waits for and what the owner can decide.
139
- - **Turn exits are watched by a guard, not by the executor's memory.** It reads the declared work
140
- state and what the turn did on it: a file edit or a tree-changing command. A turn with neither
141
- returns to the executor with the next step from the progress. Handed-in and merged work the guard
142
- does not judge: it has already waited out someone else's step.
136
+ - **Turn exits are watched by a guard, not by the executor's memory.** It reads the declared work state and what
137
+ the turn did on it: a file edit or a tree-changing command. A turn with neither returns to the
138
+ executor with the next step from the progress.
143
139
  - **A removed task folder lifts the state requirement and does not end the turn.** The progress
144
- leaves with the folder, taken apart before the PR opens: from then to the merge there is no state
145
- line. A turn is not released by this sign — a removed folder means the middle of handing in, not
146
- its end. From there the turn is judged by the second sign; a turn that opened the PR passes it by
147
- itself.
140
+ leaves with the folder, taken apart before the PR opens; a removed folder means the middle of
141
+ handing in, not its end. From there the turn is judged by the second sign.
148
142
  - **Work without a branch and without a task folder is judged by the same guard by the second
149
143
  sign.** It has no state, and the first sign has nowhere to come from — but a turn with no edit of
150
144
  the tree does not end here either.
@@ -153,35 +147,38 @@ flowchart TD
153
147
  not done by a single line. An epic branch, named by the header of its plan, carries no folder by
154
148
  the rule and is not judged so.
155
149
  - **Exploration does not end a turn, however much of it there is.** Switching branch, pulling,
156
- browsing history and reading PRs are preparation, not work; a turn of these alone leaves the work
157
- where it stood. Parts of a compound command are judged one by one: a read joined to an edit
158
- remains work.
150
+ browsing history and reading PRs are preparation, not work. Parts of a compound command are
151
+ judged one by one: a read joined to an edit remains work.
159
152
  - **A reply to the owner is not an action and does not stand last in a turn.** The order inside a
160
- turn is one: work, the first step of the next, then text. Saying what was done is always allowed;
161
- its place is after the next action, not instead.
153
+ turn is one: work, the first step of the next, then text; what was done is said after the next
154
+ action, not instead of it.
162
155
  - **The last action of a turn is only ever work.** One sign for every kind of stop: a file edit or a
163
156
  changing command — last among what the turn did. The guard's tiers — exploration, waiting, handing
164
157
  in without starting the next — only derive a readable refusal from it.
165
158
  - **Waiting for someone else's step is never the last action of a turn.** While they are waited for,
166
- the work stays where it stood. The last action is judged: waiting mid-turn is lawful, background
167
- work remains work, and a turn ended by a loop until the run is ready, or by watching it, is not
168
- released.
159
+ the work stays where it stood. The last action is judged: waiting mid-turn is lawful, and so is a
160
+ launch in the background mid-turn. Standing last, it is an announcement of intent: what does not depend on it is done while it runs.
169
161
  - **The handover is written even where the branch has no name.** All of it lies in the tree and is
170
162
  reachable on a detached head; one file needs a name, and a short snapshot of the head gives it.
171
- The hook's silence costs more here than elsewhere: compaction comes without a handover, and the
172
- next session starts from a blank.
163
+ Otherwise compaction comes without a handover, and the next session starts from a blank.
164
+ - **A next step written into the progress is begun by the same turn.** The guard reads the order
165
+ of actions: after the last edit of the progress it wants work other than the commit and the push
166
+ of it. A full report and a moved stage number do not replace the step.
173
167
  - **A plan stage is declared closed only after its check command has passed.** The "Checked by"
174
168
  (`Чем проверяется`) line carries the command in backticks and what in its output means "matches".
175
169
  The guard reads the previous stage number from the branch history and holds a turn where the
176
170
  number grew and the command did not run: a session later, marked from memory cannot be told from
177
171
  checked.
178
172
  - **The end of an epic is a stop, and it is the one lawful waiting for a word.** Every task of the
179
- epic is merged or handed over, so there is no next task to take: a guard refuses taking one, and
180
- both guards of the turn end let the stop through by one reading of the epic table. The turn shows
173
+ epic is merged or handed over, so there is no next task to take, and both guards of the turn end
174
+ let the stop through. The turn shows
181
175
  the table of the epic's tasks, what was done on each and what confirms it, and says that the
182
176
  session waits for orders. On the main branch the epic is not read, and the turn is judged as before.
183
177
  <!-- rt-when: ответ владельцу о состоянии работы -->
184
178
 
179
+ - **A step of the plan that is not done forbids a stop, and a report about the done is not an
180
+ exception.** The tier about the epic judges the whole and says nothing about a turn inside one
181
+ task. The count is read from the progress; lawful exits stay as they were.
185
182
  - **The word about a stop the guard reads from the owner, not from the executor.** Otherwise the
186
183
  stop is declared by whoever finds it convenient, and the ban holds until the first inconvenience.
187
184
  - **Until the epic is closed a turn ends only by one of the four exits.** A turn that ended with
@@ -203,14 +200,13 @@ flowchart TD
203
200
  - **A statement about the tree's state is watched by the statement guard, not by the executor's
204
201
  memory.** Everything the reply says about the tree carries a command and its output; said without
205
202
  one, it is no statement — not "checked", not "cleared", not "done". The guard reads the turn's
206
- text to the owner and looks for a command of the same turn; each word has its own kind of command. The previous turn
207
- does not count: the tree's state changes, and yesterday's output says nothing of today's.
203
+ text to the owner and looks for a command of the same turn; each word has its own kind of
204
+ command. The previous turn does not count: yesterday's output says nothing of today's.
208
205
  - **The statement guard waits for the reply text rather than judging the record as it found it.**
209
206
  The text lands in the turn record no earlier than the host calls the hook. Not having waited, the
210
207
  guard returns the turn: an empty record means not "nothing to say" but "nothing to read".
211
- - **The guard catches a statement word, not a wrong conclusion.** About a sample judged by one file,
212
- or a path a person will not take, there is nothing to judge by: no word and no command to compare
213
- with. This is the guard's known boundary; the articles below hold it, not the guard.
208
+ - **The guard catches a statement word, not a wrong conclusion.** About a sample judged by one file
209
+ there is nothing to judge by: no word and no command to compare with. This is the guard's known boundary; the articles below hold it, not the guard.
214
210
  - **A turn about someone else's step is watched by the waiting guard, not by the executor's
215
211
  memory.** It refuses a turn's end where someone else's step was spoken of and nothing was done on
216
212
  the next task — no task created, no branch, no folder, no column moved. Someone else's step it
@@ -218,8 +214,8 @@ flowchart TD
218
214
  are not an action: they are said instead of one.
219
215
  - **A turn that handed work in carries it to a lifted draft.** A draft's merge button is locked by
220
216
  the host, and in the PR list ready cannot be told from unfinished. The next task is taken on top
221
- of that, not instead. The waiting guard watches this: a turn that opened a PR does not end until a
222
- command of the same turn asked the state of the handed-in work.
217
+ of that, not instead. The waiting guard demands a command of the same turn about the state of the
218
+ handed-in work.
223
219
  - **The waiting guard's refusal is lifted by both actions at once.** The taken next task carries the
224
220
  open-PR sign away, and the demand to ask the handed-in work's state never sounds after it.
225
221
  - **Work left in the working tree does not end the turn.** A branch ahead of the remote ref with no
@@ -231,6 +227,13 @@ flowchart TD
231
227
  - **The end of a run is learned from the return of a background command, not from a look at the
232
228
  page.** A background wait brings the executor back to the PR by itself; a look at the page is
233
229
  repeated idly or not at all — the work does not move.
230
+ - **A run nobody started by hand is watched the same as a rerun, and the opened PR starts it.** The
231
+ pipeline wakes by itself: the turn holds no starting command, and one read of the state closes
232
+ nothing. Read as going, the run goes under a wait in the same turn — the waiting guard watches
233
+ the pair "the request opened here, its run read as going".
234
+ - **A green run is carried to a lifted draft by the one who handed the work over, a red one is
235
+ fixed in the same branch.** The owner sees a locked button and reads it as work still going. The
236
+ wait runs in the background, next to the next work.
234
237
  - **Waiting for one's own measurement is done with one wait, not a notification on every step.** A
235
238
  notification is for where every event is acted on; where the outcome matters — one wait.
236
239
  - **A guard's refusal ends the turn.** No other road to the refused edit is sought: not a shell
@@ -260,17 +263,14 @@ flowchart TD
260
263
  list: whoever finds it convenient this minute assigns it, and it drifts.
261
264
  - **A refusal of an irreversible action has a safe part, and it is done.** The demand to ask the
262
265
  owner applies to the action, not the turn: work with a separable harmless part is split, not
263
- postponed whole. A list of options instead of work reads as work — the more neatly drawn up, the
264
- more fully: numbered, with figures, the emptiness of the turn behind it unseen. The owner is told
265
- what is done and what remained for their word.
266
+ postponed whole. The owner is told what is done and what remained for their word.
266
267
  - **The sign of irreversibility is taken from the list, not derived by argument.** The list was
267
268
  drawn up by someone who already weighed reversibility. The argument "it goes outside and cannot be
268
269
  rolled back" always comes, the list only when read, and an argument on top of the list cancels it
269
270
  silently: from outside it looks like caution, not a skipped step. Actions outside the list the
270
271
  executor does not gate.
271
272
  - **A turn in which the executor admitted a miss does not end until the incident record exists.**
272
- The incident guard refuses at the turn's end: by the time of admission the miss has already
273
- happened. The records directory is named by the rule's companion, the file name is the date and
273
+ The incident guard refuses at the turn's end. The records directory is named by the rule's companion, the file name is the date and
274
274
  the miss, the form — the layout template. The admission is caught by a set of samples: a miss
275
275
  admitted in words outside the set the guard lets through.
276
276
  - **A session begun from a handover enters the work by the same rule as any other.** The handover
@@ -282,16 +282,14 @@ flowchart TD
282
282
  with a ready command but does not break the session.
283
283
  - **A filled window ends a turn only where there is no compaction.** Where it is declared, the
284
284
  window is the turn going on: the session compacts and works on, and the stop threshold fires only
285
- when compaction did not come. A turn closed below the threshold loses the rest of the window the
286
- tree paid for, and only the owner catches this.
285
+ when compaction did not come. A turn closed below the threshold loses the rest of the window.
287
286
  - **The session's window fill is watched by a guard, not by the executor's memory.** At the first
288
287
  threshold it reminds to pick a stopping point, at the second it refuses everything but the
289
288
  handover, delivery commands and the task folder — the folder whole: at closing, both the decision
290
289
  along the way and the stage revision are edited. The window size and both thresholds the tree sets
291
290
  itself; a tree that set no size gets no guard.
292
291
  - **The context compaction threshold the tree sets itself, and it stands BELOW the stop threshold.**
293
- Equal thresholds are a race, and the guard wins it: it stands on the call, and compaction comes
294
- between turns. The distance is declared as a number, not derived as a difference; whether the
292
+ Equal thresholds are a race, and the guard wins it. The distance is declared as a number, not derived as a difference; whether the
295
293
  thresholds stand apart the layout audit tells.
296
294
  - **A session closes with a handover, and it lies as a section of the progress.** It is committed
297
295
  and goes into the branch, so the handover survives a move to another machine, and no second record
@@ -76,6 +76,14 @@ flowchart TD
76
76
  have no closed set, and they are declared as a file constant with a telling name.
77
77
  <!-- rt-when: *.ts -->
78
78
 
79
+ - **A set that must be complete is declared as a full record over the key type, not a partial
80
+ one.** A partial declaration makes a missing key lawful, and the shortage shows on the screen
81
+ rather than at the build. The set that must answer for every key of another one is declared by
82
+ that key type whole, and an unfilled key stops compiling. The type is silent about the value —
83
+ an empty string and a copy of the key pass it — so the completeness of values is held by a test
84
+ that walks the whole set, written by the same change as the declaration.
85
+ <!-- rt-when: *.ts -->
86
+
79
87
  - **A type is taken from the package where it is declared.** An own copy of a foreign type
80
88
  diverges from the original silently, and only one of them compiles.
81
89
  <!-- rt-when: *.ts -->
@@ -34,10 +34,16 @@ what is named here is read twice — before the work and after it.>
34
34
 
35
35
  ### 1. <name>
36
36
 
37
- - **What is done:** <in one phrase>
37
+ - **Steps:**
38
+ 1. <what is done first>
39
+ 2. <what is done after it>
38
40
  - **Readiness sign:** <what must become true>
39
41
  - **Verified by:** `<command>` — <what in its output means "it matched">
40
42
 
43
+ The steps are the smallest unit of the work, and they are written here in full: the progress
44
+ mirrors this list with its marks, and a check matches the two by number and by name. A step is
45
+ named by what is done, not by what is thought over — a line nobody can call done is not a step.
46
+
41
47
  The command is written in backticks: the turn exit guard reads it and does not let out a turn in
42
48
  which the stage is declared closed and the command was not run. An acceptance written in prose
43
49
  cannot be confirmed by anything. The command is run right here, while the plan is written, not at
@@ -12,6 +12,19 @@ Rewritten by every session, not appended to.
12
12
  - **Waiting for the owner:** <what exactly, or "no"; the owner's standing word about a stop is quoted in « »>
13
13
  - **PR:** <number and state, or "not open yet">
14
14
 
15
+ ## Steps
16
+
17
+ The steps of the plan, all of them, with a mark each. Rewritten by every turn that moves the work.
18
+
19
+ - `[x]` done · `[>]` going on right now · `[ ]` not begun
20
+
21
+ Exactly one step carries `[>]`. The numbers and the names are copied from the plan and not
22
+ reworded: a check matches the two lists, and the turn exit guard counts what is not done yet.
23
+
24
+ - [x] 1.1 <name of the first step of the first stage>
25
+ - [>] 1.2 <name of the second step of the first stage>
26
+ - [ ] 2.1 <name of the first step of the second stage>
27
+
15
28
  ## Decisions along the way
16
29
 
17
30
  - **<decision>** — <reason>. Affected stage of the plan: <number>.
@@ -1,5 +1,17 @@
1
1
  import { IAsset } from './assets.js';
2
2
  import { IObservationDay, IObservationLine, IObservationsCargo, TSkillKind } from './cargo.js';
3
+ /**
4
+ * Чем замещается имя ресурса, которого пакет не везёт.
5
+ *
6
+ * Своё правило дерево нередко зовёт своим же именем — `rt-tools-storybook` в дереве `rt-tools`, — и
7
+ * тогда имя ресурса выдаёт адрес дерева. Проверка груза на утечку находила его и останавливала
8
+ * отправку целиком: дерево с такими именами не отправляло ничего и никогда.
9
+ *
10
+ * Пакету имя чужого правила не пригодится: он его не везёт и статьи о нём не пишет. Что загрузка
11
+ * была своей, приём и так читает полем рода рядом, а у отказа проверки рода нет — замещение идёт
12
+ * у обоих, иначе имя уезжало бы второй записью.
13
+ */
14
+ export declare const OWN_RESOURCE: string;
3
15
  /** Строка файла дня в строку груза. Битая или чужого рода — `null`: наблюдение не роняет груз. */
4
16
  export declare function parseObservationLine(line: string): Omit<IObservationLine, 'skill'> | null;
5
17
  /** Род загруженного скила по раскладке. */
@@ -1 +1 @@
1
- {"version":3,"file":"observations-cargo.d.ts","sourceRoot":"","sources":["../../../projects/agent-kit/src/lib/observations-cargo.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,kBAAkB,EAAsB,UAAU,EAAE,MAAM,YAAY,CAAC;AASnH,kGAAkG;AAClG,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,gBAAgB,EAAE,OAAO,CAAC,GAAG,IAAI,CAsBzF;AAED,2CAA2C;AAC3C,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,UAAU,CAI/E;AAED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AAE,SAAS,MAAM,EAAE,GAAG,SAAS,gBAAgB,EAAE,CAc/F;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,eAAe,EAAE,CAepI;AAED,qFAAqF;AACrF,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED,oBAAoB;AACpB,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,eAAe,EAAE,GAAG,kBAAkB,CAElI;AAED,6BAA6B;AAC7B,wBAAgB,UAAU,CAAC,KAAK,EAAE,kBAAkB,GAAG,MAAM,CAE5D"}
@@ -17,6 +17,22 @@ import { dayBefore, OBSERVATIONS_DIR } from './observations.js';
17
17
  const DAY_FILE = /^(\d{4}-\d{2}-\d{2})\.jsonl$/;
18
18
  /** Род скила по роду ресурса раскладки. Имя, которого раскладка не знает, — своё у дерева. */
19
19
  const KIND_BY_ASSET = { rules: 'rule', patterns: 'pattern', skills: 'skill' };
20
+ /**
21
+ * Чем замещается имя ресурса, которого пакет не везёт.
22
+ *
23
+ * Своё правило дерево нередко зовёт своим же именем — `rt-tools-storybook` в дереве `rt-tools`, — и
24
+ * тогда имя ресурса выдаёт адрес дерева. Проверка груза на утечку находила его и останавливала
25
+ * отправку целиком: дерево с такими именами не отправляло ничего и никогда.
26
+ *
27
+ * Пакету имя чужого правила не пригодится: он его не везёт и статьи о нём не пишет. Что загрузка
28
+ * была своей, приём и так читает полем рода рядом, а у отказа проверки рода нет — замещение идёт
29
+ * у обоих, иначе имя уезжало бы второй записью.
30
+ */
31
+ export const OWN_RESOURCE = 'own';
32
+ /** Везёт ли пакет ресурс с таким именем. Судятся все роды, а не одни скилы: имя хука тоже пакетное. */
33
+ function packaged(name, assets) {
34
+ return assets.some((asset) => asset.name === name);
35
+ }
20
36
  /** Строка файла дня в строку груза. Битая или чужого рода — `null`: наблюдение не роняет груз. */
21
37
  export function parseObservationLine(line) {
22
38
  if (!line.trim()) {
@@ -50,7 +66,8 @@ export function linesOfDay(text, assets) {
50
66
  for (const raw of text.split('\n')) {
51
67
  const parsed = parseObservationLine(raw);
52
68
  if (parsed) {
53
- lines.push(parsed.ev === 'skill-load' ? { ...parsed, skill: skillKindOf(parsed.res, assets) } : parsed);
69
+ const named = packaged(parsed.res, assets) ? parsed : { ...parsed, res: OWN_RESOURCE };
70
+ lines.push(named.ev === 'skill-load' ? { ...named, skill: skillKindOf(parsed.res, assets) } : named);
54
71
  }
55
72
  }
56
73
  return lines;
@@ -1 +1 @@
1
- {"version":3,"file":"observations-cargo.js","sourceRoot":"","sources":["../../../projects/agent-kit/src/lib/observations-cargo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAyD,kBAAkB,EAAc,MAAM,YAAY,CAAC;AACnH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,6EAA6E;AAC7E,MAAM,QAAQ,GAAW,8BAA8B,CAAC;AAExD,8FAA8F;AAC9F,MAAM,aAAa,GAAyC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAEpH,kGAAkG;AAClG,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC7C,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,IAAI,CAAC;QAC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AAkB,EAAiB,EAAE,CAAC,GAAG,KAAK,IAAI,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC;SAC5E,IAAI,CAAC,CAAC,IAAY,EAAE,KAAa,EAAU,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;SACxE,GAAG,CAAC,CAAC,GAAW,EAAmB,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,QAAQ,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;AACtI,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,QAAQ,CAAC,IAAY;IACjC,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACtE,CAAC;AAED,oBAAoB;AACpB,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,MAAc,EAAE,IAAY,EAAE,IAAgC;IAC1G,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;AAC1D,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,UAAU,CAAC,KAAyB;IAChD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAW,EAAE,GAAoB,EAAU,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AACvG,CAAC","sourcesContent":["/**\n * Груз наблюдений: строки файлов дня за отрезок отправки — как лежат, по дням, плюс род скила у\n * каждой загрузки.\n *\n * Сводка отвечает «как дела сейчас» и теряет сессию и время при сведении; приёмнику, который\n * считает использование за период и по сессиям, нужны сами строки. Они читаются здесь отдельно от\n * сводки: та разбирает строку в свою форму без времени, а грузу время нужно.\n *\n * Род скила считает отправитель: только дерево знает свою раскладку, приём пакета не знает.\n */\nimport { createHash } from 'node:crypto';\nimport { existsSync, readFileSync, readdirSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { IAsset } from './assets.js';\nimport { IObservationDay, IObservationLine, IObservationsCargo, OBSERVATION_EVENTS, TSkillKind } from './cargo.js';\nimport { dayBefore, OBSERVATIONS_DIR } from './observations.js';\n\n/** Имя файла дня: `2026-08-12.jsonl`. Чужое имя в каталоге не наблюдение. */\nconst DAY_FILE: RegExp = /^(\\d{4}-\\d{2}-\\d{2})\\.jsonl$/;\n\n/** Род скила по роду ресурса раскладки. Имя, которого раскладка не знает, — своё у дерева. */\nconst KIND_BY_ASSET: Readonly<Record<string, TSkillKind>> = { rules: 'rule', patterns: 'pattern', skills: 'skill' };\n\n/** Строка файла дня в строку груза. Битая или чужого рода — `null`: наблюдение не роняет груз. */\nexport function parseObservationLine(line: string): Omit<IObservationLine, 'skill'> | null {\n if (!line.trim()) {\n return null;\n }\n try {\n const found: Record<string, unknown> = JSON.parse(line) as Record<string, unknown>;\n const text: (key: string) => string = (key: string): string => {\n const value: unknown = found[key];\n\n return typeof value === 'string' ? value : '';\n };\n const ev: string = text('ev');\n\n if (!OBSERVATION_EVENTS.includes(ev) || !text('sid')) {\n return null;\n }\n const kind: string = text('kind');\n\n return { t: text('t'), ev, res: text('res'), ...(kind ? { kind } : {}), sid: text('sid'), v: text('v') };\n } catch {\n return null;\n }\n}\n\n/** Род загруженного скила по раскладке. */\nexport function skillKindOf(name: string, assets: readonly IAsset[]): TSkillKind {\n const laid: IAsset | undefined = assets.find((asset: IAsset): boolean => asset.name === name && asset.kind in KIND_BY_ASSET);\n\n return laid ? KIND_BY_ASSET[laid.kind] : 'own';\n}\n\n/** Строки одного файла дня, с родом скила у загрузок. */\nexport function linesOfDay(text: string, assets: readonly IAsset[]): readonly IObservationLine[] {\n const lines: IObservationLine[] = [];\n\n for (const raw of text.split('\\n')) {\n const parsed: Omit<IObservationLine, 'skill'> | null = parseObservationLine(raw);\n\n if (parsed) {\n lines.push(parsed.ev === 'skill-load' ? { ...parsed, skill: skillKindOf(parsed.res, assets) } : parsed);\n }\n }\n\n return lines;\n}\n\n/**\n * Дни отрезка отправки: последние `days` дней по названному дню, включая его. Дни идут по\n * возрастанию; день без файла не входит — приёму нечего замещать.\n */\nexport function readObservationDays(root: string, today: string, days: number, assets: readonly IAsset[]): readonly IObservationDay[] {\n const dir: string = join(root, OBSERVATIONS_DIR);\n\n if (!existsSync(dir)) {\n return [];\n }\n const since: string = dayBefore(today, days - 1);\n // Дни записаны `ГГГГ-ММ-ДД`: порядок строк у них хронологический, и сравнение идёт строками.\n const inWindow: (day: string) => boolean = (day: string): boolean => day.localeCompare(since) >= 0 && day.localeCompare(today) <= 0;\n\n return readdirSync(dir)\n .map((name: string): string | null => DAY_FILE.exec(name)?.[1] ?? null)\n .filter((day: string | null): day is string => day !== null && inWindow(day))\n .sort((left: string, right: string): number => left.localeCompare(right))\n .map((day: string): IObservationDay => ({ day, lines: linesOfDay(readFileSync(join(dir, `${day}.jsonl`), 'utf8'), assets) }));\n}\n\n/** Признак рабочей копии: контрольная сумма её корня. Сам путь наружу не уезжает. */\nexport function originOf(root: string): string {\n return createHash('sha1').update(root).digest('hex').slice(0, 12);\n}\n\n/** Груз из дней. */\nexport function observationsCargo(tree: string, schema: string, root: string, days: readonly IObservationDay[]): IObservationsCargo {\n return { tree, schema, days, origin: originOf(root) };\n}\n\n/** Сколько строк в грузе. */\nexport function linesTotal(cargo: IObservationsCargo): number {\n return cargo.days.reduce((sum: number, day: IObservationDay): number => sum + day.lines.length, 0);\n}\n"]}
1
+ {"version":3,"file":"observations-cargo.js","sourceRoot":"","sources":["../../../projects/agent-kit/src/lib/observations-cargo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,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AAG,EAAE,KAAK,EAAE,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,QAAQ,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;AACtI,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,QAAQ,CAAC,IAAY;IACjC,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACtE,CAAC;AAED,oBAAoB;AACpB,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,MAAc,EAAE,IAAY,EAAE,IAAgC;IAC1G,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;AAC1D,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,UAAU,CAAC,KAAyB;IAChD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAW,EAAE,GAAoB,EAAU,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AACvG,CAAC","sourcesContent":["/**\n * Груз наблюдений: строки файлов дня за отрезок отправки — как лежат, по дням, плюс род скила у\n * каждой загрузки.\n *\n * Сводка отвечает «как дела сейчас» и теряет сессию и время при сведении; приёмнику, который\n * считает использование за период и по сессиям, нужны сами строки. Они читаются здесь отдельно от\n * сводки: та разбирает строку в свою форму без времени, а грузу время нужно.\n *\n * Род скила считает отправитель: только дерево знает свою раскладку, приём пакета не знает.\n */\nimport { createHash } from 'node:crypto';\nimport { existsSync, readFileSync, readdirSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { IAsset } from './assets.js';\nimport { IObservationDay, IObservationLine, IObservationsCargo, OBSERVATION_EVENTS, TSkillKind } from './cargo.js';\nimport { dayBefore, OBSERVATIONS_DIR } from './observations.js';\n\n/** Имя файла дня: `2026-08-12.jsonl`. Чужое имя в каталоге не наблюдение. */\nconst DAY_FILE: RegExp = /^(\\d{4}-\\d{2}-\\d{2})\\.jsonl$/;\n\n/** Род скила по роду ресурса раскладки. Имя, которого раскладка не знает, — своё у дерева. */\nconst KIND_BY_ASSET: Readonly<Record<string, TSkillKind>> = { rules: 'rule', patterns: 'pattern', skills: 'skill' };\n\n/**\n * Чем замещается имя ресурса, которого пакет не везёт.\n *\n * Своё правило дерево нередко зовёт своим же именем — `rt-tools-storybook` в дереве `rt-tools`, — и\n * тогда имя ресурса выдаёт адрес дерева. Проверка груза на утечку находила его и останавливала\n * отправку целиком: дерево с такими именами не отправляло ничего и никогда.\n *\n * Пакету имя чужого правила не пригодится: он его не везёт и статьи о нём не пишет. Что загрузка\n * была своей, приём и так читает полем рода рядом, а у отказа проверки рода нет — замещение идёт\n * у обоих, иначе имя уезжало бы второй записью.\n */\nexport const OWN_RESOURCE: string = 'own';\n\n/** Везёт ли пакет ресурс с таким именем. Судятся все роды, а не одни скилы: имя хука тоже пакетное. */\nfunction packaged(name: string, assets: readonly IAsset[]): boolean {\n return assets.some((asset: IAsset): boolean => asset.name === name);\n}\n\n/** Строка файла дня в строку груза. Битая или чужого рода — `null`: наблюдение не роняет груз. */\nexport function parseObservationLine(line: string): Omit<IObservationLine, 'skill'> | null {\n if (!line.trim()) {\n return null;\n }\n try {\n const found: Record<string, unknown> = JSON.parse(line) as Record<string, unknown>;\n const text: (key: string) => string = (key: string): string => {\n const value: unknown = found[key];\n\n return typeof value === 'string' ? value : '';\n };\n const ev: string = text('ev');\n\n if (!OBSERVATION_EVENTS.includes(ev) || !text('sid')) {\n return null;\n }\n const kind: string = text('kind');\n\n return { t: text('t'), ev, res: text('res'), ...(kind ? { kind } : {}), sid: text('sid'), v: text('v') };\n } catch {\n return null;\n }\n}\n\n/** Род загруженного скила по раскладке. */\nexport function skillKindOf(name: string, assets: readonly IAsset[]): TSkillKind {\n const laid: IAsset | undefined = assets.find((asset: IAsset): boolean => asset.name === name && asset.kind in KIND_BY_ASSET);\n\n return laid ? KIND_BY_ASSET[laid.kind] : 'own';\n}\n\n/** Строки одного файла дня, с родом скила у загрузок. */\nexport function linesOfDay(text: string, assets: readonly IAsset[]): readonly IObservationLine[] {\n const lines: IObservationLine[] = [];\n\n for (const raw of text.split('\\n')) {\n const parsed: Omit<IObservationLine, 'skill'> | null = parseObservationLine(raw);\n\n if (parsed) {\n const named: Omit<IObservationLine, 'skill'> = packaged(parsed.res, assets) ? parsed : { ...parsed, res: OWN_RESOURCE };\n\n lines.push(named.ev === 'skill-load' ? { ...named, skill: skillKindOf(parsed.res, assets) } : named);\n }\n }\n\n return lines;\n}\n\n/**\n * Дни отрезка отправки: последние `days` дней по названному дню, включая его. Дни идут по\n * возрастанию; день без файла не входит — приёму нечего замещать.\n */\nexport function readObservationDays(root: string, today: string, days: number, assets: readonly IAsset[]): readonly IObservationDay[] {\n const dir: string = join(root, OBSERVATIONS_DIR);\n\n if (!existsSync(dir)) {\n return [];\n }\n const since: string = dayBefore(today, days - 1);\n // Дни записаны `ГГГГ-ММ-ДД`: порядок строк у них хронологический, и сравнение идёт строками.\n const inWindow: (day: string) => boolean = (day: string): boolean => day.localeCompare(since) >= 0 && day.localeCompare(today) <= 0;\n\n return readdirSync(dir)\n .map((name: string): string | null => DAY_FILE.exec(name)?.[1] ?? null)\n .filter((day: string | null): day is string => day !== null && inWindow(day))\n .sort((left: string, right: string): number => left.localeCompare(right))\n .map((day: string): IObservationDay => ({ day, lines: linesOfDay(readFileSync(join(dir, `${day}.jsonl`), 'utf8'), assets) }));\n}\n\n/** Признак рабочей копии: контрольная сумма её корня. Сам путь наружу не уезжает. */\nexport function originOf(root: string): string {\n return createHash('sha1').update(root).digest('hex').slice(0, 12);\n}\n\n/** Груз из дней. */\nexport function observationsCargo(tree: string, schema: string, root: string, days: readonly IObservationDay[]): IObservationsCargo {\n return { tree, schema, days, origin: originOf(root) };\n}\n\n/** Сколько строк в грузе. */\nexport function linesTotal(cargo: IObservationsCargo): number {\n return cargo.days.reduce((sum: number, day: IObservationDay): number => sum + day.lines.length, 0);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rt-tools/agent-kit",
3
- "version": "0.29.0",
3
+ "version": "0.29.1",
4
4
  "description": "Переносимый слой правил для агента: законы, хуки, проверки и агенты, раскладываемые в репозиторий одной командой",
5
5
  "author": "RT Team",
6
6
  "license": "Apache-2.0",
Binary file
Binary file