Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/question-lease-and-labels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@pymodel/pythinker-code': patch
---

Questions no longer expire after 60 seconds, expired questions are not reported as user dismissals, answers retain question text and option labels, and Escape no longer dismisses a question.
8 changes: 4 additions & 4 deletions apps/pythinker-web/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ The browser web UI for Pythinker Code — a peer to the TUI in `apps/pythinker-c
- Shared components go in `src/components/`; reusable logic goes in `src/composables/` with a `use` prefix.
- There is **no auto-import plugin** and **no path alias** — `#/` and `@/` are intentionally unused. Write relative imports (`../i18n`, `./config`).

## i18n (normative — keeping locales in sync is manual)
## i18n (normative — the app is English-only)

- Setup: `src/i18n/index.ts`, vue-i18n in Composition mode (`legacy: false`), fallback `en`. The active locale is persisted in `localStorage` under `pythinker-locale`.
- Locale files: `src/i18n/locales/{en,zh}/<namespace>.ts`, each `export default { ... } as const`. New namespaces are registered in `src/i18n/locales/index.ts`.
- **`en` is the only locale.** `src/i18n/locales/` contains exactly one directory, and `locales/index.ts` registers only `en`. Do not add a second locale, and do not "restore parity" with one that does not exist.
- Locale files: `src/i18n/locales/en/<namespace>.ts`, each `export default { ... } as const`. New namespaces are registered in `src/i18n/locales/index.ts`.
- Reference with `const { t } = useI18n()` and `t('namespace.key')` (same form in templates).
- **Adding a key:** add it to **both** `en/<ns>.ts` and `zh/<ns>.ts`. **Adding a namespace:** create the file in both locales **and** register it in `locales/index.ts`.
- There is **no automated missing-key or en/zh parity check**. Keeping the two locales in sync is a manual responsibility — do not leave a key present in only one locale.
- **Adding a key:** add it to `en/<ns>.ts`. **Adding a namespace:** create the file under `en/` **and** register it in `locales/index.ts`.

## Commands

Expand Down
41 changes: 34 additions & 7 deletions apps/pythinker-web/src/components/QuestionCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ const total = computed(() => props.question.questions.length);
const hasPreview = computed(() =>
current.value.options.some((option) => option.preview?.trim()),
);
const now = ref(Date.now());
const remainingMinutes = computed(() => {
const expiresAt = Date.parse(props.question.expiresAt);
if (Number.isNaN(expiresAt)) return undefined;
return Math.ceil((expiresAt - now.value) / 60_000);
});
const leaseWarning = computed(() => {
const expiresAt = Date.parse(props.question.expiresAt);
if (Number.isNaN(expiresAt)) return undefined;
const remainingMs = expiresAt - now.value;
if (remainingMs <= 0 || remainingMs >= 5 * 60_000) return undefined;
if (remainingMs < 60_000) return t('question.expiresSoonSeconds');
const minutes = remainingMinutes.value;
if (minutes === undefined) return undefined;
return t('question.expiresSoon', { minutes });
Comment thread
coderabbitai[bot] marked this conversation as resolved.
});

