@gbrennon/good-news-everyone 0.0.0-stage → 0.2.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.
Files changed (45) hide show
  1. package/README.md +93 -2
  2. package/docs/assets/notification-complete.png +0 -0
  3. package/docs/assets/notification-error.png +0 -0
  4. package/docs/assets/notification-question.png +0 -0
  5. package/package.json +46 -4
  6. package/scripts/install.sh +72 -0
  7. package/src/contracts/agent_outcome.ts +1 -0
  8. package/src/contracts/agent_stop_reason.ts +1 -0
  9. package/src/contracts/hook_api.ts +37 -0
  10. package/src/contracts/hook_content_block.ts +7 -0
  11. package/src/contracts/hook_event_context.ts +7 -0
  12. package/src/contracts/hook_exec_options.ts +6 -0
  13. package/src/contracts/hook_execution_result.ts +8 -0
  14. package/src/contracts/index.ts +17 -0
  15. package/src/contracts/notification_event.ts +1 -0
  16. package/src/contracts/scheduled_task.ts +6 -0
  17. package/src/contracts/scheduler.ts +8 -0
  18. package/src/contracts/settle_content_block.ts +7 -0
  19. package/src/contracts/settle_context.ts +8 -0
  20. package/src/contracts/settle_event.ts +13 -0
  21. package/src/contracts/settle_message.ts +11 -0
  22. package/src/contracts/tool_input_payload.ts +7 -0
  23. package/src/contracts/tool_result_event.ts +12 -0
  24. package/src/contracts/tool_result_patch.ts +8 -0
  25. package/src/default_extension/default_extension.ts +83 -0
  26. package/src/default_extension/index.ts +2 -0
  27. package/src/index.ts +29 -0
  28. package/src/notification_command.ts +340 -0
  29. package/src/notification_hook_service/index.ts +1 -0
  30. package/src/notification_hook_service/notification_hook_service.ts +460 -0
  31. package/src/notification_hook_service/notification_template.ts +9 -0
  32. package/src/notification_hooks_extension/agent_lifecycle.ts +1 -0
  33. package/src/notification_hooks_extension/index.ts +2 -0
  34. package/src/notification_hooks_extension/notification_hooks_extension.ts +70 -0
  35. package/src/notification_settings.ts +219 -0
  36. package/src/notification_taglines/index.ts +3 -0
  37. package/src/notification_taglines/notification_tagline.ts +4 -0
  38. package/src/notification_taglines/notification_tagline_selector.ts +87 -0
  39. package/src/notification_taglines/random_source.ts +17 -0
  40. package/src/omp.ts +5 -0
  41. package/src/reminder_coordinator/index.ts +2 -0
  42. package/src/reminder_coordinator/pending_reminder.ts +11 -0
  43. package/src/reminder_coordinator/reminder_coordinator.ts +88 -0
  44. package/src/reminder_coordinator/reminder_resend.ts +1 -0
  45. package/src/system_scheduler.ts +18 -0
