@leolastforce/chalice-active-task 0.0.0-stage → 0.1.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/README.md CHANGED
@@ -1,3 +1,8 @@
1
- # Temporary Holding Version
1
+ > This is a chalice package, check out github.com/leolastforce/Chalice
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # Active task
4
+ Simple widget tool for the agent to showcase what htey are actively working on during long stretches, hides whilst agent is inactive, tool name is "active_task" with one field; text
5
+
6
+ Resets to nothing at start of everyturn, meaning it must be reset each time by the agent (this is to avoid stale active tasks)
7
+
8
+ extension has a somewhat high chance of being removed from the default chalice ecosystem due to it really not being that useful..
package/index.ts ADDED
@@ -0,0 +1,68 @@
1
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+ import { Type } from "typebox";
3
+ import { ActivityIndicator } from "./indicator.ts";
4
+
5
+ const STATE_ENTRY = "active-task";
6
+
7
+ export default function activeTaskExtension(pi: ExtensionAPI) {
8
+ let text = "";
9
+ let active = false;
10
+
11
+ const updateWidget = (ctx: ExtensionContext): void => {
12
+ if (!ctx.hasUI) return;
13
+ if (!active || !text) {
14
+ ctx.ui.setWidget("active-task", undefined);
15
+ return;
16
+ }
17
+ const activity = text;
18
+ ctx.ui.setWidget("active-task", (tui, theme) => new ActivityIndicator(tui, theme, activity), { placement: "aboveEditor" });
19
+ };
20
+
21
+ const restore = (ctx: ExtensionContext): void => {
22
+ text = "";
23
+ for (const entry of ctx.sessionManager.getBranch()) {
24
+ if (entry.type !== "custom" || entry.customType !== STATE_ENTRY) continue;
25
+ if (typeof entry.data === "string") text = entry.data;
26
+ }
27
+ updateWidget(ctx);
28
+ };
29
+
30
+ pi.on("session_start", (_event, ctx) => restore(ctx));
31
+ pi.on("session_tree", (_event, ctx) => restore(ctx));
32
+ pi.on("agent_start", (_event, ctx) => {
33
+ active = true;
34
+ updateWidget(ctx);
35
+ });
36
+ pi.on("before_agent_start", (_event, ctx) => {
37
+ text = "";
38
+ updateWidget(ctx);
39
+ });
40
+ pi.on("agent_settled", (_event, ctx) => {
41
+ active = false;
42
+ updateWidget(ctx);
43
+ });
44
+
45
+ pi.registerTool({
46
+ name: "active_task",
47
+ label: "Active task",
48
+ description: "Show what you are doing now as one short activity line. The line resets for every new prompt; setting text replaces it and an empty string clears it.",
49
+ promptSnippet: "Show your current activity in one short line",
50
+ promptGuidelines: [
51
+ "Use active_task when starting meaningful work: set text to a short, concrete phrase describing what you are doing now, and replace it when your focus changes.",
52
+ "This is an activity line, not a plan or checklist. Skip updates for trivial answers and do not update it for every tool call. The line resets at the start of every new prompt and hides while idle, so set it once when you begin work and keep it accurate for that request.",
53
+ ],
54
+ parameters: Type.Object({
55
+ text: Type.String({ description: "Current activity, e.g. Investigating session restoration. Empty string clears the line." }),
56
+ }),
57
+ executionMode: "sequential",
58
+ async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
59
+ text = params.text.replace(/\s+/gu, " ").trim();
60
+ pi.appendEntry(STATE_ENTRY, text);
61
+ updateWidget(ctx);
62
+ return {
63
+ content: [{ type: "text", text: text || "Activity cleared" }],
64
+ details: { text },
65
+ };
66
+ },
67
+ });
68
+ }
package/indicator.ts ADDED
@@ -0,0 +1,68 @@
1
+ import type { Theme } from "@earendil-works/pi-coding-agent";
2
+ import { type Component, type TUI, truncateToWidth } from "@earendil-works/pi-tui";
3
+
4
+ const FRAMES = [
5
+ ["·", "✢", "✳", "✶", "✻", "✽", "✻", "✶", "✳", "✢", "·"],
6
+ ["⠁", "⠂", "⠄", "⡀", "⢀", "⠠", "⠐", "⠈"],
7
+ ["·", "·", "•", "•", "●", "●", "•", "•"],
8
+ ["○", "○", "◉", "◉", "●", "●", "◉", "◉"],
9
+ ["·", "·", "✧", "✧", "✦", "✦", "✧", "✧"],
10
+ ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
11
+ ["⠁", "⠃", "⠇", "⠧", "⠷", "⠿", "⠷", "⠧", "⠇", "⠃"],
12
+ ["⠈", "⠉", "⠋", "⠛", "⠟", "⠿", "⠟", "⠛", "⠋", "⠉"],
13
+ ["◴", "◷", "◶", "◵"],
14
+ ["◐", "◓", "◑", "◒"],
15
+ ["◰", "◳", "◲", "◱"],
16
+ ["◇", "◆", "◇", "⋄"],
17
+ ["▪", "◼", "■", "◼"],
18
+ ["▏", "▎", "▍", "▌", "▋", "▊", "▉", "█", "▉", "▊", "▋", "▌", "▍", "▎"],
19
+ ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█", "▇", "▆", "▅", "▄", "▃", "▂"],
20
+ ["⠁", "⠉", "⠙", "⠚", "⠒", "⠲", "⠴", "⠤"],
21
+ ["╱", "─", "╲", "│"],
22
+ ["+", "×", "+", "✳"],
23
+ ["⋄", "✧", "✦", "✧"],
24
+ ["▖", "▘", "▝", "▗"],
25
+ ].flatMap((frames) => Array.from({ length: 40 }, (_, index) => frames[index % frames.length]));
26
+
27
+ export class ActivityIndicator implements Component {
28
+ private frame = 0;
29
+ private wave = 0;
30
+ private readonly spinnerTimer: ReturnType<typeof setInterval>;
31
+ private readonly waveTimer: ReturnType<typeof setInterval>;
32
+ private readonly characters: string[];
33
+ private readonly tui: TUI;
34
+ private readonly theme: Theme;
35
+
36
+ constructor(tui: TUI, theme: Theme, text: string) {
37
+ this.tui = tui;
38
+ this.theme = theme;
39
+ this.characters = Array.from(text);
40
+ this.spinnerTimer = setInterval(() => {
41
+ this.frame = (this.frame + 1) % FRAMES.length;
42
+ this.tui.requestRender();
43
+ }, 80);
44
+ this.waveTimer = setInterval(() => {
45
+ this.wave = (this.wave + 1) % Math.max(1, this.characters.length);
46
+ this.tui.requestRender();
47
+ }, 120);
48
+ }
49
+
50
+ render(width: number): string[] {
51
+ const indicator = this.theme.fg("accent", FRAMES[this.frame]);
52
+ const message = this.characters.map((character, index) => {
53
+ const distance = Math.abs(index - this.wave);
54
+ if (distance > 2) return this.theme.fg("muted", character);
55
+ if (distance === 0) return this.theme.fg("accent", `\x1b[1m\x1b[4m${character}\x1b[24m\x1b[22m`);
56
+ if (distance === 1) return this.theme.fg("accent", `\x1b[1m${character}\x1b[22m`);
57
+ return this.theme.fg("accent", character);
58
+ }).join("");
59
+ return [truncateToWidth(`${indicator} ${truncateToWidth(message, Math.max(0, width - 4))} ${indicator}`, width)];
60
+ }
61
+
62
+ invalidate(): void {}
63
+
64
+ dispose(): void {
65
+ clearInterval(this.spinnerTimer);
66
+ clearInterval(this.waveTimer);
67
+ }
68
+ }
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
- "name": "@leolastforce/chalice-active-task",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@leolastforce/chalice-active-task",
3
+ "version": "0.1.0",
4
+ "description": "Chalice Module for the activity indicator",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "chalice",
9
+ "pi-package"
10
+ ],
11
+ "pi": {
12
+ "extensions": [
13
+ "./index.ts"
14
+ ]
15
+ },
16
+ "files": [
17
+ "index.ts",
18
+ "indicator.ts"
19
+ ],
20
+ "peerDependencies": {
21
+ "@earendil-works/pi-coding-agent": "*",
22
+ "@earendil-works/pi-tui": "*",
23
+ "typebox": "*"
24
+ },
25
+ "peerDependenciesMeta": {
26
+ "@earendil-works/pi-coding-agent": {
27
+ "optional": true
28
+ },
29
+ "@earendil-works/pi-tui": {
30
+ "optional": true
31
+ },
32
+ "typebox": {
33
+ "optional": true
34
+ }
35
+ },
36
+ "engines": {
37
+ "node": ">=22.19.0"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ }
42
+ }