function goBack(): void {
if (step.value > 0) step.value--;
Expand Down Expand Up @@ -207,17 +223,15 @@ function dismiss(): void {
}

// ---------------------------------------------------------------------------
// Keyboard: number keys pick options for current question, Enter submit, Esc dismiss
// Keyboard: number keys pick options for the current question and Enter submits.
// ---------------------------------------------------------------------------

function handleKeydown(e: KeyboardEvent): void {
const tag = (document.activeElement?.tagName ?? '').toLowerCase();
if (tag === 'input' || tag === 'textarea') return;
// While minimized the options aren't visible, so don't let number keys pick
// an unseen answer; only Escape (dismiss) stays live.
if (minimized.value && e.key !== 'Escape') return;
// While minimized the options are not visible, so keyboard selection is disabled.
if (minimized.value) return;

if (e.key === 'Escape') { e.preventDefault(); dismiss(); return; }
if (e.key === 'Enter') { e.preventDefault(); submit(); return; }

const num = parseInt(e.key, 10);
Expand All @@ -236,15 +250,27 @@ function handleKeydown(e: KeyboardEvent): void {
}
}

onMounted(() => document.addEventListener('keydown', handleKeydown));
onUnmounted(() => document.removeEventListener('keydown', handleKeydown));
let leaseTimer: ReturnType<typeof setInterval> | undefined;

onMounted(() => {
document.addEventListener('keydown', handleKeydown);
leaseTimer = setInterval(() => {
now.value = Date.now();
}, 30_000);
});

onUnmounted(() => {
document.removeEventListener('keydown', handleKeydown);
if (leaseTimer !== undefined) clearInterval(leaseTimer);
});
</script>

<template>
<div class="qcard" :class="{ minimized }">
<!-- Step indicator (multi-question) -->
<div class="qh">
<span class="qtitle">{{ t('question.title') }}</span>
<span v-if="leaseWarning" class="qexpires">{{ leaseWarning }}</span>
<template v-if="total > 1 && !minimized">
<span class="qstep">{{ t('question.step', { current: step + 1, total }) }}</span>
<button class="qnav" :disabled="step === 0" @click="goBack">{{ t('question.prev') }}</button>
Expand Down Expand Up @@ -371,6 +397,7 @@ onUnmounted(() => document.removeEventListener('keydown', handleKeydown));
}
.qtitle { color: var(--blue2); font-weight: 700; }
.qstep { color: var(--muted); font-size: calc(var(--ui-font-size) - 3px); margin-left: 4px; }
.qexpires { color: var(--muted); font-size: calc(var(--ui-font-size) - 3px); margin-left: 4px; }
.qnav {
font-family: var(--mono);
font-size: calc(var(--ui-font-size) - 3px);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1660,6 +1660,7 @@ function toUiQuestion(q: AppQuestionRequest): UIQuestion {
return {
questionId: q.questionId,
sessionId: q.sessionId,
expiresAt: q.expiresAt,
questions: q.questions.map((qi) => ({
id: qi.id,
question: qi.question,
Expand Down
2 changes: 2 additions & 0 deletions apps/pythinker-web/src/i18n/locales/en/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ export default {
dismiss: 'Dismiss',
minimize: 'Minimize',
expand: 'Expand',
expiresSoon: 'Expires in {minutes} min',
expiresSoonSeconds: 'Expires in less than a minute',
Comment thread
coderabbitai[bot] marked this conversation as resolved.
} as const;
1 change: 1 addition & 0 deletions apps/pythinker-web/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export interface QueuedPromptView {
export interface UIQuestion {
questionId: string;
sessionId: string;
expiresAt: string;
questions: {
id: string;
question: string;
Expand Down
122 changes: 122 additions & 0 deletions apps/pythinker-web/test/question-card-lifecycle.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { mount } from '@vue/test-utils';
import { createI18n } from 'vue-i18n';
import { afterEach, describe, expect, it, vi } from 'vitest';

import QuestionCard from '../src/components/QuestionCard.vue';
import type { UIQuestion } from '../src/types';

const i18n = createI18n({
legacy: false,
locale: 'en',
messages: {
en: {
question: {
title: 'Question',
step: '{current}/{total}',
prev: 'Prev',
next: 'Next',
expand: 'Expand',
minimize: 'Minimize',
otherDefault: 'Other',
submit: 'Submit',
dismiss: 'Dismiss',
notes: 'Notes',
notesPlaceholder: 'Add notes on this option',
expiresSoon: 'Expires in {minutes} min',
expiresSoonSeconds: 'Expires in less than a minute',
},
},
},
missingWarn: false,
fallbackWarn: false,
});

const mounted: ReturnType<typeof mount>[] = [];

function question(expiresAt: string): UIQuestion {
return {
questionId: 'qreq_1',
sessionId: 'sess_1',
expiresAt,
questions: [
{
id: 'q1',
question: 'Pick one',
options: [
{ id: 'a', label: 'A' },
{ id: 'b', label: 'B' },
],
},
],
};
}

function mountCard(input: UIQuestion) {
const wrapper = mount(QuestionCard, {
props: { question: input },
global: {
plugins: [i18n],
stubs: {
Markdown: {
props: ['text'],
template: '<pre class="markdown-stub">{{ text }}</pre>',
},
},
},
});
mounted.push(wrapper);
return wrapper;
}

afterEach(() => {
for (const wrapper of mounted.splice(0)) wrapper.unmount();
});

describe('QuestionCard lifecycle', () => {
it('does not dismiss when Escape is pressed', () => {
const wrapper = mountCard(question(new Date(Date.now() + 20 * 60_000).toISOString()));

document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));

expect(wrapper.emitted('dismiss')).toBeUndefined();
});

it('shows an expiry warning within five minutes and hides it at twenty minutes', () => {
const soon = mountCard(question(new Date(Date.now() + 2 * 60_000).toISOString()));
const later = mountCard(question(new Date(Date.now() + 20 * 60_000).toISOString()));

expect(soon.find('.qexpires').text()).toBe('Expires in 2 min');
expect(later.find('.qexpires').exists()).toBe(false);
});

it('hides the expiry warning at five minutes and shows it at four minutes fifty-nine seconds', () => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-01-01T00:00:00.000Z'));
try {
const boundary = mountCard(question(new Date(Date.now() + 5 * 60_000).toISOString()));
const soon = mountCard(question(new Date(Date.now() + 4 * 60_000 + 59_000).toISOString()));

expect(boundary.find('.qexpires').exists()).toBe(false);
expect(soon.find('.qexpires').exists()).toBe(true);
} finally {
vi.useRealTimers();
}
});

it('ignores Enter while minimized', async () => {
const wrapper = mountCard(question(new Date(Date.now() + 20 * 60_000).toISOString()));

document.dispatchEvent(new KeyboardEvent('keydown', { key: '1', bubbles: true }));
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
const answerCount = wrapper.emitted('answer')?.length ?? 0;

expect(answerCount).toBe(1);

await wrapper.find('.qmin').trigger('click');

document.dispatchEvent(new KeyboardEvent('keydown', { key: '1', bubbles: true }));
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));

expect(wrapper.emitted('answer')).toHaveLength(answerCount);
});
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
1 change: 1 addition & 0 deletions apps/pythinker-web/test/question-card-recommended.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function question(overrides: Partial<UIQuestion['questions'][number]> = {}): UIQ
return {
questionId: 'qreq_1',
sessionId: 'sess_1',
expiresAt: new Date(Date.now() + 20 * 60_000).toISOString(),
questions: [
{
id: 'q1',
Expand Down
7 changes: 7 additions & 0 deletions packages/agent-core/src/errors/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const ErrorCodes = {

AGENT_NOT_FOUND: 'agent.not_found',
TURN_AGENT_BUSY: 'turn.agent_busy',
QUESTION_EXPIRED: 'question.expired',

GOAL_ALREADY_EXISTS: 'goal.already_exists',
GOAL_NOT_FOUND: 'goal.not_found',
Expand Down Expand Up @@ -229,6 +230,12 @@ export const PYTHINKER_ERROR_INFO = {
public: true,
action: 'Wait for the current turn to finish or steer it.',
},
'question.expired': {
title: 'Question expired',
retryable: false,
public: true,
action: 'Ask the user again if you still need the answer.',
},

'goal.already_exists': {
title: 'A goal is already active',
Expand Down
Loading
Loading