package/README.md CHANGED
@@ -1,3 +1,94 @@
1
- # Temporary Holding Version
1
+ # Good News, Everyone!
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
+ Native TypeScript lifecycle notification hook for the Pi coding agent.
4
+ It announces your agent's state changes, both the good and the not-so-good.
5
+
6
+ > [!NOTE]
7
+ > If you are viewing this repository elsewhere, please be aware that it may be
8
+ > a read-only mirror. The original repository lives on Codeberg:
9
+ > <https://codeberg.org/gbrennon/good-news-everyone>.
10
+
11
+ ## About the name
12
+
13
+ The project's name and its connection to the notification behavior are explained in
14
+ [`docs/name.md`](docs/name.md).
15
+
16
+ ## Notification details
17
+
18
+ See [`docs/notifications.md`](docs/notifications.md) for taglines and reminder behavior.
19
+
20
+ ### Screenshots
21
+
22
+ #### Question notification
23
+
24
+ ![Question notification](docs/assets/notification-question.png)
25
+
26
+ Shown when the agent needs input before it can continue.
27
+
28
+ #### Completion notification
29
+
30
+ ![Completion notification](docs/assets/notification-complete.png)
31
+
32
+ Shown when the agent completes its work successfully.
33
+
34
+ #### Error notification
35
+
36
+ ![Error notification](docs/assets/notification-error.png)
37
+
38
+ Shown when the agent fails or is aborted.
39
+
40
+ ## Installation
41
+
42
+ ### From npm
43
+
44
+ Install the published package with the host package manager:
45
+
46
+ ```bash
47
+ pi install npm:@gbrennon/good-news-everyone@0.1.0
48
+ omp plugin install @gbrennon/good-news-everyone@0.1.0
49
+ ```
50
+
51
+ Pi loads `src/index.ts`; OMP loads the dedicated `src/omp.ts` entrypoint.
52
+ Restart the host after installing or updating the package.
53
+
54
+ ### From this checkout
55
+
56
+ Use the installer script when installing from a repository checkout:
57
+
58
+ ```bash
59
+ ./scripts/install.sh pi
60
+ ./scripts/install.sh omp
61
+ ```
62
+
63
+ Omit the agent name to install for both hosts:
64
+
65
+ ```bash
66
+ ./scripts/install.sh
67
+ ```
68
+
69
+ The script installs the current checkout path through the Pi or OMP package
70
+ manager, so it uses the entrypoints and command code in this checkout rather
71
+ than a potentially stale published version. It also removes known legacy
72
+ manually copied notification hooks. It requires `pi` and/or `omp` on `PATH`.
73
+
74
+ ## Overview
75
+
76
+ - Dispatches notifications on `ui_prompt_start` (input needed) and
77
+ `agent_settled` (complete/error) via `notify-send`.
78
+ - Tracks the latest turn outcome per workspace directory.
79
+ - Re-sends unhandled `question` (input needed) notifications on a fixed interval until the user
80
+ responds, the session shuts down, or a reminder cap is reached.
81
+
82
+ ## Architecture
83
+
84
+ See [`docs/architecture.md`](docs/architecture.md) for compatibility and component details.
85
+
86
+ ## Automated releases
87
+
88
+ See [`docs/releases.md`](docs/releases.md) for the release process and required repository secrets.
89
+
90
+ ## Verification
91
+
92
+ ```bash
93
+ bun test
94
+ ```
package/package.json CHANGED
@@ -1,6 +1,48 @@
1
1
  {
2
2
  "name": "@gbrennon/good-news-everyone",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Notifications from your AI agent, both the good and the not-so-good",
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "exports": {
8
+ ".": "./src/index.ts",
9
+ "./omp": "./src/omp.ts"
10
+ },
11
+ "files": [
12
+ "README.md",
13
+ "docs/assets",
14
+ "scripts/install.sh",
15
+ "src"
16
+ ],
17
+ "keywords": [
18
+ "pi-package",
19
+ "omp-plugin",
20
+ "notifications",
21
+ "ai-agent"
22
+ ],
23
+ "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://codeberg.org/gbrennon/good-news-everyone.git"
27
+ },
28
+ "bugs": {
29
+ "url": "https://codeberg.org/gbrennon/good-news-everyone/issues"
30
+ },
31
+ "homepage": "https://codeberg.org/gbrennon/good-news-everyone",
32
+ "pi": {
33
+ "extensions": [
34
+ "./src/index.ts"
35
+ ]
36
+ },
37
+ "omp": {
38
+ "extensions": [
39
+ "./src/omp.ts"
40
+ ]
41
+ },
42
+ "scripts": {
43
+ "test": "bun test"
44
+ },
45
+ "devDependencies": {
46
+ "bun-types": "^1.3.14"
47
+ }
48
+ }
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+
4
+ root_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
5
+ package_name="@gbrennon/good-news-everyone"
6
+
7
+ if [[ "$#" -gt 1 ]]; then
8
+ printf 'usage: %s [pi|omp]\n' "$0" >&2
9
+ exit 2
10
+ fi
11
+
12
+ if [[ "$#" == 1 && "$1" != "pi" && "$1" != "omp" ]]; then
13
+ printf 'unsupported agent: %s\n' "$1" >&2
14
+ printf 'usage: %s [pi|omp]\n' "$0" >&2
15
+ exit 2
16
+ fi
17
+
18
+ if [[ "$#" == 1 ]]; then
19
+ agents=("$1")
20
+ else
21
+ agents=(pi omp)
22
+ fi
23
+
24
+ remove_legacy_hooks() {
25
+ local agent="$1"
26
+ local extension_dir
27
+ case "$agent" in
28
+ pi)
29
+ extension_dir="${HOME}/.pi/agent/extensions"
30
+ ;;
31
+ omp)
32
+ extension_dir="${HOME}/.omp/agent/extensions"
33
+ ;;
34
+ esac
35
+
36
+ rm -f \
37
+ "$extension_dir/ai-toolkit-notify.ts" \
38
+ "$extension_dir/ai-toolkit-notify-hook.ts" \
39
+ "$extension_dir/gb-agent-notifications-hook.ts" \
40
+ "$extension_dir/good-news-everyone-hook.ts"
41
+ if [[ "$agent" == "omp" ]]; then
42
+ rm -f "${HOME}/.omp/agent/hooks/post/ai-toolkit-notify.ts"
43
+ fi
44
+ }
45
+
46
+ install_agent() {
47
+ local agent="$1"
48
+ case "$agent" in
49
+ pi)
50
+ command -v pi >/dev/null 2>&1 || {
51
+ printf 'required command not found: pi\n' >&2
52
+ exit 1
53
+ }
54
+ pi remove "npm:${package_name}" >/dev/null 2>&1 || true
55
+ pi remove "$root_dir" >/dev/null 2>&1 || true
56
+ pi install "$root_dir" --approve
57
+ ;;
58
+ omp)
59
+ command -v omp >/dev/null 2>&1 || {
60
+ printf 'required command not found: omp\n' >&2
61
+ exit 1
62
+ }
63
+ omp plugin install "$root_dir" --force
64
+ ;;
65
+ esac
66
+ remove_legacy_hooks "$agent"
67
+ printf 'installed checkout for %s through the package manager\n' "$agent"
68
+ }
69
+
70
+ for agent in "${agents[@]}"; do
71
+ install_agent "$agent"
72
+ done
@@ -0,0 +1 @@
1
+ export type AgentOutcome = "completed" | "aborted" | "error";
@@ -0,0 +1 @@
1
+ export type AgentStopReason = "stop" | "length" | "toolUse" | "error" | "aborted";
@@ -0,0 +1,37 @@
1
+ import type { HookEventContext } from "./hook_event_context";
2
+ import type { HookExecOptions } from "./hook_exec_options";
3
+ import type { HookExecutionResult } from "./hook_execution_result";
4
+ import type { SettleEvent } from "./settle_event";
5
+ import type { ToolResultEvent } from "./tool_result_event";
6
+ import type { ToolResultPatch } from "./tool_result_patch";
7
+
8
+ /**
9
+ * Register lifecycle handlers and execute commands in the active workspace.
10
+ */
11
+ export interface HookApi {
12
+ on(
13
+ event: "tool_result",
14
+ handler: (
15
+ event: ToolResultEvent,
16
+ ctx: HookEventContext,
17
+ ) => Promise<ToolResultPatch | undefined>,
18
+ ): void;
19
+ on(
20
+ event:
21
+ | "ui_prompt_start"
22
+ | "agent_start"
23
+ | "agent_end"
24
+ | "agent_before_settle"
25
+ | "agent_settled"
26
+ | "session_shutdown",
27
+ handler: (
28
+ event: SettleEvent,
29
+ ctx: HookEventContext,
30
+ ) => Promise<void> | void,
31
+ ): void;
32
+ exec(
33
+ command: string,
34
+ args: readonly string[],
35
+ options: HookExecOptions,
36
+ ): Promise<HookExecutionResult>;
37
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Represent a text content block from a hook event.
3
+ */
4
+ export interface HookContentBlock {
5
+ readonly type: "text";
6
+ readonly text: string;
7
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Identify the workspace and optional session for a hook event.
3
+ */
4
+ export interface HookEventContext {
5
+ readonly cwd: string;
6
+ readonly sessionId?: string;
7
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Configure an external command execution.
3
+ */
4
+ export interface HookExecOptions {
5
+ readonly cwd: string;
6
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Report the result of an external command execution.
3
+ */
4
+ export interface HookExecutionResult {
5
+ readonly code: number;
6
+ readonly stdout: string;
7
+ readonly stderr: string;
8
+ }
@@ -0,0 +1,17 @@
1
+ export type { AgentOutcome } from "./agent_outcome";
2
+ export type { AgentStopReason } from "./agent_stop_reason";
3
+ export type { HookApi } from "./hook_api";
4
+ export type { HookContentBlock } from "./hook_content_block";
5
+ export type { HookEventContext } from "./hook_event_context";
6
+ export type { HookExecOptions } from "./hook_exec_options";
7
+ export type { HookExecutionResult } from "./hook_execution_result";
8
+ export type { NotificationEvent } from "./notification_event";
9
+ export type { ScheduledTask } from "./scheduled_task";
10
+ export type { Scheduler } from "./scheduler";
11
+ export type { SettleContentBlock } from "./settle_content_block";
12
+ export type { SettleContext } from "./settle_context";
13
+ export type { SettleEvent } from "./settle_event";
14
+ export type { SettleMessage } from "./settle_message";
15
+ export type { ToolInputPayload } from "./tool_input_payload";
16
+ export type { ToolResultEvent } from "./tool_result_event";
17
+ export type { ToolResultPatch } from "./tool_result_patch";
@@ -0,0 +1 @@
1
+ export type NotificationEvent = "question" | "complete" | "error";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Cancel one scheduled callback.
3
+ */
4
+ export interface ScheduledTask {
5
+ cancel(): void;
6
+ }
@@ -0,0 +1,8 @@
1
+ import type { ScheduledTask } from "./scheduled_task";
2
+
3
+ /**
4
+ * Schedule callbacks for later execution.
5
+ */
6
+ export interface Scheduler {
7
+ schedule(callback: () => void, delayMs: number): ScheduledTask;
8
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Represent a text content block in a settlement message.
3
+ */
4
+ export interface SettleContentBlock {
5
+ readonly type: "text";
6
+ readonly text: string;
7
+ }
@@ -0,0 +1,8 @@
1
+ import type { SettleMessage } from "./settle_message";
2
+
3
+ /**
4
+ * Provide prior context messages for a settlement event.
5
+ */
6
+ export interface SettleContext {
7
+ readonly contextMessages?: readonly SettleMessage[];
8
+ }
@@ -0,0 +1,13 @@
1
+ import type { AgentOutcome } from "./agent_outcome";
2
+ import type { SettleContext } from "./settle_context";
3
+ import type { SettleMessage } from "./settle_message";
4
+
5
+ /**
6
+ * Describe the outcome and messages reported by an agent.
7
+ */
8
+ export interface SettleEvent {
9
+ readonly aborted?: boolean;
10
+ readonly context?: SettleContext;
11
+ readonly messages?: readonly SettleMessage[];
12
+ readonly outcome?: AgentOutcome;
13
+ }
@@ -0,0 +1,11 @@
1
+ import type { AgentStopReason } from "./agent_stop_reason";
2
+ import type { SettleContentBlock } from "./settle_content_block";
3
+
4
+ /**
5
+ * Represent one message reported during agent settlement.
6
+ */
7
+ export interface SettleMessage {
8
+ readonly role: string;
9
+ readonly content?: string | readonly SettleContentBlock[];
10
+ readonly stopReason?: AgentStopReason;
11
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Provide tool input path information when available.
3
+ */
4
+ export interface ToolInputPayload {
5
+ readonly path?: string;
6
+ readonly filePath?: string;
7
+ }
@@ -0,0 +1,12 @@
1
+ import type { HookContentBlock } from "./hook_content_block";
2
+ import type { ToolInputPayload } from "./tool_input_payload";
3
+
4
+ /**
5
+ * Report the result produced by a tool invocation.
6
+ */
7
+ export interface ToolResultEvent {
8
+ readonly isError?: boolean;
9
+ readonly toolName: string;
10
+ readonly input: ToolInputPayload;
11
+ readonly content: readonly HookContentBlock[];
12
+ }
@@ -0,0 +1,8 @@
1
+ import type { HookContentBlock } from "./hook_content_block";
2
+
3
+ /**
4
+ * Replace the visible tool result content.
5
+ */
6
+ export interface ToolResultPatch {
7
+ readonly content: readonly HookContentBlock[];
8
+ }
@@ -0,0 +1,83 @@
1
+ import type { HookApi } from "../contracts";
2
+ import { NotificationHookService } from "../notification_hook_service";
3
+ import { NotificationTaglineSelector } from "../notification_taglines";
4
+ import type { AgentLifecycle } from "../notification_hooks_extension";
5
+ import { NotificationHooksExtension } from "../notification_hooks_extension";
6
+ import { NotificationSettingsStore } from "../notification_settings";
7
+ import { ReminderCoordinator } from "../reminder_coordinator";
8
+ import { SystemScheduler } from "../system_scheduler";
9
+ import {
10
+ registerNotificationCommand,
11
+ type NotificationCommandHostApi,
12
+ } from "../notification_command";
13
+
14
+ /**
15
+ * Compose and expose the production notification extension.
16
+ */
17
+ export class DefaultExtension {
18
+ private readonly extension: NotificationHooksExtension;
19
+ private readonly settingsStore: NotificationSettingsStore;
20
+ private readonly service: NotificationHookService;
21
+
22
+ public constructor(agentName = process.env.PI_HOOK_AGENT ?? "pi") {
23
+ const settingsStore = new NotificationSettingsStore();
24
+ const settings = settingsStore.load();
25
+ const reminders = new ReminderCoordinator(
26
+ new SystemScheduler(),
27
+ DefaultExtension.readPositiveInteger(
28
+ process.env.PI_NOTIFY_REMINDER_INTERVAL_MS,
29
+ 120_000,
30
+ ),
31
+ DefaultExtension.readPositiveInteger(
32
+ process.env.PI_NOTIFY_MAX_REMINDERS,
33
+ 3,
34
+ ),
35
+ );
36
+ const service = new NotificationHookService(
37
+ agentName,
38
+ reminders,
39
+ new NotificationTaglineSelector(),
40
+ settings.mode,
41
+ settings.completeKind,
42
+ );
43
+ this.settingsStore = settingsStore;
44
+ this.service = service;
45
+ this.extension = new NotificationHooksExtension(
46
+ service,
47
+ DefaultExtension.lifecycleForAgent(agentName),
48
+ );
49
+ }
50
+
51
+ /**
52
+ * Register the configured notification extension on a hook API.
53
+ */
54
+ public register(api: HookApi): void {
55
+ this.extension.register(api);
56
+ const agentApi = api as { agent?: { kind?: "main" | "sub" } };
57
+ this.service.setAgentKind(agentApi.agent?.kind);
58
+ if ("registerCommand" in api) {
59
+ const hostApi = api as unknown as NotificationCommandHostApi;
60
+ registerNotificationCommand(
61
+ hostApi,
62
+ this.settingsStore,
63
+ this.service,
64
+ );
65
+ }
66
+ }
67
+
68
+ private static lifecycleForAgent(agent: string): AgentLifecycle {
69
+ return agent === "omp" ? "end" : "settled";
70
+ }
71
+
72
+ private static readPositiveInteger(
73
+ value: string | undefined,
74
+ fallback: number,
75
+ ): number {
76
+ const parsed = Number.parseInt(value ?? "", 10);
77
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
78
+ }
79
+ }
80
+
81
+ const defaultExtension = new DefaultExtension();
82
+
83
+ export default defaultExtension.register.bind(defaultExtension);
@@ -0,0 +1,2 @@
1
+ export { DefaultExtension } from "./default_extension";
2
+ export { default } from "./default_extension";
package/src/index.ts ADDED
@@ -0,0 +1,29 @@
1
+ export type {
2
+ AgentOutcome,
3
+ AgentStopReason,
4
+ HookApi,
5
+ HookContentBlock,
6
+ HookEventContext,
7
+ HookExecOptions,
8
+ HookExecutionResult,
9
+ NotificationEvent,
10
+ ScheduledTask,
11
+ Scheduler,
12
+ SettleContentBlock,
13
+ SettleContext,
14
+ SettleEvent,
15
+ SettleMessage,
16
+ ToolInputPayload,
17
+ ToolResultEvent,
18
+ ToolResultPatch,
19
+ } from "./contracts";
20
+
21
+ export type { AgentLifecycle } from "./notification_hooks_extension";
22
+
23
+ export { NotificationHookService } from "./notification_hook_service";
24
+ export { NotificationTaglineSelector, RandomSource } from "./notification_taglines";
25
+ export { NotificationHooksExtension } from "./notification_hooks_extension";
26
+ export { ReminderCoordinator } from "./reminder_coordinator";
27
+ export { SystemScheduler } from "./system_scheduler";
28
+ export { DefaultExtension } from "./default_extension";
29
+ export { default } from "./default_extension";