@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.
- package/LICENSE +21 -0
- package/NOTICE +20 -0
- package/README.md +50 -2
- package/dist/activation.d.ts +5 -0
- package/dist/activation.js +1255 -0
- package/dist/admission.d.ts +9 -0
- package/dist/authoring.d.ts +1 -0
- package/dist/contract.d.ts +51 -0
- package/dist/definitions.d.ts +27 -0
- package/dist/execution.d.ts +14 -0
- package/dist/frontmatter.d.ts +5 -0
- package/dist/index.d.ts +132 -0
- package/dist/index.js +1213 -0
- package/dist/occurrences.d.ts +6 -0
- package/dist/schedule.d.ts +24 -0
- package/dist/state.d.ts +47 -0
- package/dist/tasks.d.ts +28 -0
- package/dist/tool.d.ts +38 -0
- package/package.json +64 -5
- package/skills/pulses-ops/SKILL.md +14 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import { type Harness, type TaskId, type Tx } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { PulsesOptions, PulseTrigger } from "./contract.ts";
|
|
4
|
+
import type { PulseDefinition } from "./definitions.ts";
|
|
5
|
+
import { type createRunTask } from "./tasks.ts";
|
|
6
|
+
/** Native task inputs are the request authority, not a second receipt ledger. */
|
|
7
|
+
export declare function admitted(tx: Tx, bindingKey: string, pulseId: string, requestId: string): Promise<TaskId<import("@earendil-works/chord").JsonValue> | undefined>;
|
|
8
|
+
export declare function validateConcurrency(limit: number): number;
|
|
9
|
+
export declare function createAdmission(host: () => Harness, options: PulsesOptions, Run: ReturnType<typeof createRunTask>, accepting: () => boolean): (definition: PulseDefinition, trigger: PulseTrigger, requestId: string, context: Context) => Promise<TaskId | undefined>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const pulseAuthoring = "Create pulses/<self-explanatory-name>/PULSE.md in the workspace shown by pulses({}). Use a lowercase kebab-case folder name. Preserve its AGENTS.md, existing journals and artifacts. Read applicable workspace and pulse-local instructions. Native cwd remains the workspace root; use the explicit pulse-home path for local files.\n\nExample PULSE.md:\n---\ntitle: Check agreed sources\nschedule: every 5h\nenabled: true\nquietHours: 22:00-08:00\n---\nCheck the agreed sources for changes since the previous run.\nPost actionable findings to the designated available destination.\n\ntitle and schedule are required. Schedules: manual, every 30m, every 5h, every 2d, daily 09:00, weekly fri 17:00 or at <datetime>. Use an explicit timezone offset for a one-time timestamp when timezone matters. Daily and weekly times and quietHours use the runtime's local timezone. Checks run every five minutes. Existing trigger: manual needs no schedule; trigger: time requires one.\n\nenabled defaults to true. Set false to pause both scheduled and manual runs. quietHours is optional and accepts HH:MM-HH:MM, including overnight ranges. Manual runs bypass quiet hours without consuming recurrence checkpoints. Optional expiresAt stops new admissions at that datetime. Child execution is the default; target: resident requires an explicit host-supplied continuing resident. Leave unrelated frontmatter keys, comments and body conventions untouched.\n\nKeep the body a short SOP: the actual task, sources, destination and consequential limits. Do not duplicate general skill guidance or require skills the task does not need. Define concrete destinations only when available. The worker receives the body plus standard result-routing and procedural-feedback instructions; do not repeat them in definitions.\n\nUse ordinary file tools to edit definitions. Disable routines worth keeping for later; delete obsolete definitions without deleting their journals or artifacts. There is no authoring configuration API. pulses({}) lists paths and invalid-definition diagnostics. pulses({run: \"name\"}) requests an immediate run. Admission is not completion. Inspect native task and submission outcomes through the consuming app. Child results are passive context and never wake the parent; resident work reports in that conversation.\n\nTracked missed occurrences coalesce into one run per job with a count and period. Cover that period rather than replaying each occurrence. Host restrictions, concurrency and active responsibility can hold admission. Reenabling or readding seeds the current slot, not disabled history. Removed, expired or superseded pending work stays inspectable. Retrying the same native tool task rejoins its accepted request, even after definition edits or deletion. An interrupted external side effect may have an uncertain outcome; report that uncertainty rather than repeat it. Stop uses the consuming app's native controls. It aborts only the coordinator and its owned input, then settles its passive report. Removing a definition or component never deletes files or native history.";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import type { ConversationId, SettledSubmissionRecord, TaskId, ToolExecutionApi, Tx } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { ScheduledAdmissionDecision, ScheduledInput, ScheduledOccurrence, ScheduledResult, ScheduledSource, ScheduledTrigger, SchedulingBinding } from "@howaboua/pi-durable-components";
|
|
4
|
+
import type { PulseDefinition } from "./definitions.ts";
|
|
5
|
+
export type PulseBinding = SchedulingBinding;
|
|
6
|
+
export type PulseSource = ScheduledSource;
|
|
7
|
+
export type PulseRunRequest = {
|
|
8
|
+
bindingKey: string;
|
|
9
|
+
pulseId: string;
|
|
10
|
+
requestId: string;
|
|
11
|
+
};
|
|
12
|
+
export type PulseTrigger = ScheduledTrigger;
|
|
13
|
+
export type PulseOccurrence = ScheduledOccurrence;
|
|
14
|
+
export type PulseAdmission = {
|
|
15
|
+
binding: PulseBinding;
|
|
16
|
+
definition: PulseDefinition;
|
|
17
|
+
trigger: PulseTrigger;
|
|
18
|
+
requestId: string;
|
|
19
|
+
taskId: TaskId;
|
|
20
|
+
conversationId: ConversationId;
|
|
21
|
+
occurrence?: PulseOccurrence;
|
|
22
|
+
};
|
|
23
|
+
export type PulseAdmissionDecision = ScheduledAdmissionDecision;
|
|
24
|
+
export type PulseInputDelivery = ScheduledInput;
|
|
25
|
+
/** The abort-before-dispatch case has a native task outcome but no submission receipt. */
|
|
26
|
+
export type PulseOutcome = ScheduledResult["outcome"];
|
|
27
|
+
export type PulseResultDelivery = ScheduledResult;
|
|
28
|
+
export interface PulsesOptions {
|
|
29
|
+
/** Resolve the caller's authorised binding in api.env. Never infer from global bindings or host paths. */
|
|
30
|
+
resolveToolBinding?(api: ToolExecutionApi, context: Context): Promise<string>;
|
|
31
|
+
/** After receipt lookup, outside the admission queue. Establish caller scope only; defer actual authorisation to admit, since run() rejoins receipts again. Never infer authority from request IDs. admitTransaction owns atomic policy/credit with task creation. Call run at most once and return its result; no external side effects. */
|
|
32
|
+
withToolRunAuthorization?(api: ToolExecutionApi, request: PulseRunRequest, run: () => Promise<TaskId | undefined>, context: Context): Promise<TaskId | undefined>;
|
|
33
|
+
/** Initial limit only. Persisted changes through setConcurrency survive rebinding. */
|
|
34
|
+
concurrency?: number;
|
|
35
|
+
getBindings(context: Context): Promise<readonly PulseBinding[]>;
|
|
36
|
+
/** Read immediate pulse directories in the explicit execution environment. Never modify files. */
|
|
37
|
+
readDefinitions(binding: PulseBinding, context: Context): Promise<readonly PulseSource[]>;
|
|
38
|
+
/** Prepare environment data and preflight every new admission. Race-safe policy/credit belongs in admitTransaction. */
|
|
39
|
+
admit(binding: PulseBinding, definition: PulseDefinition, trigger: PulseTrigger, context: Context): Promise<void>;
|
|
40
|
+
/** Same native transaction as createTask. Blocked rolls back ALL changes, including policy credit. Use tx.doc only: table reads after createTask are forbidden. No filesystem, network, Harness reads or irreversible effects. Receipt retries bypass this hook. */
|
|
41
|
+
admitTransaction?(tx: Tx, admission: PulseAdmission, context: Context): Promise<PulseAdmissionDecision>;
|
|
42
|
+
/** Deliver already accepted work. Validate native task lineage and rejoin requestId before new input policy; return the actual settled input receipt. */
|
|
43
|
+
submitInput?(delivery: PulseInputDelivery, context: Context): Promise<SettledSubmissionRecord>;
|
|
44
|
+
/** Transaction-only configuration on every NEW child admission, never the resident target. Prepare data in admit. Use document operations only, no table reads or filesystem/model I/O. Configure cwd=root and fresh pulse-home instructions without accumulating old instructions; preserve native parent models/tools/extensions. */
|
|
45
|
+
configure(tx: Tx, conversationId: ConversationId, binding: PulseBinding, definition: PulseDefinition, creation: {
|
|
46
|
+
created: boolean;
|
|
47
|
+
}): Promise<void>;
|
|
48
|
+
/** Must submit type:write with requestId and await its native receipt. Never wake the parent. */
|
|
49
|
+
writeResult?(delivery: PulseResultDelivery, context: Context): Promise<SettledSubmissionRecord>;
|
|
50
|
+
onError(error: unknown): void;
|
|
51
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PulseBinding, PulseSource } from "./contract.ts";
|
|
2
|
+
import { type PulseQuietHours, type PulseSchedule } from "./schedule.ts";
|
|
3
|
+
type PulsePaths = {
|
|
4
|
+
id: string;
|
|
5
|
+
bindingKey: string;
|
|
6
|
+
root: string;
|
|
7
|
+
pulseHome: string;
|
|
8
|
+
path: string;
|
|
9
|
+
};
|
|
10
|
+
export type PulseDefinition = PulsePaths & {
|
|
11
|
+
status: "valid";
|
|
12
|
+
title: string;
|
|
13
|
+
scheduleText: string;
|
|
14
|
+
schedule: PulseSchedule;
|
|
15
|
+
enabled: boolean;
|
|
16
|
+
target?: "child" | "resident";
|
|
17
|
+
expiresAt?: number;
|
|
18
|
+
quietHours?: PulseQuietHours;
|
|
19
|
+
body: string;
|
|
20
|
+
};
|
|
21
|
+
export type PulseCatalogItem = PulseDefinition | (PulsePaths & {
|
|
22
|
+
status: "invalid";
|
|
23
|
+
title: string;
|
|
24
|
+
error: string;
|
|
25
|
+
});
|
|
26
|
+
export declare function parsePulseDefinition(binding: PulseBinding, source: PulseSource): PulseCatalogItem;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { JsonValue } from "@earendil-works/chord";
|
|
2
|
+
import type { ConversationId, SubmissionRecord, TaskRecord, Tx } from "@earendil-works/pi-durable";
|
|
3
|
+
export type PulseExecutionRequest = {
|
|
4
|
+
bindingKey: string;
|
|
5
|
+
pulseId: string;
|
|
6
|
+
conversationId: ConversationId;
|
|
7
|
+
};
|
|
8
|
+
/** Latest admitted execution for this exact job and conversation, including historical targets. */
|
|
9
|
+
export declare function execution(tx: Tx, request: PulseExecutionRequest): Promise<{
|
|
10
|
+
task: TaskRecord<JsonValue, JsonValue, JsonValue>;
|
|
11
|
+
submission: Extract<SubmissionRecord, {
|
|
12
|
+
type: "input";
|
|
13
|
+
}> | undefined;
|
|
14
|
+
} | undefined>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import { type Harness, type TaskId, type ToolExecutionApi } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { PulseRunRequest, PulsesOptions } from "./contract.ts";
|
|
4
|
+
import { type PulseCatalogItem } from "./definitions.ts";
|
|
5
|
+
import { type PulseExecutionRequest } from "./execution.ts";
|
|
6
|
+
import { explicitReady } from "./occurrences.ts";
|
|
7
|
+
export type { PulseAdmission, PulseAdmissionDecision, PulseBinding, PulseInputDelivery, PulseOccurrence, PulseOutcome, PulseResultDelivery, PulseRunRequest, PulseSource, PulsesOptions, PulseTrigger, } from "./contract.ts";
|
|
8
|
+
export { type PulseCatalogItem, type PulseDefinition, parsePulseDefinition, } from "./definitions.ts";
|
|
9
|
+
export type { PulseExecutionRequest } from "./execution.ts";
|
|
10
|
+
export { parsePulseFrontmatter } from "./frontmatter.ts";
|
|
11
|
+
export { explicitReady } from "./occurrences.ts";
|
|
12
|
+
export { isPulseDue, isPulseQuietAt, type PulseQuietHours, type PulseSchedule, parsePulseQuietHours, parsePulseSchedule, pulseDueKey, } from "./schedule.ts";
|
|
13
|
+
export type { PulseCheckpoint, PulseDisposition, PulseReference, } from "./state.ts";
|
|
14
|
+
export type { PulseRunInput } from "./tasks.ts";
|
|
15
|
+
/** Supply the actual installed asset path mapped into the execution environment. Compatible with Skills' LoadedSkill. */
|
|
16
|
+
export declare function pulsesSkill(filePath: string, baseDir: string): {
|
|
17
|
+
name: string;
|
|
18
|
+
description: string;
|
|
19
|
+
filePath: string;
|
|
20
|
+
baseDir: string;
|
|
21
|
+
};
|
|
22
|
+
export declare function createPulses(options: PulsesOptions): {
|
|
23
|
+
extension: import("@earendil-works/pi-durable").Extension<{
|
|
24
|
+
name: string;
|
|
25
|
+
description: string;
|
|
26
|
+
parameters: import("typebox").TObject<{
|
|
27
|
+
run: import("typebox").TOptional<import("typebox").TString>;
|
|
28
|
+
skill: import("typebox").TOptional<import("typebox").TLiteral<true>>;
|
|
29
|
+
}>;
|
|
30
|
+
constrainedSampling?: false | import("@earendil-works/pi-ai").ConstrainedSamplingConfig;
|
|
31
|
+
replay?: "safe" | "unsafe";
|
|
32
|
+
executionMode?: import("@earendil-works/pi-durable").ToolExecutionMode;
|
|
33
|
+
prepareArguments?(args: unknown): {
|
|
34
|
+
run?: string;
|
|
35
|
+
skill?: true;
|
|
36
|
+
};
|
|
37
|
+
structuredOutputSchema?: import("typebox").TSchema;
|
|
38
|
+
callers?: readonly ("model" | "tools")[];
|
|
39
|
+
deferred?: true;
|
|
40
|
+
outputLimits?: {
|
|
41
|
+
readonly maxBytes?: number;
|
|
42
|
+
readonly maxLines?: number;
|
|
43
|
+
readonly retain?: "head" | "tail";
|
|
44
|
+
};
|
|
45
|
+
execute(args: {
|
|
46
|
+
run?: string;
|
|
47
|
+
skill?: true;
|
|
48
|
+
}, api: ToolExecutionApi<import("@earendil-works/chord").JsonValue>, context: Context): Promise<import("@earendil-works/pi-durable").ToolExecutionResult<import("@earendil-works/chord").JsonValue>>;
|
|
49
|
+
executionHints: {
|
|
50
|
+
discovery: "help";
|
|
51
|
+
};
|
|
52
|
+
}>;
|
|
53
|
+
tool: {
|
|
54
|
+
name: string;
|
|
55
|
+
description: string;
|
|
56
|
+
parameters: import("typebox").TObject<{
|
|
57
|
+
run: import("typebox").TOptional<import("typebox").TString>;
|
|
58
|
+
skill: import("typebox").TOptional<import("typebox").TLiteral<true>>;
|
|
59
|
+
}>;
|
|
60
|
+
constrainedSampling?: false | import("@earendil-works/pi-ai").ConstrainedSamplingConfig;
|
|
61
|
+
replay?: "safe" | "unsafe";
|
|
62
|
+
executionMode?: import("@earendil-works/pi-durable").ToolExecutionMode;
|
|
63
|
+
prepareArguments?(args: unknown): {
|
|
64
|
+
run?: string;
|
|
65
|
+
skill?: true;
|
|
66
|
+
};
|
|
67
|
+
structuredOutputSchema?: import("typebox").TSchema;
|
|
68
|
+
callers?: readonly ("model" | "tools")[];
|
|
69
|
+
deferred?: true;
|
|
70
|
+
outputLimits?: {
|
|
71
|
+
readonly maxBytes?: number;
|
|
72
|
+
readonly maxLines?: number;
|
|
73
|
+
readonly retain?: "head" | "tail";
|
|
74
|
+
};
|
|
75
|
+
execute(args: {
|
|
76
|
+
run?: string;
|
|
77
|
+
skill?: true;
|
|
78
|
+
}, api: ToolExecutionApi<import("@earendil-works/chord").JsonValue>, context: Context): Promise<import("@earendil-works/pi-durable").ToolExecutionResult<import("@earendil-works/chord").JsonValue>>;
|
|
79
|
+
executionHints: {
|
|
80
|
+
discovery: "help";
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
catalog: (context: Context, bindingKey?: string) => Promise<PulseCatalogItem[]>;
|
|
84
|
+
scan: (context: Context) => Promise<PulseCatalogItem[]>;
|
|
85
|
+
explicitReady: typeof explicitReady;
|
|
86
|
+
configuration(context: Context): Promise<{
|
|
87
|
+
concurrency: number;
|
|
88
|
+
}>;
|
|
89
|
+
setConcurrency(limit: number, context: Context): Promise<{
|
|
90
|
+
concurrency: number;
|
|
91
|
+
}>;
|
|
92
|
+
run(request: PulseRunRequest, context: Context): Promise<TaskId | undefined>;
|
|
93
|
+
/** Native task and input receipt for the latest run of this exact job/target. No receipt means not yet submitted. */
|
|
94
|
+
execution(request: PulseExecutionRequest, context: Context): Promise<{
|
|
95
|
+
task: import("@earendil-works/pi-durable").TaskRecord<import("@earendil-works/chord").JsonValue, import("@earendil-works/chord").JsonValue, import("@earendil-works/chord").JsonValue>;
|
|
96
|
+
submission: Extract<import("@earendil-works/pi-durable").SubmissionRecord, {
|
|
97
|
+
type: "input";
|
|
98
|
+
}> | undefined;
|
|
99
|
+
} | undefined>;
|
|
100
|
+
observe(context: Context): Promise<{
|
|
101
|
+
firstSeenAt: number;
|
|
102
|
+
scheduledEligible?: boolean;
|
|
103
|
+
scheduleKey?: string;
|
|
104
|
+
trackedAt?: number;
|
|
105
|
+
trackedSchedule?: import("./schedule.ts").PulseSchedule;
|
|
106
|
+
quietHours?: import("./schedule.ts").PulseQuietHours;
|
|
107
|
+
expiresAt?: number;
|
|
108
|
+
nextDueAt?: number;
|
|
109
|
+
pending?: import("./contract.ts").PulseOccurrence;
|
|
110
|
+
blocked?: {
|
|
111
|
+
reason: string;
|
|
112
|
+
retryAt?: number;
|
|
113
|
+
};
|
|
114
|
+
disposition?: import("./state.ts").PulseDisposition;
|
|
115
|
+
lastRunAt?: number;
|
|
116
|
+
lastDueKey?: string;
|
|
117
|
+
current?: import("./state.ts").PulseReference;
|
|
118
|
+
history: import("./state.ts").PulseReference[];
|
|
119
|
+
activeTask?: TaskId;
|
|
120
|
+
key: string;
|
|
121
|
+
task: import("@earendil-works/pi-durable").TaskRecord<import("@earendil-works/chord").JsonValue, import("@earendil-works/chord").JsonValue, unknown> | undefined;
|
|
122
|
+
}[]>;
|
|
123
|
+
stop(request: {
|
|
124
|
+
bindingKey: string;
|
|
125
|
+
pulseId: string;
|
|
126
|
+
}, context: Context): Promise<void>;
|
|
127
|
+
bind(value: Harness, context: Context): Promise<void>;
|
|
128
|
+
/** Stop new admissions and drain admission work while task bindings remain available. */
|
|
129
|
+
stopAdmission(): Promise<void>;
|
|
130
|
+
/** Release only after the host has drained/closed native task invocations. */
|
|
131
|
+
unbind(): Promise<void>;
|
|
132
|
+
};
|