@iiiokojiadbi/shift 0.37.0 → 0.38.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/track.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // Generated from core/src by scripts/sync-core.ts — edit the source, not this copy.
2
2
  import { ARCHIVE_TOOL, CLOSED, DIR, TASK_LIST, TASKS, taskFile } from './layout'
3
- import { formatItem, itemsOf } from './markdown'
3
+ import { formatItem, itemsOf, trackTimes } from './markdown'
4
4
  import type { Project } from './project'
5
5
  import type { Store } from './store'
6
6
  import { formatTaskLine, taskLine } from './tasks'
@@ -10,11 +10,15 @@ import type { Item, ItemChange, TrackInput } from './types'
10
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
11
  // item in a few characters, not by the words of its name.
12
12
 
13
- export async function updateTrack(project: Project, input: TrackInput): Promise<{ deny: string } | { result: string }> {
13
+ export async function updateTrack(
14
+ project: Project,
15
+ input: TrackInput,
16
+ now: number | null = null,
17
+ ): Promise<{ deny: string } | { result: string }> {
14
18
  const { store, root } = project
15
19
  const done: string[] = []
16
20
  if (input.items.length > 0) {
17
- const items = await setItems(store, root, input.task, input.items)
21
+ const items = await setItems(store, root, input.task, input.items, now)
18
22
  if ('deny' in items) return items
19
23
  done.push(items.result)
20
24
  }
@@ -51,6 +55,7 @@ async function setItems(
51
55
  root: string,
52
56
  task: string,
53
57
  changes: readonly ItemChange[],
58
+ now: number | null,
54
59
  ): Promise<{ deny: string } | { result: string }> {
55
60
  const path = taskFile(`${root}/${DIR}`, task, 'track')
56
61
  const read = await store.read(path)
@@ -58,7 +63,7 @@ async function setItems(
58
63
  let text = numberItems(read)
59
64
  const lines: string[] = []
60
65
  for (const [n, change] of changes.entries()) {
61
- const applied = applyItem(text, task, change)
66
+ const applied = applyItem(text, task, change, now)
62
67
  if ('deny' in applied) return { deny: changes.length === 1 ? applied.deny : `items[${n}]: ${applied.deny}\nNothing was written.` }
63
68
  text = applied.text
64
69
  lines.push(`${task}/track.md: ${applied.line}`)
@@ -70,7 +75,7 @@ async function setItems(
70
75
  return { result: lines.join('\n') }
71
76
  }
72
77
 
73
- function applyItem(text: string, task: string, change: ItemChange): { deny: string } | { text: string; line: string } {
78
+ function applyItem(text: string, task: string, change: ItemChange, now: number | null): { deny: string } | { text: string; line: string } {
74
79
  const lines = text.split('\n')
75
80
  const items = itemsOf(text).filter(item => item.status !== '')
76
81
 
@@ -81,16 +86,18 @@ function applyItem(text: string, task: string, change: ItemChange): { deny: stri
81
86
  const line = formatItem(change.status, nextId(items), change.item, change.note)
82
87
  const body = text.trimEnd()
83
88
 
84
- return { text: `${body === '' ? '' : `${body}\n`}${line}\n`, line }
89
+ return { text: `${body === '' ? '' : `${body}\n`}${line}${trackTimes(now, CLOSED.has(change.status) ? now : null)}\n`, line }
85
90
  }
86
91
 
87
92
  const found = items.find(each => each.id === change.id)
88
93
  if (found === undefined) {
89
94
  return { deny: `No item #${change.id} in ${task}. Its items:\n${items.map(each => each.line).join('\n')}` }
90
95
  }
91
- lines[found.index] = formatItem(change.status, change.id, found.name, change.note ?? found.note)
96
+ const closed = CLOSED.has(change.status) ? (CLOSED.has(found.status) ? found.closed : now) : null
97
+ const line = formatItem(change.status, change.id, found.name, change.note ?? found.note)
92
98
 
93
- return { text: lines.join('\n'), line: lines[found.index] ?? '' }
99
+ lines[found.index] = line + trackTimes(found.created, closed)
100
+ return { text: lines.join('\n'), line }
94
101
  }
95
102
 
96
103
  // Ids for the track items without one, or with one an earlier item took — added by hand, or written before items had
@@ -105,7 +112,7 @@ export function numberItems(text: string): string {
105
112
  seen.add(item.id)
106
113
  continue
107
114
  }
108
- lines[item.index] = formatItem(item.status, next++, item.name, item.note)
115
+ lines[item.index] = formatItem(item.status, next++, item.name, item.note) + trackTimes(item.created, item.closed)
109
116
  }
110
117
 
111
118
  return lines.join('\n')
package/core/types.ts CHANGED
@@ -33,7 +33,17 @@ 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; id: number | null; name: string; note: string | null; rest: string; line: string; index: number }
36
+ export type Item = {
37
+ created: number | null
38
+ closed: number | null
39
+ status: string
40
+ id: number | null
41
+ name: string
42
+ note: string | null
43
+ rest: string
44
+ line: string
45
+ index: number
46
+ }
37
47
 
38
48
  // The board's tasks: status, folder name and the note after the dash.
39
49
  export type FocusTask = { status: string; name: string; line: string }
@@ -98,7 +108,8 @@ export type AboutMeta = {
98
108
  result: string
99
109
  }
100
110
 
101
- export type Reading = { tokens: number | undefined; window: number; threshold: number | undefined }
111
+ export type HintTargets = { soft: number | null; final: number }
112
+ export type Reading = { tokens: number | undefined; window: number; threshold: number | undefined; hintTargets?: HintTargets }
102
113
 
103
114
  export type HistoryEntry = { name: string; about: string | null }
104
115
  // The last shifts' about.md, oldest first, and how many shifts the project has in all.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iiiokojiadbi/shift",
3
- "version": "0.37.0",
3
+ "version": "0.38.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",