@howaboua/pi-durable-pulses 0.0.0-stage → 0.10.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.
@@ -0,0 +1,6 @@
1
+ import type { Tx } from "@earendil-works/pi-durable";
2
+ import type { PulseCatalogItem } from "./definitions.ts";
3
+ /** Reconcile source state before policy: a pause retains every tracked due slot. */
4
+ export declare function reconcileSchedules(tx: Tx, definitions: readonly PulseCatalogItem[], now: number): Promise<void>;
5
+ /** Transaction-only readiness for cross-source priority. No files or host reads. */
6
+ export declare function explicitReady(tx: Tx, bindingKey: string, now: number): Promise<boolean>;
@@ -0,0 +1,24 @@
1
+ export type { ScheduledQuietHours as PulseQuietHours, ScheduledTiming as PulseSchedule, } from "@howaboua/pi-durable-components";
2
+ import type { ScheduledQuietHours as PulseQuietHours, ScheduledTiming as PulseSchedule } from "@howaboua/pi-durable-components";
3
+ export declare function parsePulseQuietHours(raw: string): PulseQuietHours | null;
4
+ export declare function isPulseQuietAt(quietHours: PulseQuietHours, nowMs: number): boolean;
5
+ export declare function parsePulseSchedule(raw: string): PulseSchedule | null;
6
+ export declare function pulseDueKey(schedule: PulseSchedule, nowMs: number): string | null;
7
+ export declare function isPulseDue(options: {
8
+ schedule: PulseSchedule;
9
+ nowMs: number;
10
+ firstSeenAt?: number | undefined;
11
+ lastRunAt?: number | undefined;
12
+ lastDueKey?: string | undefined;
13
+ }): {
14
+ due: boolean;
15
+ dueKey: string | null;
16
+ };
17
+ /** First untracked slot; discovery never manufactures earlier occurrences. */
18
+ export declare function nextPulseDue(schedule: PulseSchedule, after: number): number | undefined;
19
+ /** Count calendar slots in local time, not elapsed 24h periods across DST. */
20
+ export declare function pulseOccurrences(schedule: PulseSchedule, first: number, now: number): {
21
+ count: number;
22
+ startAt: number;
23
+ endAt: number;
24
+ } | undefined;
@@ -0,0 +1,47 @@
1
+ import { type ConversationId, type TaskId, type Tx } from "@earendil-works/pi-durable";
2
+ import type { PulseOccurrence } from "./contract.ts";
3
+ import type { PulseQuietHours, PulseSchedule } from "./schedule.ts";
4
+ export type PulseReference = {
5
+ conversationId: ConversationId;
6
+ root: string;
7
+ pulseHome: string;
8
+ parentConversationId?: ConversationId;
9
+ target?: "child" | "resident";
10
+ };
11
+ export type PulseDisposition = {
12
+ status: "obsolete" | "superseded";
13
+ reason: string;
14
+ at: number;
15
+ occurrence: PulseOccurrence;
16
+ };
17
+ export type PulseCheckpoint = {
18
+ firstSeenAt: number;
19
+ scheduledEligible?: boolean;
20
+ /** Parsed schedule identity. Missing legacy values seed the current slot on discovery. */
21
+ scheduleKey?: string;
22
+ /** Exact accounting starts here, never inferred from legacy lastRunAt. */
23
+ trackedAt?: number;
24
+ trackedSchedule?: PulseSchedule;
25
+ quietHours?: PulseQuietHours;
26
+ expiresAt?: number;
27
+ nextDueAt?: number;
28
+ pending?: PulseOccurrence;
29
+ blocked?: {
30
+ reason: string;
31
+ retryAt?: number;
32
+ };
33
+ disposition?: PulseDisposition;
34
+ lastRunAt?: number;
35
+ lastDueKey?: string;
36
+ current?: PulseReference;
37
+ history: PulseReference[];
38
+ activeTask?: TaskId;
39
+ };
40
+ export declare const Checkpoints: import("@earendil-works/pi-durable").SessionDocToken<{
41
+ pulses: Record<string, PulseCheckpoint>;
42
+ concurrency?: number;
43
+ backoffUntil?: number;
44
+ }>;
45
+ export declare const pulseKey: (bindingKey: string, id: string) => string;
46
+ /** Repair only missing conversation references from already admitted native task inputs, never rerun work. */
47
+ export declare function restoreMissingReferences(tx: Tx): Promise<void>;
@@ -0,0 +1,28 @@
1
+ import { type Harness, type SettledSubmissionRecord, type Task, type TaskId } from "@earendil-works/pi-durable";
2
+ import type { PulseBinding, PulseOccurrence, PulsesOptions, PulseTrigger } from "./contract.ts";
3
+ import type { PulseDefinition } from "./definitions.ts";
4
+ import type { PulseReference } from "./state.ts";
5
+ export declare const Anchor: Task<null, {
6
+ phase: "done";
7
+ }, null, object>;
8
+ export type PulseRunInput = {
9
+ binding: PulseBinding;
10
+ definition: PulseDefinition;
11
+ reference: PulseReference;
12
+ trigger: PulseTrigger;
13
+ requestId: string;
14
+ /** Absent on native tasks admitted before missed-period tracking. */
15
+ occurrence?: PulseOccurrence;
16
+ };
17
+ type RunState = {
18
+ phase: "dispatch";
19
+ } | {
20
+ phase: "retry";
21
+ after: number;
22
+ } | {
23
+ phase: "deliver";
24
+ outcome: SettledSubmissionRecord;
25
+ };
26
+ export declare const pulseInputRequestId: (taskId: TaskId) => string;
27
+ export declare function createRunTask(host: () => Harness, options: PulsesOptions): Task<PulseRunInput, RunState, SettledSubmissionRecord, object>;
28
+ export {};
package/dist/tool.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ import type { Context } from "@earendil-works/chord";
2
+ import { type TaskId, type ToolExecutionApi } from "@earendil-works/pi-durable";
3
+ import { Type } from "typebox";
4
+ import type { PulseRunRequest, PulsesOptions } from "./contract.ts";
5
+ import type { PulseCatalogItem } from "./definitions.ts";
6
+ export declare function createPulsesTool(options: PulsesOptions, operations: {
7
+ catalog(context: Context, bindingKey: string): Promise<PulseCatalogItem[]>;
8
+ run(request: PulseRunRequest, context: Context, api: ToolExecutionApi): Promise<TaskId | undefined>;
9
+ }): {
10
+ name: string;
11
+ description: string;
12
+ parameters: Type.TObject<{
13
+ run: Type.TOptional<Type.TString>;
14
+ skill: Type.TOptional<Type.TLiteral<true>>;
15
+ }>;
16
+ constrainedSampling?: false | import("@earendil-works/pi-ai").ConstrainedSamplingConfig;
17
+ replay?: "safe" | "unsafe";
18
+ executionMode?: import("@earendil-works/pi-durable").ToolExecutionMode;
19
+ prepareArguments?(args: unknown): {
20
+ run?: string;
21
+ skill?: true;
22
+ };
23
+ structuredOutputSchema?: Type.TSchema;
24
+ callers?: readonly ("model" | "tools")[];
25
+ deferred?: true;
26
+ outputLimits?: {
27
+ readonly maxBytes?: number;
28
+ readonly maxLines?: number;
29
+ readonly retain?: "head" | "tail";
30
+ };
31
+ execute(args: {
32
+ run?: string;
33
+ skill?: true;
34
+ }, api: ToolExecutionApi<import("@earendil-works/chord").JsonValue>, context: Context): Promise<import("@earendil-works/pi-durable").ToolExecutionResult<import("@earendil-works/chord").JsonValue>>;
35
+ executionHints: {
36
+ discovery: "help";
37
+ };
38
+ };
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
- "name": "@howaboua/pi-durable-pulses",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@howaboua/pi-durable-pulses",
3
+ "version": "0.10.0",
4
+ "description": "Persistent native scheduled pulse conversations",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/IgorWarzocha/pi-durable-components.git",
10
+ "directory": "packages/pulses"
11
+ },
12
+ "author": "Igor Warzocha",
13
+ "engines": {
14
+ "node": ">=22.19.0"
15
+ },
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ },
23
+ "./component": {
24
+ "types": "./dist/activation.d.ts",
25
+ "import": "./dist/activation.js"
26
+ }
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "skills",
31
+ "README.md",
32
+ "NOTICE",
33
+ "LICENSE"
34
+ ],
35
+ "sideEffects": false,
36
+ "dependencies": {
37
+ "typebox": "1.3.27",
38
+ "@howaboua/pi-durable-components": "0.10.0"
39
+ },
40
+ "peerDependencies": {
41
+ "@earendil-works/chord": "1.4.0",
42
+ "@earendil-works/pi-ai": "1.4.0",
43
+ "@earendil-works/pi-durable": "1.4.0",
44
+ "@modelcontextprotocol/sdk": ">=1.25.2 <2"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "durable": {
50
+ "schemaVersion": 1,
51
+ "kind": "extension",
52
+ "entry": "./component",
53
+ "runtimes": [
54
+ "node"
55
+ ],
56
+ "requires": [
57
+ "durable.scheduling.v1"
58
+ ],
59
+ "permissions": [
60
+ "storage",
61
+ "filesystem",
62
+ "models"
63
+ ]
64
+ }
65
+ }
@@ -0,0 +1,14 @@
1
+ ---
2
+ name: pulses-ops
3
+ description: Manage folder-owned pulses and inspect native scheduled work.
4
+ ---
5
+
6
+ # Pulses
7
+
8
+ Keep each pulse in `pulses/<id>/PULSE.md`, using a kebab-case directory name. Preserve its `AGENTS.md`, existing `runs/` journals and other artifacts. Read applicable workspace and pulse-local instructions before working. Native cwd remains the workspace root; use the explicit pulse-home path for local files. Do not invent an app-managed output directory or universal journal schema.
9
+
10
+ Frontmatter accepts `title`, `schedule`, `enabled`, optional `quietHours`, `expiresAt` and `target`. Leave unrelated keys, comments and body conventions alone. Schedules are `manual`, `every 30m`, `every 3h`, `every 2d`, `daily 9:00`, `weekly mon 9:00` and `at <datetime>`. Use runtime-local time. Scans have five-minute granularity. Quiet hours such as `22:00-08:00` hold scheduled work. `expiresAt` takes a datetime. Child execution is the default. Use `target: resident` only when the host supplies the intended continuing resident. Existing `trigger: manual` needs no schedule and `trigger: time` requires one.
11
+
12
+ Use `pulses({})` to list paths and invalid definitions, `pulses({run:"name"})` to request a run and `pulses({skill:true})` for authoring guidance. The consuming app's native controls expose execution outcomes and Stop. Disabled definitions cannot run manually. A manual Run bypasses quiet hours, does not consume the scheduled checkpoint, and cannot overlap active responsibility. Host restrictions can hold admission. On resume, tracked missed occurrences coalesce into one run per job with an explicit count and period. Respect that period rather than repeating each occurrence. Different jobs share a configurable execution limit, initially two. Reenabling or readding a disabled definition seeds its current slot rather than recovering disabled history. Removed, expired and superseded pending work stays inspectable. Retry an invocation with the same request ID when its admission is uncertain.
13
+
14
+ Inspect native task and submission outcomes, not dispatch alone, to determine completion. Stop aborts the native coordinator and the run owning its input, then settles its passive result. An interrupted external side effect may have an uncertain outcome. Report that uncertainty rather than repeat it. Child result delivery is passive context, never a follow-up that wakes the parent. Resident-target work reports in that resident's ordinary conversation. Parent changes preserve old native history and the pulse's files. Disabling or removing a definition deletes neither.