@iiiokojiadbi/shift 0.35.0 → 0.36.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.
package/core/flows.ts CHANGED
@@ -313,8 +313,9 @@ export async function resumeShift(project: Project): Promise<{ text: string; pro
313
313
  return { text: `No letter.md in any folder of ${SHIFTS}/ — nothing to pick up.` }
314
314
  }
315
315
 
316
- // The records, the last shifts and the documents' remarks as they are now, for the message after a shift.
317
- async function handBack(project: Project, dir: string): Promise<HandedBack> {
316
+ // The records, the last shifts and the documents' remarks as they are now, for the message after a shift. A harness
317
+ // that carries the message into the replacement history reads them before the let-go, not after it.
318
+ export async function handBack(project: Project, dir: string): Promise<HandedBack> {
318
319
  return {
319
320
  work: await readRecords(project),
320
321
  knowledge: project.settings.knowledge,
@@ -390,8 +391,9 @@ export type LetGo = {
390
391
  after: number
391
392
  }
392
393
 
393
- // After the let-go: the summary and the outcome on disk, then continue or wait, as the agent asked.
394
- export async function settleShift(project: Project, letGo: LetGo): Promise<Settled> {
394
+ // After the let-go: the summary and the outcome on disk, then continue or wait, as the agent asked. `back` is what
395
+ // the message hands back, read before the let-go when the harness carries it into the replacement history.
396
+ export async function settleShift(project: Project, letGo: LetGo, back?: HandedBack): Promise<Settled> {
395
397
  const { store } = project
396
398
  const { shift, before, after } = letGo
397
399
  const summary = renderSummary(letGo.messages)
@@ -402,19 +404,19 @@ export async function settleShift(project: Project, letGo: LetGo): Promise<Settl
402
404
  `${shift.dir}/${NAMES.about}`,
403
405
  renderAbout({ ...shift, tokensBefore: before, tokensAfter: after, summaryChars: summary.length, result }),
404
406
  )
405
- const back = await handBack(project, shift.dir)
407
+ const handed = back ?? (await handBack(project, shift.dir))
406
408
  const name = basename(shift.dir)
407
409
 
408
- const files = deliveredFiles(back.work)
410
+ const files = deliveredFiles(handed.work)
409
411
  if (shift.after === 'continue') {
410
412
  await outcome(OUTCOME.continuing(shrank))
411
- const prompt = continuePrompt(shift.letter, back)
413
+ const prompt = continuePrompt(shift.letter, handed)
412
414
 
413
415
  return { after: 'continue', prompt, note: { context: prompt, dir: shift.dir, files }, row: CONTINUING(name, shrank, shift.dir) }
414
416
  }
415
417
 
416
418
  await outcome(OUTCOME.waiting(shrank, 'waiting for the owner'))
417
- const note = { context: waitContext(shift.letter, back), dir: shift.dir, files }
419
+ const note = { context: waitContext(shift.letter, handed), dir: shift.dir, files }
418
420
 
419
421
  return { after: 'wait', note, row: WAITING(name, shrank) }
420
422
  }
package/core/loop.ts CHANGED
@@ -1,9 +1,19 @@
1
1
  // Generated from core/src by scripts/sync-core.ts — edit the source, not this copy.
2
- import { settleShift, shiftNotMade, shiftUnsettled } from './flows'
2
+ import { handBack, settleShift, shiftNotMade, shiftUnsettled } from './flows'
3
3
  import { type GaugeKeeper, offerHint, takeHint } from './hint'
4
4
  import { basename } from './paths'
5
5
  import type { Project } from './project'
6
- import { compactInstructions, FAILURE_NOTE, HELD_NOTE, NOT_MADE_NOTE, ourWords, SHIFT_NOW, UNSETTLED_NOTE } from './texts/prompts'
6
+ import {
7
+ compactInstructions,
8
+ continuePrompt,
9
+ FAILURE_NOTE,
10
+ HELD_NOTE,
11
+ NOT_MADE_NOTE,
12
+ ourWords,
13
+ SHIFT_NOW,
14
+ UNSETTLED_NOTE,
15
+ WAKE,
16
+ } from './texts/prompts'
7
17
  import { DELIVERED, NOT_CONTINUED } from './texts/rows'
8
18
  import type { PendingShift, Settled, WaitNote } from './types'
9
19
 
@@ -42,10 +52,13 @@ export type Loop = {
42
52
  export type LetGoHarness = {
43
53
  // How full the history is now; undefined before the first reading.
44
54
  fill(): Promise<number | undefined>
45
- // Lets the history go with the instructions: what it went into and the fills around it, or why it did not.
55
+ // Lets the history go with the instructions: what it went into and the fills around it, or why it did not. `carry`
56
+ // is the message a harness able to put it into the replacement history takes; `carried` says that it did, and then
57
+ // the message is never told again as the turn's prompt.
46
58
  letGo(
47
59
  instructions: string,
48
- ): Promise<{ messages: readonly { role: string; text: string }[]; before?: number; after?: number } | { skip: string }>
60
+ carry?: string,
61
+ ): Promise<{ messages: readonly { role: string; text: string }[]; before?: number; after?: number; carried?: boolean } | { skip: string }>
49
62
  // Starts the agent's next turn with the prompt, and what the owner's held messages carried besides their text.
50
63
  continueWith(prompt: string, attachments?: readonly unknown[]): Promise<void>
51
64
  // What the harness refreshes once the history is let go, before the message after it.
@@ -108,7 +121,12 @@ async function letGoShift(project: Project, loop: Loop, harness: LetGoHarness, s
108
121
  return
109
122
  }
110
123
 
111
- const done = await harness.letGo(compactInstructions(shift)).catch((error: unknown) => ({ skip: `the let-go failed: ${String(error)}` }))
124
+ // A continue shift's message is built before the let-go: a harness able to put it into the replacement history takes
125
+ // it there, so everything admitted after the compaction reads the letter first.
126
+ const back = shift.after === 'continue' ? await handBack(project, shift.dir).catch(() => null) : null
127
+ const done = await harness
128
+ .letGo(compactInstructions(shift), back === null ? undefined : continuePrompt(shift.letter, back))
129
+ .catch((error: unknown) => ({ skip: `the let-go failed: ${String(error)}` }))
112
130
  if ('skip' in done) {
113
131
  // The harness's reason, in the mod's words wherever it goes: the note, the row and about.md.
114
132
  const why = ourWords(done.skip)
@@ -119,12 +137,16 @@ async function letGoShift(project: Project, loop: Loop, harness: LetGoHarness, s
119
137
  let settled: Settled
120
138
  try {
121
139
  await harness.afterLetGo?.()
122
- settled = await settleShift(project, {
123
- shift,
124
- messages: done.messages,
125
- before: done.before ?? before,
126
- after: done.after ?? (await harness.fill()) ?? 0,
127
- })
140
+ settled = await settleShift(
141
+ project,
142
+ {
143
+ shift,
144
+ messages: done.messages,
145
+ before: done.before ?? before,
146
+ after: done.after ?? (await harness.fill()) ?? 0,
147
+ },
148
+ back ?? undefined,
149
+ )
128
150
  } catch (error) {
129
151
  const why = ourWords(String(error))
130
152
  loop.tell(await shiftUnsettled(project, shift, why, done.before ?? before), 'error')
@@ -140,7 +162,11 @@ async function letGoShift(project: Project, loop: Loop, harness: LetGoHarness, s
140
162
  // The shift is settled and written; a turn that does not start is told, not recorded against it, and its letter
141
163
  // waits for the owner's next message as after a wait. A letter an earlier shift left waiting is older than this one.
142
164
  await dropWaiting(loop).catch(() => undefined)
143
- await finish(loop, harness, settled.prompt, settled.note)
165
+ // A message the harness carried is in the history already: the turn starts from one line, never the whole message
166
+ // told twice. A note kept for a turn that did not start carries that line too.
167
+ const carried = done.carried === true
168
+ const text = carried ? WAKE : settled.prompt
169
+ await finish(loop, harness, text, carried ? { ...settled.note, context: text } : settled.note)
144
170
  }
145
171
 
146
172
  // 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,
@@ -208,6 +208,10 @@ export function continuePrompt(letter: string, back: HandedBack): string {
208
208
  return shiftMessage('Shift done. You continue from where you stopped.', letter, back, [GUIDE_KNOWN, `Continue from "${NEXT}".`])
209
209
  }
210
210
 
211
+ // The turn after a let-go whose message the harness already put into the replacement history: the letter, the board
212
+ // and the tasks are above this line, so only the turn has to be started, never the message told twice.
213
+ export const WAKE = `The shift is done and your letter is above. Continue from "${NEXT}".`
214
+
211
215
  export function waitContext(letter: string, back: HandedBack): string {
212
216
  return shiftMessage("You shifted and waited for the owner; the owner's message comes with this one.", letter, back, [GUIDE_KNOWN])
213
217
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iiiokojiadbi/shift",
3
- "version": "0.35.0",
3
+ "version": "0.36.1",
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",