@iiiokojiadbi/shift 0.1.0 → 0.29.0

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.
package/core/flows.ts CHANGED
@@ -13,7 +13,6 @@ import {
13
13
  INDEX,
14
14
  KNOWLEDGE,
15
15
  LETTER,
16
- MAX_AUTO_STREAK,
17
16
  NAMES,
18
17
  OLD_DIR,
19
18
  SETTINGS,
@@ -44,6 +43,7 @@ import {
44
43
  waitContext,
45
44
  } from './texts/prompts'
46
45
  import { CONTINUING, NOT_MADE, renderTasks, type TaskView, UNSETTLED, WAITING } from './texts/rows'
46
+ import { numberTracks } from './track'
47
47
  import type { ArchiveInput, HandedBack, OpenInput, PendingShift, SessionFile, Settled, ShiftInput, Stuck, TaskFiles, Work } from './types'
48
48
 
49
49
  // The flows that do not depend on the harness: an adapter hands them the loaded project and what only it knows.
@@ -147,6 +147,7 @@ export async function acceptShift(project: Project, call: ShiftCall): Promise<{
147
147
  if (letterProblem !== null) return { deny: letterProblem }
148
148
 
149
149
  if (settings.enabled) await refreshDocs(project)
150
+ await numberTracks(project)
150
151
  const work = await readRecords(project)
151
152
  if (work === null) return { deny: `No board: create ${BOARD} by the sections in ${GUIDE_TOOL} and call again.` }
152
153
  const previousDir = await previousShift(project)
@@ -213,7 +214,7 @@ export async function openTask(project: Project, input: OpenInput): Promise<{ de
213
214
  const task: TaskFiles = {
214
215
  name: input.name,
215
216
  task: renderTask(input),
216
- track: input.items.map(item => `${formatItem('open', item.name, item.note)}\n`).join(''),
217
+ track: input.items.map((item, n) => `${formatItem('open', n + 1, item.name, item.note)}\n`).join(''),
217
218
  notes: [],
218
219
  }
219
220
  const listPath = `${root}/${TASK_LIST}`
@@ -226,7 +227,7 @@ export async function openTask(project: Project, input: OpenInput): Promise<{ de
226
227
  await store.write(`${folder}/${NAMES.track}`, task.track ?? '')
227
228
  await store.write(listPath, list)
228
229
 
229
- return { result: OPENED(input.name, formatTaskLine(input.status, input.name, input.name, input.about)) }
230
+ return { result: OPENED(input.name, formatTaskLine(input.status, input.name, input.name, input.about), task.track ?? '') }
230
231
  }
231
232
 
232
233
  function renderTask(input: OpenInput): string {
@@ -349,19 +350,14 @@ export type LetGo = {
349
350
  messages: readonly { role: string; text: string }[]
350
351
  before: number | undefined
351
352
  after: number
352
- // `continue` shifts in a row without the owner before this one.
353
- streak: number
354
353
  }
355
354
 
356
- // After the let-go: the summary and the outcome on disk, then continue, or wait — asked for, or forced after
357
- // `MAX_AUTO_STREAK` continues in a row without the owner.
355
+ // After the let-go: the summary and the outcome on disk, then continue or wait, as the agent asked.
358
356
  export async function settleShift(project: Project, letGo: LetGo): Promise<Settled> {
359
357
  const { store } = project
360
358
  const { shift, before, after } = letGo
361
359
  const summary = renderSummary(letGo.messages)
362
360
  await store.write(`${shift.dir}/${NAMES.summary}`, summary)
363
- const streak = letGo.streak + 1
364
- const isCapped = shift.after === 'continue' && streak > MAX_AUTO_STREAK
365
361
  const shrank = `${formatK(before ?? 0)} → ${formatK(after)}`
366
362
  const outcome = (result: string) =>
367
363
  store.write(
@@ -371,22 +367,20 @@ export async function settleShift(project: Project, letGo: LetGo): Promise<Settl
371
367
  const back = await handBack(project, shift.dir)
372
368
  const name = basename(shift.dir)
373
369
 
374
- if (shift.after === 'continue' && !isCapped) {
370
+ if (shift.after === 'continue') {
375
371
  await outcome(OUTCOME.continuing(shrank))
376
372
 
377
373
  return {
378
374
  after: 'continue',
379
- streak,
380
375
  prompt: continuePrompt(shift.letter, back),
381
376
  row: CONTINUING(name, shrank, shift.dir),
382
377
  }
383
378
  }
384
379
 
385
- const why = isCapped ? `waiting: ${MAX_AUTO_STREAK} shifts in a row without the owner` : 'waiting for the owner'
386
- await outcome(OUTCOME.waiting(shrank, why))
380
+ await outcome(OUTCOME.waiting(shrank, 'waiting for the owner'))
387
381
  const note = { context: waitContext(shift.letter, back), dir: shift.dir, files: deliveredFiles(back.work) }
388
382
 
389
- return { after: 'wait', note, row: WAITING(name, shrank, isCapped) }
383
+ return { after: 'wait', note, row: WAITING(name, shrank) }
390
384
  }
391
385
 
392
386
  // The fill the stretch started from, if the last shift was this session's: a fresh process counts from there.
@@ -458,7 +452,10 @@ export async function tasksView(project: Project): Promise<string> {
458
452
  status: task.status,
459
453
  name: task.name,
460
454
  about: task.about,
461
- items: task.status === 'in progress' ? open.map(item => ({ status: item.status, name: item.name })) : null,
455
+ items:
456
+ task.status === 'in progress'
457
+ ? open.map(item => ({ status: item.status, name: item.id === null ? item.name : `#${item.id} ${item.name}` }))
458
+ : null,
462
459
  closed: items.length - open.length,
463
460
  total: items.length,
464
461
  })
package/core/input.ts CHANGED
@@ -139,7 +139,7 @@ export function parseTrackInput(raw: Record<string, unknown>): TrackInput | stri
139
139
  const status = optional(raw, 'status')
140
140
  const note = optional(raw, 'note')
141
141
  if (Array.isArray(raw.items) && raw.items.length > 0) {
142
- if (optional(raw, 'item') !== null) return 'Pass item inside items, or leave items out.'
142
+ if (optional(raw, 'item') !== null || raw.id !== undefined) return 'Pass id and item inside items, or leave items out.'
143
143
  const items: ItemChange[] = []
144
144
  for (const [n, each] of raw.items.entries()) {
145
145
  const change = itemChange(typeof each === 'object' && each !== null ? (each as Record<string, unknown>) : {})
@@ -151,7 +151,7 @@ export function parseTrackInput(raw: Record<string, unknown>): TrackInput | stri
151
151
 
152
152
  return typeof own === 'string' ? own : { task, items, own }
153
153
  }
154
- if (optional(raw, 'item') === null) {
154
+ if (optional(raw, 'item') === null && raw.id === undefined) {
155
155
  const own = ownStatus(status ?? '', note)
156
156
 
157
157
  return typeof own === 'string' ? own : { task, items: [], own }
@@ -161,12 +161,14 @@ export function parseTrackInput(raw: Record<string, unknown>): TrackInput | stri
161
161
  return typeof change === 'string' ? change : { task, items: [change], own: null }
162
162
  }
163
163
 
164
- // One item's change: its words, a status of a track item, a one-line note.
164
+ // One item's change: its id, or the text of a new item; a status of a track item, a one-line note.
165
165
  function itemChange(raw: Record<string, unknown>): ItemChange | string {
166
- const item = text(raw, 'item')
166
+ const item = optional(raw, 'item')
167
+ const id = itemId(raw.id)
167
168
  const status = text(raw, 'status')
168
169
  const note = optional(raw, 'note')
169
- if (item === '') return "item is empty: words of the item's name."
170
+ if (raw.id !== undefined && id === null) return 'id is the number of a track item, as in its #<id>.'
171
+ if ((id === null) === (item === null)) return 'Pass id to change an item, or item to add a new one.'
170
172
  if (!isOneOf(STATUSES, status)) return `status for a track item is one of ${quote(STATUSES)}.`
171
173
  for (const [key, value] of [
172
174
  ['item', item],
@@ -176,7 +178,13 @@ function itemChange(raw: Record<string, unknown>): ItemChange | string {
176
178
  if (problem !== null) return problem
177
179
  }
178
180
 
179
- return { item, status, note, add: raw.add === true }
181
+ return id === null ? { item: item ?? '', status, note } : { id, status, note }
182
+ }
183
+
184
+ // A positive whole number, given as one or as a string, with or without its `#`.
185
+ function itemId(raw: unknown): number | null {
186
+ const id = typeof raw === 'string' ? Number(raw.replace(/^#/, '')) : raw
187
+ return typeof id === 'number' && Number.isInteger(id) && id > 0 ? id : null
180
188
  }
181
189
 
182
190
  // The task's own status in TASKS.md: a waiting or deferred one carries its reason.
package/core/layout.ts CHANGED
@@ -26,9 +26,6 @@ export const RESUME_COMMAND = 'unshift'
26
26
 
27
27
  export const TASKS_COMMAND = 'shift-tasks'
28
28
 
29
- // Consecutive self-continued shifts before the mod stops and waits for the owner.
30
- export const MAX_AUTO_STREAK = 3
31
-
32
29
  // The board is the state of the work; past this it has turned into a diary.
33
30
  export const BOARD_MAX_LINES = 150
34
31
 
package/core/loop.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  // Generated from core/src by scripts/sync-core.ts — edit the source, not this copy.
2
2
  import { settleShift, shiftNotMade, shiftUnsettled } from './flows'
3
3
  import { type GaugeKeeper, takeHint } from './hint'
4
- import { MAX_AUTO_STREAK } from './layout'
5
4
  import { basename } from './paths'
6
5
  import type { Project } from './project'
7
6
  import { compactInstructions, FAILURE_NOTE, NOT_MADE_NOTE, UNSETTLED_NOTE } from './texts/prompts'
@@ -15,8 +14,6 @@ import type { PendingShift, Settled, WaitNote } from './types'
15
14
  export type LoopState = {
16
15
  // The shift accepted in this turn, let go once the turn ends.
17
16
  pending: PendingShift | null
18
- // `continue` shifts in a row without the owner.
19
- streak: number
20
17
  // The letter and the records waiting for the owner's next message.
21
18
  note: WaitNote | null
22
19
  }
@@ -44,7 +41,7 @@ export type LetGoHarness = {
44
41
  afterLetGo?(): Promise<void>
45
42
  }
46
43
 
47
- export const FRESH_LOOP: LoopState = { pending: null, streak: 0, note: null }
44
+ export const FRESH_LOOP: LoopState = { pending: null, note: null }
48
45
 
49
46
  // An accepted shift waits for its turn to end.
50
47
  export async function holdShift(loop: Loop, shift: PendingShift): Promise<void> {
@@ -87,8 +84,6 @@ export async function afterTurn(project: Project, loop: Loop, harness: LetGoHarn
87
84
  messages: done.messages,
88
85
  before: done.before ?? before,
89
86
  after: done.after ?? (await harness.fill()) ?? 0,
90
- // Read now: the owner may have spoken while the history was let go.
91
- streak: (await loop.read()).streak,
92
87
  })
93
88
  } catch (error) {
94
89
  const why = String(error)
@@ -102,30 +97,21 @@ export async function afterTurn(project: Project, loop: Loop, harness: LetGoHarn
102
97
  loop.tell(settled.row, 'info')
103
98
  return
104
99
  }
105
- const { streak } = settled
106
- await loop.update(current => ({ ...current, streak }))
107
100
  loop.tell(settled.row, 'info')
108
101
  // The shift is settled and written; a turn that does not start is told, not recorded against it.
109
102
  await harness.continueWith(settled.prompt).catch((error: unknown) => loop.tell(NOT_CONTINUED(String(error)), 'error'))
110
103
  }
111
104
 
112
105
  // A failed shift is told to the agent, who was told it was accepted: at once when it was to continue and may go on,
113
- // within the same count of runs without the owner; otherwise with the owner's next message.
106
+ // otherwise with the owner's next message.
114
107
  async function tellAgent(loop: Loop, harness: LetGoHarness, shift: PendingShift, context: string, goOn: boolean): Promise<void> {
115
- const { streak } = await loop.read()
116
- if (goOn && shift.after === 'continue' && streak < MAX_AUTO_STREAK) {
117
- await loop.update(current => ({ ...current, streak: current.streak + 1 }))
108
+ if (goOn && shift.after === 'continue') {
118
109
  await harness.continueWith(context).catch((error: unknown) => loop.tell(NOT_CONTINUED(String(error)), 'error'))
119
110
  return
120
111
  }
121
112
  await loop.update(current => ({ ...current, note: { context, dir: shift.dir, files: [FAILURE_NOTE] } }))
122
113
  }
123
114
 
124
- // The owner spoke: the count of shifts without them starts over.
125
- export async function ownerSpoke(loop: Loop): Promise<void> {
126
- await loop.update(state => ({ ...state, streak: 0 }))
127
- }
128
-
129
115
  // The note waiting for the owner's message, if any, and what clears it once it went with that message: a failed
130
116
  // delivery keeps it for the next one.
131
117
  export async function waitingNote(loop: Loop): Promise<{ context: string; delivered: () => Promise<void> } | null> {
package/core/markdown.ts CHANGED
@@ -140,20 +140,24 @@ export function findDate(text: string): string | null {
140
140
  return null
141
141
  }
142
142
 
143
- // Every `- ` line of a text as an item; a line without a `[status]` has an empty one.
143
+ // Every `- ` line of a text as an item; a line without a `[status]` has an empty one, a track item without `#<id>`
144
+ // a null id.
144
145
  export function itemsOf(text: string): Item[] {
145
146
  return text.split('\n').flatMap((raw, index) => {
146
147
  if (!raw.startsWith('- ')) return []
147
148
  const line = raw.trim()
148
149
  const match = /^- \[([^\]]+)\] *(.*)$/.exec(line)
149
150
  const rest = match?.[2] ?? line.slice(2).trim()
150
- const cut = rest.indexOf(' — ')
151
+ const id = /^#(\d+) +/.exec(rest)
152
+ const named = id === null ? rest : rest.slice(id[0].length)
153
+ const cut = named.indexOf(' — ')
151
154
 
152
155
  return [
153
156
  {
154
157
  status: match?.[1] ?? '',
155
- name: cut === -1 ? rest : rest.slice(0, cut),
156
- note: cut === -1 ? null : rest.slice(cut + 3),
158
+ id: id === null ? null : Number(id[1]),
159
+ name: cut === -1 ? named : named.slice(0, cut),
160
+ note: cut === -1 ? null : named.slice(cut + 3),
157
161
  rest,
158
162
  line,
159
163
  index,
@@ -162,8 +166,8 @@ export function itemsOf(text: string): Item[] {
162
166
  })
163
167
  }
164
168
 
165
- export function formatItem(status: string, name: string, note: string | null): string {
166
- return `- [${status}] ${name}${note === null ? '' : ` — ${note}`}`
169
+ export function formatItem(status: string, id: number, name: string, note: string | null): string {
170
+ return `- [${status}] #${id} ${name}${note === null ? '' : ` — ${note}`}`
167
171
  }
168
172
 
169
173
  export function formatK(n: number): string {
@@ -20,7 +20,6 @@ import {
20
20
  KNOWLEDGE_MAX_LINES,
21
21
  LETTER,
22
22
  LETTER_SECTIONS,
23
- MAX_AUTO_STREAK,
24
23
  MOD,
25
24
  NAME_RULE,
26
25
  NAMES,
@@ -112,8 +111,8 @@ Each fact lives in one place. Your records live in the project directory, not in
112
111
 
113
112
  const TASK_RULES = `A task is one line of work, split by meaning: a feature, an adapter, a migration. Each lives in \`${TASKS}/<name>/\`, \`<name>\` in ${NAME_RULE}:
114
113
  - \`task.md\` — what the task is: a \`# <title>\` line, then sections ${TASK_SECTIONS.map(s => `"${s}"`).join(', ')}, all required ("none" if empty). Update it as the task changes. Decisions and dead ends that matter only inside this task go here;
115
- - \`track.md\` — the task's tracker: one line per item, \`- [status] item — what matters\`, status: ${STATUSES.join(', ')}. Add items as you go and set their status with \`${TRACK_TOOL}\`, not by hand; closed items stay until the task is archived — the track is the task's history;
116
- - \`${NAMES.notes}/\` — notes, when a line is not enough: research, a decision worked out, evidence. A markdown file with a frontmatter \`description\` and nothing else required, linked from its item in \`track.md\` — \`- [open] item — see [what it holds](${NAMES.notes}/<file>.md)\` — or from \`task.md\` when it is about the whole task. After a shift a task in progress shows its notes as a list with their descriptions; open one when its item comes up. Most items need none.
114
+ - \`track.md\` — the task's tracker: one line per item, \`- [status] #<id> item — what matters\`, status: ${STATUSES.join(', ')}. Add items as you go and set their status with \`${TRACK_TOOL}\`, not by hand: it gives a new item its id and finds an item by it; closed items stay until the task is archived — the track is the task's history;
115
+ - \`${NAMES.notes}/\` — notes, when a line is not enough: research, a decision worked out, evidence. A markdown file with a frontmatter \`description\` and nothing else required, linked from its item in \`track.md\` — \`- [open] #3 item — see [what it holds](${NAMES.notes}/<file>.md)\` — or from \`task.md\` when it is about the whole task. After a shift a task in progress shows its notes as a list with their descriptions; open one when its item comes up. Most items need none.
117
116
 
118
117
  Open a task with \`${OPEN_TOOL}\`, which writes its folder, its files and its line valid at once. Every folder in \`${TASKS}/\` is in \`${TASK_LIST}\`, and every listed task has its folder. What is "in progress" there is what you are doing now — one task, several, or none.`
119
118
 
@@ -207,7 +206,7 @@ First the flow of a shift, then the rules of each record it checks.
207
206
  - \`about\` — one line up to ${ABOUT_MAX} characters: what the stretch did and where you stand. This is the history line you will look the stretch up by, and it comes back after the next shifts: write the work, not whether you continue or wait.
208
207
  4. End the turn, no further actions: with \`continue\` — one line; with \`wait\` — your answer to the owner, whole: what you did and found, what you ask them to decide. The owner reads that message, not your letter or records.
209
208
 
210
- After the shift, the first message is "Shift done": the board and the tasks in progress, whole, with their notes listed, and the map of knowledge — \`${SHIFT_FILE}\`, \`${OWNER}\`, \`${GLOSSARY}\` and \`${TASK_LIST}\` are read again into the session's own block; then the descriptions of the last ${RECENT_SHIFTS} shifts, an open task unchanged through ${STUCK_SHIFTS} shifts and the documents with remarks, if any; your letter last. Continue from "${NEXT}". With \`wait\` they come together with the owner's next message. ${MAX_AUTO_STREAK} \`continue\` in a row without the owner — the mod then waits for the owner itself.
209
+ After the shift, the first message is "Shift done": the board and the tasks in progress, whole, with their notes listed, and the map of knowledge — \`${SHIFT_FILE}\`, \`${OWNER}\`, \`${GLOSSARY}\` and \`${TASK_LIST}\` are read again into the session's own block; then the descriptions of the last ${RECENT_SHIFTS} shifts, an open task unchanged through ${STUCK_SHIFTS} shifts and the documents with remarks, if any; your letter last. Continue from "${NEXT}". With \`wait\` they come together with the owner's next message.
211
210
 
212
211
  ## Letter — \`${LETTER}\`
213
212
 
@@ -241,7 +240,7 @@ The mod looks at the records around every tool you run. A record you changed —
241
240
  description: <about from the call>
242
241
  at: <ISO time of the shift, UTC>
243
242
  after: continue | wait
244
- result: pending | shifted (<before> → <after>), continuing | shifted (…), waiting for the owner | shifted (…), waiting: … in a row without the owner | not shifted: <reason> | let go, not settled: <reason>
243
+ result: pending | shifted (<before> → <after>), continuing | shifted (…), waiting for the owner | not shifted: <reason> | let go, not settled: <reason>
245
244
  tokens: <before> → <after>
246
245
  summary_chars: <size of summary.md>
247
246
  session: <session id>
@@ -36,8 +36,8 @@ export const NOTE_KINDS = {
36
36
 
37
37
  export type NoteKind = keyof typeof NOTE_KINDS
38
38
 
39
- export const OPENED = (name: string, line: string) =>
40
- `Opened ${TASKS}/${name}/ with task.md and track.md, and its line in ${TASK_LIST}:\n${line}\nIts decisions, dead ends and owner decisions say "none" until there are some; add items as you go with ${TRACK_TOOL}.`
39
+ export const OPENED = (name: string, line: string, track: string) =>
40
+ `Opened ${TASKS}/${name}/ with task.md and track.md, and its line in ${TASK_LIST}:\n${line}\n${track === '' ? '' : `Its items, each changed with ${TRACK_TOOL} by its id:\n${track}`}Its decisions, dead ends and owner decisions say "none" until there are some; add items as you go with ${TRACK_TOOL}.`
41
41
 
42
42
  export const ARCHIVED = (name: string) =>
43
43
  `Archived to ${ARCHIVE}/${name}/, its line is in ${INDEX}, and ${TASK_LIST} no longer lists it: links to it now point into the archive. Lift to the board any of its decisions that still bind beyond it.`
@@ -1,5 +1,5 @@
1
1
  // Generated from core/src by scripts/sync-core.ts — edit the source, not this copy.
2
- import { MAX_AUTO_STREAK, NAMES, TASK_LIST } from '../layout'
2
+ import { NAMES, TASK_LIST } from '../layout'
3
3
 
4
4
  // The owner's rows in the transcript: what became of a shift. Short, one line each.
5
5
 
@@ -12,8 +12,8 @@ export const NOT_MADE = (name: string, why: string) => `shift ${name} not made
12
12
  export const CONTINUING = (name: string, shrank: string, dir: string) =>
13
13
  `shift ${name} done (${shrank}), continuing from the letter — ${dir}/${NAMES.letter}`
14
14
 
15
- export const WAITING = (name: string, shrank: string, capped: boolean) =>
16
- `shift ${name} done (${shrank})${capped ? `, ${MAX_AUTO_STREAK} in a row without you` : ''} — waiting for you, the letter goes with your next message`
15
+ export const WAITING = (name: string, shrank: string) =>
16
+ `shift ${name} done (${shrank}) — waiting for you, the letter goes with your next message`
17
17
 
18
18
  export const UNSETTLED = (name: string, why: string) =>
19
19
  `shift ${name}: the history was let go, but the message after it failed — ${why}; the letter is in the shift's folder`
@@ -76,29 +76,28 @@ export const OPEN_SCHEMA = {
76
76
 
77
77
  export const ARCHIVE_DESCRIPTION = `Archive a finished or dropped task: moves ${TASKS}/<name>/ to ${ARCHIVE}/<name>/ and adds its line to ${INDEX}. It also takes the task out of ${TASK_LIST}.`
78
78
 
79
- export const TRACK_DESCRIPTION = `Set a status instead of editing the records by hand. With item: a track item of the task — item is words of its name (before " — "), enough to find one; a fragment that finds none or several is refused with the items listed. Without item: the task's own status in ${TASK_LIST}. status — for an item ${quote(STATUSES)}; for a task ${quote(FOCUS)}. note — replaces what follows " — ": what matters, or the reason a task is deferred or waits (required then). add: true adds item as a new item. Several items at once — when a stage closes one item and opens the next: items, a list of {item, status, note, add}, applied together or not at all; status beside items is then the task's own.`
79
+ export const TRACK_DESCRIPTION = `Set a status instead of editing the records by hand. With id: the track item with that id, the number in its "#<id>". With item: a new item with that text, given the next id. Without either: the task's own status in ${TASK_LIST}. status — for an item ${quote(STATUSES)}; for a task ${quote(FOCUS)}. note — replaces what follows " — ": what matters, or the reason a task is deferred or waits (required then). Several items at once — when a stage closes one item and opens the next: items, a list of {id or item, status, note}, applied together or not at all; status beside items is then the task's own.`
80
80
 
81
81
  export const TRACK_SCHEMA = {
82
82
  type: 'object',
83
83
  properties: {
84
84
  task: { type: 'string', description: `The task's folder name in ${TASKS}/.` },
85
- item: { type: 'string', description: "Words of the track item's name; leave out to set the task's own status." },
85
+ id: { type: 'integer', description: 'The track item to change: the number in its "#<id>".' },
86
+ item: { type: 'string', description: 'The text of a new track item; what matters goes in note.' },
86
87
  status: { type: 'string', enum: [...new Set([...STATUSES, ...FOCUS])] },
87
88
  note: { type: 'string', description: 'One line: replaces what follows " — ".' },
88
- add: { type: 'boolean', description: 'true: add item as a new item.' },
89
89
  items: {
90
90
  type: 'array',
91
- description:
92
- 'Several items in one call, in place of item: each found or added as item alone would be; one that fails writes nothing.',
91
+ description: 'Several items in one call, in place of id and item: each changed or added as alone; one that fails writes nothing.',
93
92
  items: {
94
93
  type: 'object',
95
94
  properties: {
95
+ id: { type: 'integer' },
96
96
  item: { type: 'string' },
97
97
  status: { type: 'string', enum: [...STATUSES] },
98
98
  note: { type: 'string' },
99
- add: { type: 'boolean' },
100
99
  },
101
- required: ['item', 'status'],
100
+ required: ['status'],
102
101
  },
103
102
  },
104
103
  },
@@ -207,7 +206,7 @@ export const TOOL_TEXTS: Record<string, ToolText> = {
207
206
  [TRACK_TOOL]: {
208
207
  label: 'Task status',
209
208
  description: TRACK_DESCRIPTION,
210
- brief: `set a track item's status or add an item, found by words of its name, several at once with items; without an item, the task's own status in \`${TASK_LIST}\`.`,
209
+ brief: `set a track item's status by its id or add an item, several at once with items; without either, the task's own status in \`${TASK_LIST}\`.`,
211
210
  schema: TRACK_SCHEMA,
212
211
  },
213
212
  [HISTORY_TOOL]: {
package/core/track.ts CHANGED
@@ -6,9 +6,9 @@ import type { Store } from './store'
6
6
  import { formatTaskLine, taskLine } from './tasks'
7
7
  import type { Item, ItemChange, TrackInput } from './types'
8
8
 
9
- // Statuses set by a tool instead of an edit by hand: a track item found by the words of its name, or a task's own
10
- // line in TASKS.md. Items carry no ids — the records stay clean, and the agent knows the words it wrote; a fragment
11
- // that finds no item or several is refused with the items listed, so the wrong one is never changed.
9
+ // Statuses set by a tool instead of an edit by hand: a track item found by its id, or a task's own line in TASKS.md.
10
+ // An id is the item's `#<n>`, given by the mod when the item is added and never reused in the track: a call names an
11
+ // item in a few characters, not by the words of its name.
12
12
 
13
13
  export async function updateTrack(project: Project, input: TrackInput): Promise<{ deny: string } | { result: string }> {
14
14
  const { store, root } = project
@@ -45,7 +45,7 @@ async function setTaskStatus(
45
45
  return { result: `${TASK_LIST}: ${lines[at]}` }
46
46
  }
47
47
 
48
- // Every change applied to the track in order, then written once: one that finds no item or several writes nothing.
48
+ // Every change applied to the track in order, then written once: one that finds no item writes nothing.
49
49
  async function setItems(
50
50
  store: Store,
51
51
  root: string,
@@ -53,8 +53,9 @@ async function setItems(
53
53
  changes: readonly ItemChange[],
54
54
  ): Promise<{ deny: string } | { result: string }> {
55
55
  const path = taskFile(`${root}/${DIR}`, task, 'track')
56
- let text = await store.read(path)
57
- if (text === null) return { deny: `No ${TASKS}/${task}/track.md: the task is not open.` }
56
+ const read = await store.read(path)
57
+ if (read === null) return { deny: `No ${TASKS}/${task}/track.md: the task is not open.` }
58
+ let text = numberItems(read)
58
59
  const lines: string[] = []
59
60
  for (const [n, change] of changes.entries()) {
60
61
  const applied = applyItem(text, task, change)
@@ -72,29 +73,57 @@ async function setItems(
72
73
  function applyItem(text: string, task: string, change: ItemChange): { deny: string } | { text: string; line: string } {
73
74
  const lines = text.split('\n')
74
75
  const items = itemsOf(text).filter(item => item.status !== '')
75
- const listed = (found: readonly Item[]) => found.map((each, n) => `${n + 1}. ${each.line}`).join('\n')
76
- const wanted = change.item.toLowerCase()
77
76
 
78
- if (change.add) {
79
- if (items.some(each => each.name.toLowerCase() === wanted)) return { deny: `"${change.item}" is already an item of ${task}.` }
80
- const line = formatItem(change.status, change.item, change.note)
77
+ if ('item' in change) {
78
+ const wanted = change.item.toLowerCase()
79
+ const same = items.find(each => each.name.toLowerCase() === wanted)
80
+ if (same !== undefined) return { deny: `"${change.item}" is already an item of ${task}: #${same.id}.` }
81
+ const line = formatItem(change.status, nextId(items), change.item, change.note)
81
82
  const body = text.trimEnd()
82
83
 
83
84
  return { text: `${body === '' ? '' : `${body}\n`}${line}\n`, line }
84
85
  }
85
86
 
86
- const exact = items.filter(each => each.name.toLowerCase() === wanted)
87
- const found = exact.length === 1 ? exact : items.filter(each => each.name.toLowerCase().includes(wanted))
88
- if (found.length > 1) {
89
- return { deny: `"${change.item}" is in ${found.length} items of ${task}:\n${listed(found)}\nCall again with words that find one.` }
87
+ const found = items.find(each => each.id === change.id)
88
+ if (found === undefined) {
89
+ return { deny: `No item #${change.id} in ${task}. Its items:\n${items.map(each => each.line).join('\n')}` }
90
90
  }
91
- const only = found[0]
92
- if (only === undefined) {
93
- return {
94
- deny: `No item of ${task} has "${change.item}" in its name. Its items:\n${listed(items)}\nCall again with words of one of them, or add: true for a new item.`,
91
+ lines[found.index] = formatItem(change.status, change.id, found.name, change.note ?? found.note)
92
+
93
+ return { text: lines.join('\n'), line: lines[found.index] ?? '' }
94
+ }
95
+
96
+ // Ids for the track items without one, or with one an earlier item took — added by hand, or written before items had
97
+ // ids — numbered on from the highest; the text as it was when every item has its own.
98
+ export function numberItems(text: string): string {
99
+ const items = itemsOf(text).filter(item => item.status !== '')
100
+ let next = nextId(items)
101
+ const lines = text.split('\n')
102
+ const seen = new Set<number>()
103
+ for (const item of items) {
104
+ if (item.id !== null && !seen.has(item.id)) {
105
+ seen.add(item.id)
106
+ continue
95
107
  }
108
+ lines[item.index] = formatItem(item.status, next++, item.name, item.note)
96
109
  }
97
- lines[only.index] = formatItem(change.status, only.name, change.note ?? only.note)
98
110
 
99
- return { text: lines.join('\n'), line: lines[only.index] ?? '' }
111
+ return lines.join('\n')
112
+ }
113
+
114
+ // Every open task's track numbered where it has items without ids: done at a shift, so the tracks it hands back
115
+ // carry an id on every item.
116
+ export async function numberTracks(project: Project): Promise<void> {
117
+ const { store, root } = project
118
+ for (const task of await store.list(`${root}/${TASKS}`, 'dir')) {
119
+ const path = taskFile(`${root}/${DIR}`, task, 'track')
120
+ const text = await store.read(path)
121
+ if (text === null) continue
122
+ const numbered = numberItems(text)
123
+ if (numbered !== text) await store.write(path, numbered)
124
+ }
125
+ }
126
+
127
+ function nextId(items: readonly Item[]): number {
128
+ return Math.max(0, ...items.map(item => item.id ?? 0)) + 1
100
129
  }
package/core/types.ts CHANGED
@@ -11,9 +11,9 @@ export type Gauge = { base: number | null; hinted: number | null; unassisted: bo
11
11
 
12
12
  export type ShiftInput = { letter: string; after: ShiftAfter; about: string }
13
13
 
14
- // What task_track asks for: an item of a task's track by words of its name, or the task's own line in TASKS.md.
15
- // One track item's change: found by words of its name, or added.
16
- export type ItemChange = { item: string; status: string; note: string | null; add: boolean }
14
+ // What task_track asks for: items of a task's track, or the task's own line in TASKS.md.
15
+ // One track item's change: an item found by its id, or a new item by its text.
16
+ export type ItemChange = ({ id: number } | { item: string }) & { status: string; note: string | null }
17
17
  // Track items changed together, all or none, and the task's own status in TASKS.md.
18
18
  export type TrackInput = { task: string; items: ItemChange[]; own: { status: string; note: string | null } | null }
19
19
 
@@ -33,7 +33,7 @@ export type OpenInput = {
33
33
  export type ArchiveInput = { name: string; outcome: (typeof OUTCOMES)[number]; about: string }
34
34
 
35
35
  // A `- [status] name — note` line of a block: `rest` is all after the status, `index` the line's place in the text.
36
- export type Item = { status: string; name: string; note: string | null; rest: string; line: string; index: number }
36
+ export type Item = { status: string; id: number | null; name: string; note: string | null; rest: string; line: string; index: number }
37
37
 
38
38
  // The board's tasks: status, folder name and the note after the dash.
39
39
  export type FocusTask = { status: string; name: string; line: string }
@@ -126,4 +126,4 @@ export type PendingShift = {
126
126
  export type WaitNote = { context: string; dir: string; files: string[] }
127
127
 
128
128
  // What follows a let-go: the agent goes on from the prompt, or the note waits for the owner; the row tells the owner.
129
- export type Settled = { after: 'continue'; streak: number; prompt: string; row: string } | { after: 'wait'; note: WaitNote; row: string }
129
+ export type Settled = { after: 'continue'; prompt: string; row: string } | { after: 'wait'; note: WaitNote; row: string }
package/index.ts CHANGED
@@ -19,7 +19,6 @@ import {
19
19
  gaugeStatus,
20
20
  letGoGauge,
21
21
  MOD,
22
- ownerSpoke,
23
22
  RESUME_COMMAND,
24
23
  RESUME_DESCRIPTION,
25
24
  resumeShift,
@@ -122,11 +121,9 @@ export default function shift(pi: ExtensionAPI): void {
122
121
  loop = { ...loop, note: last?.type === 'custom' ? ((last.data as { note: WaitNote | null } | undefined)?.note ?? null) : null }
123
122
  })
124
123
 
125
- // The owner's own input, idle or typed mid-run, starts the count of shifts without them over; only a message that
126
- // starts a run takes the waiting letter with it.
127
- pi.on('input', async (event, ctx) => {
124
+ // The owner's own input: only a message that starts a run takes the waiting letter with it.
125
+ pi.on('input', async (event, _ctx) => {
128
126
  if (!enabled || event.source === 'extension') return
129
- await ownerSpoke(loopOf(ctx))
130
127
  if (event.streamingBehavior === undefined) ownerTyped = true
131
128
  })
132
129
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iiiokojiadbi/shift",
3
- "version": "0.1.0",
3
+ "version": "0.29.0",
4
4
  "description": "The agent decides by itself when to shift: it keeps a work board and task folders, writes a letter to itself, and continues from where it stopped.",
5
5
  "license": "MIT",
6
6
  "type": "module",