kankaku 0.6.5 → 0.7.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.
@@ -81,6 +81,24 @@ export interface SessionTarget {
81
81
  pickTask(pi: ExtensionAPI, ctx: ExtensionContext): Promise<void>;
82
82
  /** `/kankaku task clear`: drops the linked hub task, keeping the rest of the session target. A no-op when none is linked. */
83
83
  clearTask(pi: ExtensionAPI): void;
84
+ /**
85
+ * Set the linked hub task directly, bypassing the picker — the panel's
86
+ * target screen (`adapters/panel/screens/target.ts`) uses this once the
87
+ * user has already chosen a task from its own `SelectList`. Builds the
88
+ * session override from the current {@link effectiveTarget}'s candidate
89
+ * plus `hubTaskId` and appends the session entry, exactly like
90
+ * {@link pickTask}'s own persistence step. A no-op when there is no
91
+ * effective target with a project.
92
+ */
93
+ setTask(pi: ExtensionAPI, hubTaskId: string): void;
94
+ /**
95
+ * `/kankaku target remember` / the panel's "Remember" row: persists the
96
+ * current {@link effectiveTarget}'s `clientId`/`projectId` (never
97
+ * `hubTaskId` — task linking stays session-only) to the project's
98
+ * `.kankaku/config.json`. Returns `false`, without persisting anything,
99
+ * when there is no effective target.
100
+ */
101
+ rememberTarget(): boolean;
84
102
  /** Current effective target (session > project config > repoPaths), regardless of role. */
85
103
  effectiveTarget(): WorkTarget | undefined;
86
104
  /** Which source produced {@link effectiveTarget}. */
@@ -346,6 +364,22 @@ export function createSessionTarget(deps: SessionTargetDeps): SessionTarget {
346
364
  pi.appendEntry<KankakuTargetEntryData>(TARGET_ENTRY_TYPE, {});
347
365
  }
348
366
 
367
+ function setTask(pi: ExtensionAPI, hubTaskId: string): void {
368
+ const target = effectiveTarget();
369
+ if (!target || target.projectId === undefined) return;
370
+
371
+ const ids: WorkTargetCandidate = { ...candidateFrom(target), hubTaskId };
372
+ sessionOverride = ids;
373
+ pi.appendEntry<KankakuTargetEntryData>(TARGET_ENTRY_TYPE, entryDataFrom(ids));
374
+ }
375
+
376
+ function rememberTarget(): boolean {
377
+ const target = effectiveTarget();
378
+ if (!target) return false;
379
+ deps.persistProjectConfig(candidateFrom(target));
380
+ return true;
381
+ }
382
+
349
383
  async function pickTask(pi: ExtensionAPI, ctx: ExtensionContext): Promise<void> {
350
384
  if (deps.role !== "orchestrator" || !ctx.hasUI) return;
351
385
 
@@ -364,9 +398,7 @@ export function createSessionTarget(deps: SessionTargetDeps): SessionTarget {
364
398
  }
365
399
  if (result.kind === "skipped") return;
366
400
 
367
- const ids: WorkTargetCandidate = { ...candidateFrom(target), hubTaskId: result.task.id };
368
- sessionOverride = ids;
369
- pi.appendEntry<KankakuTargetEntryData>(TARGET_ENTRY_TYPE, entryDataFrom(ids));
401
+ setTask(pi, result.task.id);
370
402
 
371
403
  const updated = effectiveTarget();
372
404
  if (updated) ctx.ui.notify(`kankaku: task set to ${formatWorkTargetLabel(updated)}`);
@@ -380,5 +412,20 @@ export function createSessionTarget(deps: SessionTargetDeps): SessionTarget {
380
412
  pi.appendEntry<KankakuTargetEntryData>(TARGET_ENTRY_TYPE, entryDataFrom(rest));
381
413
  }
382
414
 
383
- return { restore, ensurePicked, pick, setExplicit, clear, pickTask, clearTask, effectiveTarget, effectiveSource, runTarget, idleTarget, endRun };
415
+ return {
416
+ restore,
417
+ ensurePicked,
418
+ pick,
419
+ setExplicit,
420
+ clear,
421
+ pickTask,
422
+ clearTask,
423
+ setTask,
424
+ rememberTarget,
425
+ effectiveTarget,
426
+ effectiveSource,
427
+ runTarget,
428
+ idleTarget,
429
+ endRun,
430
+ };
384
431
  }
@@ -0,0 +1,270 @@
1
+ /**
2
+ * Pure model for the `/kankaku` panel (see odd/tasks/kankaku-panel.md): the
3
+ * set of screens, the root menu, an immutable navigation stack, the
4
+ * title/footer-hint text every adapter screen renders from, and pure row
5
+ * builders (e.g. {@link buildTargetRows}) that turn kankaku state into row
6
+ * models for a screen's `SettingsList`. No I/O, no pi imports — see
7
+ * AGENTS.md "Architecture (hexagonal)".
8
+ */
9
+
10
+ import type { WorkTarget } from "./work-target.ts";
11
+
12
+ export type PanelScreenId = "root" | "target" | "report" | "sync" | "export" | "doctor" | "about";
13
+
14
+ /** One row of the root menu (`rootMenu`): a section the panel can navigate to. */
15
+ export interface PanelMenuItem {
16
+ id: PanelScreenId;
17
+ label: string;
18
+ description: string;
19
+ /** Offered only when the hub (PocketBase) is configured; see {@link rootMenu}. */
20
+ hubOnly: boolean;
21
+ }
22
+
23
+ const ROOT_MENU_ITEMS: PanelMenuItem[] = [
24
+ // Not hub-only: the legacy billing label (`/kankaku client <name>`) is
25
+ // set from this same screen and works with no hub configured at all.
26
+ { id: "target", label: "Target", description: "Billing client, project, hub task, legacy label", hubOnly: false },
27
+ { id: "report", label: "Report", description: "Today/all totals, tasks, sessions, clients, projects", hubOnly: false },
28
+ { id: "sync", label: "Sync", description: "Status, sync now, sync all, backfill, catalog refresh", hubOnly: true },
29
+ { id: "export", label: "Export", description: "Write today's or every task as csv/json", hubOnly: false },
30
+ { id: "doctor", label: "Doctor", description: "Orphan/uncertain subagent counts, ancestor detection", hubOnly: false },
31
+ { id: "about", label: "About", description: "Versions, KANKAKU_DIR, env-only config", hubOnly: false },
32
+ ];
33
+
34
+ /**
35
+ * The root menu's rows, in a fixed order. `hubOnly` rows (only `sync`;
36
+ * `target` is not hub-only — see `ROOT_MENU_ITEMS`'s comment) are omitted
37
+ * entirely when the hub is not configured, so the panel offers exactly what
38
+ * `/kankaku` itself would today.
39
+ */
40
+ export function rootMenu(options: { hubConfigured: boolean }): PanelMenuItem[] {
41
+ return ROOT_MENU_ITEMS.filter((item) => options.hubConfigured || !item.hubOnly);
42
+ }
43
+
44
+ /** Immutable navigation stack: `stack[0]` is always `"root"`. */
45
+ export interface PanelNav {
46
+ stack: PanelScreenId[];
47
+ }
48
+
49
+ /** A fresh navigation stack, positioned at the root screen. */
50
+ export function navRoot(): PanelNav {
51
+ return { stack: ["root"] };
52
+ }
53
+
54
+ /** Push a screen onto the stack, returning a new {@link PanelNav}; the input is never mutated. */
55
+ export function navPush(nav: PanelNav, id: PanelScreenId): PanelNav {
56
+ return { stack: [...nav.stack, id] };
57
+ }
58
+
59
+ /**
60
+ * Pop the current screen, returning a new {@link PanelNav} and whether the
61
+ * panel should close. At the root, there is nothing left to pop: the stack
62
+ * is returned unchanged and `closed` is `true` — the caller closes the
63
+ * overlay instead of navigating.
64
+ */
65
+ export function navBack(nav: PanelNav): { nav: PanelNav; closed: boolean } {
66
+ if (nav.stack.length <= 1) {
67
+ return { nav, closed: true };
68
+ }
69
+ return { nav: { stack: nav.stack.slice(0, -1) }, closed: false };
70
+ }
71
+
72
+ /** The screen currently on top of the stack. */
73
+ export function navCurrent(nav: PanelNav): PanelScreenId {
74
+ return nav.stack[nav.stack.length - 1] ?? "root";
75
+ }
76
+
77
+ const SCREEN_TITLES: Record<Exclude<PanelScreenId, "root">, string> = {
78
+ target: "Target",
79
+ report: "Report",
80
+ sync: "Sync",
81
+ export: "Export",
82
+ doctor: "Doctor",
83
+ about: "About",
84
+ };
85
+
86
+ /** The prompt glyph that opens every panel title, the owner's mark for kankaku. */
87
+ export const PANEL_TITLE_PREFIX = ">_";
88
+
89
+ /** `>_ kankaku` at root, `>_ kankaku · <Screen>` on every other screen. */
90
+ export function panelTitle(screen: PanelScreenId): string {
91
+ if (screen === "root") return `${PANEL_TITLE_PREFIX} kankaku`;
92
+ return `${PANEL_TITLE_PREFIX} kankaku · ${SCREEN_TITLES[screen]}`;
93
+ }
94
+
95
+ /** One clickable/keyboard hint shown in the panel's footer. */
96
+ export interface PanelHint {
97
+ key: string;
98
+ label: string;
99
+ }
100
+
101
+ /**
102
+ * The footer hint row for a screen: navigation hints, an optional search
103
+ * hint when the current body supports it, and how Escape/left arrow/`q`
104
+ * behave — back at root closes the panel outright, so root shows only
105
+ * `esc close`; every other screen shows both `esc/← back` and `q close`.
106
+ */
107
+ export function footerHints(screen: PanelScreenId, options: { searchable: boolean }): PanelHint[] {
108
+ const hints: PanelHint[] = [{ key: "↑↓", label: "move" }];
109
+
110
+ if (screen === "root") {
111
+ hints.push({ key: "enter", label: "open" });
112
+ if (options.searchable) hints.push({ key: "/", label: "search" });
113
+ hints.push({ key: "esc", label: "close" });
114
+ return hints;
115
+ }
116
+
117
+ hints.push({ key: "enter", label: "select" });
118
+ if (options.searchable) hints.push({ key: "/", label: "search" });
119
+ hints.push({ key: "esc/←", label: "back" }, { key: "q", label: "close" });
120
+ return hints;
121
+ }
122
+
123
+ /** One row of a `SettingsList`-backed screen (e.g. {@link buildTargetRows}'s output). */
124
+ export interface PanelRow {
125
+ id: string;
126
+ label: string;
127
+ value: string;
128
+ description?: string;
129
+ }
130
+
131
+ const NONE_VALUE = "— none —";
132
+
133
+ /** Pure input for {@link buildTargetRows}. */
134
+ export interface TargetRowsInput {
135
+ /** Whether the hub (PocketBase) is configured; see `rootMenu`'s `target` row, which is offered either way. */
136
+ hubConfigured: boolean;
137
+ /** The current effective hub target, if any (`SessionTarget#effectiveTarget()`). */
138
+ target?: WorkTarget;
139
+ /** Which source produced {@link target} (already formatted by the caller as `"session" | "config" | "repoPaths"`), or `undefined` for none. */
140
+ source?: string;
141
+ /** The current effective legacy billing label (`SessionClient#effectiveClient()`), if any. */
142
+ legacyLabel?: string;
143
+ /** Which source produced {@link legacyLabel} (already formatted by the caller), or `undefined` for none. */
144
+ legacySource?: string;
145
+ }
146
+
147
+ /**
148
+ * Build the target screen's rows from kankaku's current billing-target
149
+ * state. Pure: the caller (`adapters/panel/screens/target.ts`) resolves
150
+ * `target`/`source`/`legacyLabel`/`legacySource` from `SessionTarget`/
151
+ * `SessionClient` and formats each source name as a plain string, so this
152
+ * function never depends on their concrete types.
153
+ *
154
+ * `client`/`project`/`task`/`source`/`remember` are included only when
155
+ * {@link TargetRowsInput.hubConfigured} is `true` — the panel's `target`
156
+ * screen is offered either way (see `rootMenu`), but those rows only make
157
+ * sense once a hub exists to resolve them against. `legacy` is always
158
+ * included: the legacy billing label works with no hub at all.
159
+ */
160
+ export function buildTargetRows(input: TargetRowsInput): PanelRow[] {
161
+ const rows: PanelRow[] = [];
162
+ const target = input.target;
163
+ const hasClient = target !== undefined;
164
+ const hasProject = target !== undefined && target.projectId !== undefined;
165
+
166
+ if (input.hubConfigured) {
167
+ rows.push({
168
+ id: "client",
169
+ label: "Client",
170
+ value: hasClient ? `${target.clientName} (${target.clientCode})` : NONE_VALUE,
171
+ });
172
+
173
+ rows.push({
174
+ id: "project",
175
+ label: "Project",
176
+ value: hasProject ? (target.projectName ?? NONE_VALUE) : NONE_VALUE,
177
+ ...(hasClient ? {} : { description: "pick a client first" }),
178
+ });
179
+
180
+ rows.push({
181
+ id: "task",
182
+ label: "Task",
183
+ value: hasProject && target.hubTaskTitle !== undefined ? target.hubTaskTitle : NONE_VALUE,
184
+ ...(hasProject ? {} : { description: "pick a project first" }),
185
+ });
186
+
187
+ rows.push({
188
+ id: "source",
189
+ label: "Source",
190
+ value: input.source ?? "none",
191
+ });
192
+
193
+ rows.push({
194
+ id: "remember",
195
+ label: "Remember",
196
+ value: "save to config.json",
197
+ description: "Saves the client and project (never the linked task) to this repository's .kankaku/config.json.",
198
+ });
199
+ }
200
+
201
+ rows.push({
202
+ id: "legacy",
203
+ label: "Legacy label",
204
+ value: input.legacyLabel ?? NONE_VALUE,
205
+ description: `Source: ${input.legacySource ?? "none"}`,
206
+ });
207
+
208
+ return rows;
209
+ }
210
+
211
+ /**
212
+ * Pure input for {@link buildAboutRows}. Every env-only value is passed in
213
+ * already extracted from `KankakuConfig` (see `config.ts`) rather than the
214
+ * config object itself: `KankakuConfig` lives outside `src/domain/`, and
215
+ * this module must import nothing but `src/domain/`/`src/ports/` (see
216
+ * AGENTS.md "Architecture (hexagonal)").
217
+ */
218
+ export interface AboutRowsInput {
219
+ /** kankaku's own version (`adapters/agent-info.ts#resolvePluginVersion`). */
220
+ pluginVersion?: string;
221
+ /** pi's version (`adapters/agent-info.ts#resolveAgentVersion`). */
222
+ agentVersion?: string;
223
+ /** This session's resolved kankaku directory (`adapters/kankaku-dir.ts#resolveKankakuDir`). */
224
+ kankakuDir: string;
225
+ /** The hub (PocketBase) URL, when configured. */
226
+ hubUrl?: string;
227
+ /** `KankakuConfig.interactiveTools`. */
228
+ interactiveTools: string[];
229
+ /** `KankakuConfig.segmentRules.length`. */
230
+ segmentRuleCount: number;
231
+ /** `KankakuConfig.subagentProfiles`' ids. */
232
+ subagentProfileNames: string[];
233
+ /** `KankakuConfig.client`. */
234
+ client?: string;
235
+ }
236
+
237
+ /**
238
+ * Build the panel's `about` screen rows: versions, the resolved directory,
239
+ * the hub URL, and every env-only setting (`KANKAKU_INTERACTIVE_TOOLS`,
240
+ * `KANKAKU_SEGMENTS`, `KANKAKU_SUBAGENT_TOOLS`/`KANKAKU_SUBAGENT_CHILD_ENV`,
241
+ * `KANKAKU_CLIENT`) with its env var name as the row's description — every
242
+ * row is read-only (see `screens/about.ts`).
243
+ */
244
+ export function buildAboutRows(input: AboutRowsInput): PanelRow[] {
245
+ return [
246
+ { id: "kankaku", label: "kankaku", value: input.pluginVersion ?? "unknown" },
247
+ { id: "pi", label: "pi", value: input.agentVersion ?? "unknown" },
248
+ { id: "directory", label: "Directory", value: input.kankakuDir },
249
+ { id: "hub", label: "Hub", value: input.hubUrl ?? "not configured" },
250
+ {
251
+ id: "interactive-tools",
252
+ label: "Interactive tools",
253
+ value: input.interactiveTools.length > 0 ? input.interactiveTools.join(", ") : NONE_VALUE,
254
+ description: "KANKAKU_INTERACTIVE_TOOLS",
255
+ },
256
+ {
257
+ id: "segments",
258
+ label: "Segments",
259
+ value: `${input.segmentRuleCount} rule(s)`,
260
+ description: "KANKAKU_SEGMENTS",
261
+ },
262
+ {
263
+ id: "subagent-profiles",
264
+ label: "Subagent profiles",
265
+ value: input.subagentProfileNames.length > 0 ? input.subagentProfileNames.join(", ") : NONE_VALUE,
266
+ description: "KANKAKU_SUBAGENT_TOOLS / KANKAKU_SUBAGENT_CHILD_ENV",
267
+ },
268
+ { id: "client", label: "Client", value: input.client ?? NONE_VALUE, description: "KANKAKU_CLIENT" },
269
+ ];
270
+ }
package/src/extension.ts CHANGED
@@ -184,6 +184,18 @@ export default function kankaku(pi: ExtensionAPI): void {
184
184
  let hubConfigError: string | undefined;
185
185
  let sync: SyncCommandDeps | undefined;
186
186
  let autoSyncEnabled: boolean | undefined;
187
+ let hubUrl: string | undefined;
188
+
189
+ // Resolved once, here (never on a hot path): see README "Hub
190
+ // (PocketBase)" > "Agent and measurement quality" and the panel's `about`
191
+ // screen (`adapters/panel/screens/about.ts`). Both degrade to `undefined`
192
+ // on any failure rather than guessing. Unlike the sync sink below (which
193
+ // needs them only when the hub is configured), the `about` screen shows
194
+ // these regardless — so they are resolved unconditionally here.
195
+ const agentVersion = resolveAgentVersion();
196
+ // extension.ts lives at <package root>/src/extension.ts.
197
+ const pluginPackageRoot = join(dirname(fileURLToPath(import.meta.url)), "..");
198
+ const pluginVersion = resolvePluginVersion(pluginPackageRoot);
187
199
 
188
200
  // `homeDir` is passed as a reference, never invoked here: any failure
189
201
  // resolving it (no HOME, a sandbox) must not fail extension load for
@@ -194,6 +206,7 @@ export default function kankaku(pi: ExtensionAPI): void {
194
206
 
195
207
  if (hub.credentials) {
196
208
  const credentials = hub.credentials;
209
+ hubUrl = credentials.url;
197
210
  const client = new PocketBaseClient({ url: credentials.url, email: credentials.email, password: credentials.password });
198
211
  // Same defensive resolution as above; falls back to the OS temp dir
199
212
  // when no home directory is available so an env-only hub configuration
@@ -226,14 +239,6 @@ export default function kankaku(pi: ExtensionAPI): void {
226
239
  const catalogRef = catalog;
227
240
  const machineName = machine;
228
241
 
229
- // Resolved once, here (never on a hot path): see README "Hub
230
- // (PocketBase)" > "Agent and measurement quality". Both degrade to
231
- // `undefined` on any failure rather than guessing.
232
- const agentVersion = resolveAgentVersion();
233
- // extension.ts lives at <package root>/src/extension.ts.
234
- const pluginPackageRoot = join(dirname(fileURLToPath(import.meta.url)), "..");
235
- const pluginVersion = resolvePluginVersion(pluginPackageRoot);
236
-
237
242
  const runOnce = (options?: { full?: boolean; trigger?: SyncTrigger }) => {
238
243
  const snapshot = catalogRef.read();
239
244
  const sink = new PocketBaseSink({
@@ -309,6 +314,11 @@ export default function kankaku(pi: ExtensionAPI): void {
309
314
  ...(hubConfigError !== undefined ? { hubConfigError } : {}),
310
315
  ...(sync !== undefined ? { sync } : {}),
311
316
  ...(autoSyncEnabled !== undefined ? { autoSyncEnabled } : {}),
317
+ config,
318
+ kankakuDir: resolvedDir,
319
+ ...(agentVersion !== undefined ? { agentVersion } : {}),
320
+ ...(pluginVersion !== undefined ? { pluginVersion } : {}),
321
+ ...(hubUrl !== undefined ? { hubUrl } : {}),
312
322
  ...(roleOverride !== undefined ? { roleOverride } : {}),
313
323
  ...(childMarkerPresent ? { childMarkerPresent } : {}),
314
324
  ...(profile !== undefined ? { profile } : {}),