also looking at this
fix(app): a fresh install now either works or says why
#8
16 files
+512
-75
Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.
| @@ -392,19 +392,28 @@ export class Uplink { | ||
| 392 | 392 | await this.begin(state, next) |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | /** | |
| 396 | * Answers a control word. `reply` reports whether it delivered, which | |
| 397 | * `finish` acts on for a real answer; a control reply is said and forgotten, | |
| 398 | * so the result is deliberately dropped here. | |
| 399 | */ | |
| 395 | 400 | private async control(command: ControlCommand, target: ReplyTarget): Promise<void> { |
| 396 | 401 | const state = this.chat(target.chatGuid) |
| 397 | 402 | |
| 398 | 403 | switch (command) { |
| 399 | 404 | case 'help': |
| 400 | return this.reply(target, HELP_TEXT) | |
| 405 | await this.reply(target, HELP_TEXT) | |
| 406 | return | |
| 401 | 407 | |
| 402 | 408 | case 'ping': |
| 403 | return this.reply(target, `pong (up ${formatDuration(this.now() - this.startedAt)})`) | |
| 409 | await this.reply(target, `pong (up ${formatDuration(this.now() - this.startedAt)})`) | |
| 410 | return | |
| 404 | 411 | |
| 405 | 412 | case 'status': { |
| 406 | if (!state.active) | |
| 407 | return this.reply(target, 'Idle. Text me a question or a task.') | |
| 413 | if (!state.active) { | |
| 414 | await this.reply(target, 'Idle. Text me a question or a task.') | |
| 415 | return | |
| 416 | } | |
| 408 | 417 | const active = state.active |
| 409 | 418 | const lines = [ |
| 410 | 419 | `Working ${formatDuration(this.now() - active.startedAt)} on: ${truncate(active.prompt, 80)}`, |
| @@ -412,32 +421,39 @@ export class Uplink { | ||
| 412 | 421 | ] |
| 413 | 422 | if (state.queue.length > 0) |
| 414 | 423 | lines.push(`${state.queue.length} queued.`) |
| 415 | return this.reply(target, lines.join('\n')) | |
| 424 | await this.reply(target, lines.join('\n')) | |
| 425 | return | |
| 416 | 426 | } |
| 417 | 427 | |
| 418 | 428 | case 'stop': { |
| 419 | 429 | const queued = state.queue.splice(0) |
| 420 | 430 | for (const job of queued) |
| 421 | 431 | await this.deps.store.updateRun(job.runId, { status: 'stopped', finishedAt: this.now() }) |
| 422 | if (!state.active) | |
| 423 | return this.reply(target, queued.length > 0 ? `Cleared ${queued.length} queued.` : 'Nothing running.') | |
| 432 | if (!state.active) { | |
| 433 | await this.reply(target, queued.length > 0 ? `Cleared ${queued.length} queued.` : 'Nothing running.') | |
| 434 | return | |
| 435 | } | |
| 424 | 436 | state.active.stoppedByUser = true |
| 425 | 437 | state.active.run.cancel() |
| 426 | 438 | const extra = queued.length > 0 ? ` and cleared ${queued.length} queued` : '' |
| 427 | return this.reply(target, `Stopped: ${truncate(state.active.prompt, 60)}${extra}.`) | |
| 439 | await this.reply(target, `Stopped: ${truncate(state.active.prompt, 60)}${extra}.`) | |
| 440 | return | |
| 428 | 441 | } |
| 429 | 442 | |
| 430 | 443 | case 'new': { |
| 431 | 444 | const conversation = await this.conversation(target) |
| 432 | 445 | await this.deps.store.saveConversation({ ...conversation, sessionId: null, cwd: null, moreText: null }) |
| 433 | return this.reply(target, 'Fresh start. Your next text begins a new conversation.') | |
| 446 | await this.reply(target, 'Fresh start. Your next text begins a new conversation.') | |
| 447 | return | |
| 434 | 448 | } |
| 435 | 449 | |
| 436 | 450 | case 'more': { |
| 437 | 451 | const conversation = await this.conversation(target) |
| 438 | if (!conversation.moreText) | |
| 439 | return this.reply(target, 'Nothing more to send.') | |
| 440 | return this.reply(target, conversation.moreText, { keepRest: true }) | |
| 452 | if (!conversation.moreText) { | |
| 453 | await this.reply(target, 'Nothing more to send.') | |
| 454 | return | |
| 455 | } | |
| 456 | await this.reply(target, conversation.moreText, { keepRest: true }) | |
| 441 | 457 | } |
| 442 | 458 | } |
| 443 | 459 | } |