@anhlp/alp-runtime 0.0.1-beta.3 → 0.0.1-beta.4
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/dist/assignment-results.d.ts +18 -0
- package/dist/assignment-results.js +77 -0
- package/dist/attachments.d.ts +84 -0
- package/dist/attachments.js +213 -0
- package/dist/claude-transport.d.ts +28 -0
- package/dist/claude-transport.js +87 -4
- package/dist/configure.d.ts +44 -0
- package/dist/configure.js +64 -0
- package/dist/contracts.d.ts +160 -3
- package/dist/contracts.js +11 -0
- package/dist/conversation.d.ts +45 -0
- package/dist/conversation.js +62 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +10 -1
- package/dist/mailbox.d.ts +2 -0
- package/dist/mailbox.js +3 -1
- package/dist/runtime.d.ts +7 -0
- package/dist/runtime.js +960 -115
- package/dist/session-config.d.ts +105 -0
- package/dist/session-config.js +2 -2
- package/dist/session-state.d.ts +22 -6
- package/dist/tools.d.ts +37 -0
- package/dist/tools.js +19 -0
- package/dist/worktree-domain.d.ts +2 -1
- package/dist/worktree-domain.js +4 -1
- package/package.json +11 -3
- package/src/assignment-results.ts +64 -0
- package/src/attachments.ts +254 -0
- package/src/claude-transport.ts +100 -5
- package/src/configure.ts +93 -0
- package/src/contracts.ts +150 -4
- package/src/conversation.ts +81 -0
- package/src/index.ts +6 -2
- package/src/mailbox.ts +4 -1
- package/src/runtime.ts +1049 -123
- package/src/session-config.ts +2 -2
- package/src/session-state.ts +15 -2
- package/src/tools.ts +16 -0
- package/src/worktree-domain.ts +5 -1
package/src/session-config.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { ResolvedSession, RuntimeKind } from './resolve.js';
|
|
|
5
5
|
import { models, thinkingOptionsFor } from './catalog.js';
|
|
6
6
|
import { claudeSandboxAvailable, SKILL_PLUGIN } from './claude-transport.js';
|
|
7
7
|
import { languageInstruction } from './language.js';
|
|
8
|
-
import { HANDOFF_TOOL, WAIT_TOOL, SEND_TOOL, MERGE_TOOL, VERIFY_TOOL, DISCARD_TOOL, CANCEL_TOOL, RECALL_TOOL, PIN_TOOL, BOARD_TOOL, UNPIN_TOOL, ASK_TOOL, LESSON_TOOL, SKILL_TOOL, ISSUE_TOOL, mainOf, taskActions, taskTool } from './tools.js';
|
|
8
|
+
import { HANDOFF_TOOL, WAIT_TOOL, SEND_TOOL, MERGE_TOOL, VERIFY_TOOL, DISCARD_TOOL, CANCEL_TOOL, RECALL_TOOL, PIN_TOOL, BOARD_TOOL, UNPIN_TOOL, ASK_TOOL, LESSON_TOOL, SKILL_TOOL, ISSUE_TOOL, SCHEDULE_TOOL, mainOf, taskActions, taskTool } from './tools.js';
|
|
9
9
|
|
|
10
10
|
import { COMPACT_SHARE } from './runtime-context.js';
|
|
11
11
|
|
|
@@ -293,7 +293,7 @@ export function nativeSessionConfig(
|
|
|
293
293
|
...(targets.length || parentAgent ? [SEND_TOOL] : []),
|
|
294
294
|
...(parentAgent ? [HANDOFF_TOOL] : []),
|
|
295
295
|
...(supervised ? [LESSON_TOOL, SKILL_TOOL] : []),
|
|
296
|
-
...(!parentAgent && mapping.agent.name === mainOf(mapping) ? [ISSUE_TOOL] : []),
|
|
296
|
+
...(!parentAgent && mapping.agent.name === mainOf(mapping) ? [ISSUE_TOOL, SCHEDULE_TOOL] : []),
|
|
297
297
|
ASK_TOOL,
|
|
298
298
|
PIN_TOOL,
|
|
299
299
|
BOARD_TOOL,
|
package/src/session-state.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RuntimeTransport } from './contracts.js';
|
|
1
|
+
import type { NativeBase, RuntimeTransport } from './contracts.js';
|
|
2
2
|
import type { RuntimeKind, SessionSpec, ResolvedSession } from './resolve.js';
|
|
3
3
|
import type { MailEvent } from './mailbox.js';
|
|
4
4
|
import type { Worktree, WorktreeChange, Copy } from './workspace.js';
|
|
@@ -6,11 +6,17 @@ import type { Verification } from '@anhlp/alp-core/verify';
|
|
|
6
6
|
import type { Handoff } from './handoff.js';
|
|
7
7
|
import type { SessionUsage } from './events.js';
|
|
8
8
|
|
|
9
|
+
/** The pause that stopped a turn; a matching resume may arrive before its interruption settles. */
|
|
10
|
+
export type ParkPause = { scope: RuntimeKind | 'all'; resumed?: boolean };
|
|
11
|
+
export type Parked = { reason: string; since: number; prompt?: string; pause?: ParkPause };
|
|
12
|
+
|
|
9
13
|
export type Session = {
|
|
10
14
|
runtimeKind: RuntimeKind;
|
|
11
15
|
runtime: RuntimeTransport;
|
|
12
16
|
mapping: ResolvedSession;
|
|
13
17
|
threadId: string;
|
|
18
|
+
/** Claude: the conversation threadId is made from on its first prompt, until then (a fork or rewind, §12.7). */
|
|
19
|
+
base?: NativeBase;
|
|
14
20
|
active?: string;
|
|
15
21
|
/** A continued turn accepts a simultaneous user auto prompt as steering. */
|
|
16
22
|
resumedTurn?: string;
|
|
@@ -51,7 +57,7 @@ export type Session = {
|
|
|
51
57
|
/** Set by interrupt: pending mail waits for the next user prompt. */
|
|
52
58
|
wakeBlocked: boolean;
|
|
53
59
|
/** An assignment a usage limit or a pause stopped: it waits, open, until its runtime resumes. prompt is what continues it. */
|
|
54
|
-
parked?:
|
|
60
|
+
parked?: Parked;
|
|
55
61
|
/** What the requester of a session parked by its turn's end is told happens next, instead of waiting for alp resume. */
|
|
56
62
|
parkThen?: string;
|
|
57
63
|
/** When ALP restarted this session's native process, within the last RESTART_WINDOW_MS. */
|
|
@@ -70,8 +76,15 @@ export type Session = {
|
|
|
70
76
|
skillsUsed?: Set<string>;
|
|
71
77
|
/** Why the running turn is being stopped, so its end parks the assignment instead of ending it. */
|
|
72
78
|
parkReason?: string;
|
|
79
|
+
parkPause?: ParkPause;
|
|
73
80
|
/** Mail arrived while its runtime was paused; it is delivered on resume. */
|
|
74
81
|
wakeHeld?: boolean;
|
|
82
|
+
/** How many lifecycle operations (a rewind) hold its wakes now; mail waits until the last releases (AlpRuntime.hold). */
|
|
83
|
+
lifecycleHolds?: number;
|
|
84
|
+
/** Its parked work was to continue during a lifecycle hold; it continues when the last hold releases. */
|
|
85
|
+
resumeHeld?: Parked;
|
|
86
|
+
/** An assignment opened but not yet sent its brief: mail waits and rides with the brief's turn. */
|
|
87
|
+
awaitingBrief?: boolean;
|
|
75
88
|
/** Permission questions to the user, one at a time. */
|
|
76
89
|
permissionQueue?: Promise<unknown>;
|
|
77
90
|
|
package/src/tools.ts
CHANGED
|
@@ -379,3 +379,19 @@ export function taskBrief(task: Task, writing: boolean) {
|
|
|
379
379
|
'Your handoff moves this task to review for your requester to accept. List work you found outside the task under discovered; only main and the user create tasks.',
|
|
380
380
|
].join('\n');
|
|
381
381
|
}
|
|
382
|
+
|
|
383
|
+
/** Only the project's main root may schedule a future continuation. */
|
|
384
|
+
export const SCHEDULE_TOOL = {
|
|
385
|
+
type: 'function', name: 'alp_schedule',
|
|
386
|
+
description: 'Create, list, inspect or cancel a one-shot continuation of this main/root session. create proposes the exact prompt and ISO time with UTC offset for user approval. Jobs wake an idle main without a user message; timer gates only unblock tasks, and assignment notes do not schedule a wake. Scheduling a quota-reset continuation never guarantees provider availability: recheck actual availability before delegating.',
|
|
387
|
+
inputSchema: {
|
|
388
|
+
type: 'object', properties: {
|
|
389
|
+
action: { type: 'string', enum: ['create', 'list', 'get', 'cancel'] },
|
|
390
|
+
dueAt: { type: 'string', description: 'For create: ISO timestamp with Z or an explicit UTC offset.' },
|
|
391
|
+
prompt: { type: 'string', description: 'For create: the exact continuation, at most 8000 characters.' },
|
|
392
|
+
requestId: { type: 'string', description: 'For create: stable id for this approval proposal; reuse only for an identical draft.' },
|
|
393
|
+
id: { type: 'string', description: 'For get/cancel: the scheduled job id.' },
|
|
394
|
+
status: { type: 'string', enum: ['pending', 'delivered', 'failed', 'cancelled'] },
|
|
395
|
+
}, required: ['action'], additionalProperties: false,
|
|
396
|
+
},
|
|
397
|
+
};
|
package/src/worktree-domain.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type { Session, Assignment } from './session-state.js';
|
|
|
12
12
|
|
|
13
13
|
type WorktreeContext = {
|
|
14
14
|
options: RuntimeOptions;
|
|
15
|
+
releaseResult(assignmentId: string): Promise<void>;
|
|
15
16
|
leases: Map<string, { assignment: string; agent: string }>;
|
|
16
17
|
rootOf(sessionId: string): string;
|
|
17
18
|
lineage(sessionId: string): string[];
|
|
@@ -21,7 +22,7 @@ type WorktreeContext = {
|
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
/** Checkout mutation and verification retain one shared queue per checkout. */
|
|
24
|
-
export function createWorktreeDomain({ options, leases, rootOf, lineage, runLog, runHooks, touchTask }: WorktreeContext) {
|
|
25
|
+
export function createWorktreeDomain({ options, leases, releaseResult, rootOf, lineage, runLog, runHooks, touchTask }: WorktreeContext) {
|
|
25
26
|
const merging = new Map<string, Promise<unknown>>();
|
|
26
27
|
|
|
27
28
|
/** Commits a finished isolated assignment's work and keeps it for the requester to merge. */
|
|
@@ -31,6 +32,7 @@ export function createWorktreeDomain({ options, leases, rootOf, lineage, runLog,
|
|
|
31
32
|
const change = await commitWorktree(worktree, `alp: ${assignment.agent} assignment ${assignment.id}`);
|
|
32
33
|
if (!change.files.length) {
|
|
33
34
|
await removeWorktree(worktree, { deleteBranch: true });
|
|
35
|
+
await releaseResult(assignment.id);
|
|
34
36
|
return { branch: worktree.branch, files: [], note: 'No changes; the worktree was removed' };
|
|
35
37
|
}
|
|
36
38
|
const described = { branch: worktree.branch, base: worktree.base, commit: change.commit, files: change.files, stat: change.stat };
|
|
@@ -60,6 +62,7 @@ export function createWorktreeDomain({ options, leases, rootOf, lineage, runLog,
|
|
|
60
62
|
if (action === 'discard') {
|
|
61
63
|
session.worktrees.delete(args.assignmentId);
|
|
62
64
|
await removeWorktree(worktree, { deleteBranch: true });
|
|
65
|
+
await releaseResult(args.assignmentId);
|
|
63
66
|
runLog(rootOf(sessionId), { event: 'worktree.discarded', assignmentId: args.assignmentId, branch: worktree.branch });
|
|
64
67
|
return toolResult(true, { discarded: args.assignmentId, branch: worktree.branch });
|
|
65
68
|
}
|
|
@@ -122,6 +125,7 @@ export function createWorktreeDomain({ options, leases, rootOf, lineage, runLog,
|
|
|
122
125
|
}
|
|
123
126
|
// A conflicted change keeps its branch for reference.
|
|
124
127
|
await removeWorktree(worktree, { deleteBranch: merged.status !== 'conflicts' });
|
|
128
|
+
if (merged.status !== 'conflicts') await releaseResult(args.assignmentId);
|
|
125
129
|
runLog(rootId, { event: 'worktree.merged', assignmentId: args.assignmentId, branch: worktree.branch, ...merged });
|
|
126
130
|
// The checkout changed since the assignment started, so the worktree's check says little about the result: check the checkout too.
|
|
127
131
|
let checked: Verification | undefined;
|