ptbk 0.119.0-16 → 0.119.0-21
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 +27 -9
- package/dist/book/commitments.d.ts +38 -10
- package/dist/book/commitments.js +61 -17
- package/dist/book/commitments.js.map +1 -1
- package/dist/book/convert.d.ts +36 -0
- package/dist/book/convert.js +156 -0
- package/dist/book/convert.js.map +1 -0
- package/dist/book/parse.d.ts +50 -13
- package/dist/book/parse.js +132 -45
- package/dist/book/parse.js.map +1 -1
- package/dist/book/references.d.ts +12 -4
- package/dist/book/references.js +34 -9
- package/dist/book/references.js.map +1 -1
- package/dist/book/write.d.ts +42 -0
- package/dist/book/write.js +74 -0
- package/dist/book/write.js.map +1 -0
- package/dist/browser/browser.d.ts +122 -12
- package/dist/browser/browser.js +372 -21
- package/dist/browser/browser.js.map +1 -1
- package/dist/browser/recording.d.ts +3 -3
- package/dist/browser/recording.js +5 -5
- package/dist/browser/recording.js.map +1 -1
- package/dist/chats/chat-book.d.ts +105 -0
- package/dist/chats/chat-book.js +180 -0
- package/dist/chats/chat-book.js.map +1 -0
- package/dist/chats/conversation.d.ts +54 -0
- package/dist/chats/conversation.js +188 -0
- package/dist/chats/conversation.js.map +1 -0
- package/dist/chats/local.d.ts +46 -0
- package/dist/chats/local.js +184 -0
- package/dist/chats/local.js.map +1 -0
- package/dist/chats/migration.d.ts +12 -0
- package/dist/chats/migration.js +62 -0
- package/dist/chats/migration.js.map +1 -0
- package/dist/chats/service.d.ts +81 -0
- package/dist/chats/service.js +122 -0
- package/dist/chats/service.js.map +1 -0
- package/dist/chats/store.d.ts +132 -0
- package/dist/chats/store.js +181 -0
- package/dist/chats/store.js.map +1 -0
- package/dist/chats/task-chats.d.ts +52 -0
- package/dist/chats/task-chats.js +96 -0
- package/dist/chats/task-chats.js.map +1 -0
- package/dist/cli/chats.d.ts +45 -0
- package/dist/cli/chats.js +108 -0
- package/dist/cli/chats.js.map +1 -0
- package/dist/cli/commands/add.js +32 -22
- package/dist/cli/commands/add.js.map +1 -1
- package/dist/cli/commands/answer.d.ts +2 -1
- package/dist/cli/commands/answer.js +35 -41
- package/dist/cli/commands/answer.js.map +1 -1
- package/dist/cli/commands/ask.d.ts +7 -0
- package/dist/cli/commands/ask.js +37 -0
- package/dist/cli/commands/ask.js.map +1 -0
- package/dist/cli/commands/boilerplates.js +14 -3
- package/dist/cli/commands/boilerplates.js.map +1 -1
- package/dist/cli/commands/chat.d.ts +9 -0
- package/dist/cli/commands/chat.js +89 -0
- package/dist/cli/commands/chat.js.map +1 -0
- package/dist/cli/commands/dashboard.d.ts +3 -1
- package/dist/cli/commands/dashboard.js +41 -3
- package/dist/cli/commands/dashboard.js.map +1 -1
- package/dist/cli/commands/find.js +6 -8
- package/dist/cli/commands/find.js.map +1 -1
- package/dist/cli/commands/fix.js +4 -6
- package/dist/cli/commands/fix.js.map +1 -1
- package/dist/cli/commands/init.d.ts +0 -1
- package/dist/cli/commands/init.js +38 -38
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/lint.js +16 -2
- package/dist/cli/commands/lint.js.map +1 -1
- package/dist/cli/commands/list.js +21 -13
- package/dist/cli/commands/list.js.map +1 -1
- package/dist/cli/commands/migrate.d.ts +2 -1
- package/dist/cli/commands/migrate.js +70 -24
- package/dist/cli/commands/migrate.js.map +1 -1
- package/dist/cli/commands/pause.d.ts +8 -0
- package/dist/cli/commands/pause.js +40 -0
- package/dist/cli/commands/pause.js.map +1 -0
- package/dist/cli/commands/plan.js +6 -9
- package/dist/cli/commands/plan.js.map +1 -1
- package/dist/cli/commands/recover.js +7 -3
- package/dist/cli/commands/recover.js.map +1 -1
- package/dist/cli/commands/restart.d.ts +3 -1
- package/dist/cli/commands/restart.js +74 -18
- package/dist/cli/commands/restart.js.map +1 -1
- package/dist/cli/commands/resume.d.ts +8 -0
- package/dist/cli/commands/resume.js +15 -0
- package/dist/cli/commands/resume.js.map +1 -0
- package/dist/cli/commands/run.js +6 -9
- package/dist/cli/commands/run.js.map +1 -1
- package/dist/cli/commands/start.js +40 -36
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/cli/commands/status.d.ts +2 -1
- package/dist/cli/commands/status.js +5 -1
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/stop.d.ts +3 -1
- package/dist/cli/commands/stop.js +18 -8
- package/dist/cli/commands/stop.js.map +1 -1
- package/dist/cli/commands/verify.js +7 -7
- package/dist/cli/commands/verify.js.map +1 -1
- package/dist/cli/common.d.ts +13 -0
- package/dist/cli/common.js +22 -0
- package/dist/cli/common.js.map +1 -1
- package/dist/cli/engine-delegation.d.ts +14 -0
- package/dist/cli/engine-delegation.js +46 -0
- package/dist/cli/engine-delegation.js.map +1 -0
- package/dist/cli/lifecycle.d.ts +40 -0
- package/dist/cli/lifecycle.js +71 -0
- package/dist/cli/lifecycle.js.map +1 -0
- package/dist/cli/registry.js +113 -31
- package/dist/cli/registry.js.map +1 -1
- package/dist/cli/service-view.d.ts +14 -2
- package/dist/cli/service-view.js +46 -5
- package/dist/cli/service-view.js.map +1 -1
- package/dist/cli/sources.js +5 -8
- package/dist/cli/sources.js.map +1 -1
- package/dist/cli/spec.js +1 -1
- package/dist/cli/spec.js.map +1 -1
- package/dist/common/app-data.d.ts +9 -0
- package/dist/common/app-data.js +20 -0
- package/dist/common/app-data.js.map +1 -0
- package/dist/common/errors.d.ts +2 -0
- package/dist/common/errors.js.map +1 -1
- package/dist/common/time.d.ts +6 -0
- package/dist/common/time.js +9 -0
- package/dist/common/time.js.map +1 -1
- package/dist/engine/agenda.d.ts +213 -43
- package/dist/engine/agenda.js +846 -260
- package/dist/engine/agenda.js.map +1 -1
- package/dist/engine/executor.d.ts +23 -7
- package/dist/engine/executor.js +131 -84
- package/dist/engine/executor.js.map +1 -1
- package/dist/engine/generated.d.ts +21 -1
- package/dist/engine/generated.js +36 -21
- package/dist/engine/generated.js.map +1 -1
- package/dist/engine/preview.js +10 -10
- package/dist/engine/preview.js.map +1 -1
- package/dist/engine/prompt.d.ts +16 -4
- package/dist/engine/prompt.js +22 -4
- package/dist/engine/prompt.js.map +1 -1
- package/dist/engine/routing.js +28 -4
- package/dist/engine/routing.js.map +1 -1
- package/dist/engine/snapshot.d.ts +178 -29
- package/dist/engine/state.d.ts +40 -13
- package/dist/engine/state.js +20 -5
- package/dist/engine/state.js.map +1 -1
- package/dist/engine/task-trace.d.ts +35 -7
- package/dist/engine/task-trace.js +74 -15
- package/dist/engine/task-trace.js.map +1 -1
- package/dist/engine/team.d.ts +20 -7
- package/dist/engine/team.js +30 -24
- package/dist/engine/team.js.map +1 -1
- package/dist/engine/traces.d.ts +1 -1
- package/dist/engine/traces.js +1 -1
- package/dist/expert/_main.md +67 -52
- package/dist/expert/agents/_index.md +11 -13
- package/dist/expert/agents/chatter.md +31 -0
- package/dist/expert/agents/consistency.md +6 -11
- package/dist/expert/agents/core-agents.md +9 -7
- package/dist/expert/agents/expert.md +2 -2
- package/dist/expert/agents/fixer.md +24 -0
- package/dist/expert/agents/learning.md +1 -1
- package/dist/expert/agents/non-agents.md +6 -4
- package/dist/expert/agents/teacher.md +1 -1
- package/dist/expert/agents/visual-identity.md +4 -4
- package/dist/expert/book-language/_index.md +9 -8
- package/dist/expert/book-language/commitments/_index.md +23 -3
- package/dist/expert/book-language/commitments/agent.md +11 -0
- package/dist/expert/book-language/commitments/chat-member.md +7 -0
- package/dist/expert/book-language/commitments/chat-message.md +11 -0
- package/dist/expert/book-language/commitments/chat-status.md +7 -0
- package/dist/expert/book-language/commitments/chat.md +11 -0
- package/dist/expert/book-language/commitments/entity.md +9 -0
- package/dist/expert/book-language/commitments/from.md +1 -1
- package/dist/expert/book-language/commitments/goal.md +6 -2
- package/dist/expert/book-language/commitments/link.md +9 -0
- package/dist/expert/book-language/commitments/task-depends-on.md +1 -1
- package/dist/expert/book-language/commitments/task-parent.md +1 -1
- package/dist/expert/book-language/commitments/task.md +7 -3
- package/dist/expert/book-language/commitments/team.md +1 -1
- package/dist/expert/book-language/inheritance.md +2 -2
- package/dist/expert/book-language/references.md +20 -24
- package/dist/expert/book-language/syntax.md +54 -11
- package/dist/expert/cli/acceptance.md +59 -24
- package/dist/expert/cli/api.md +23 -9
- package/dist/expert/cli/authoring.md +6 -4
- package/dist/expert/cli/autonomous-operation.md +3 -3
- package/dist/expert/cli/browser.md +29 -18
- package/dist/expert/cli/channels.md +5 -7
- package/dist/expert/cli/chat-ui.md +32 -0
- package/dist/expert/cli/chats.md +59 -0
- package/dist/expert/cli/cli.md +44 -26
- package/dist/expert/cli/configuration.md +3 -3
- package/dist/expert/cli/controls.md +13 -7
- package/dist/expert/cli/dashboard-details.md +23 -0
- package/dist/expert/cli/dashboard-layout.md +19 -12
- package/dist/expert/cli/dashboard.md +12 -8
- package/dist/expert/cli/execution.md +8 -6
- package/dist/expert/cli/first-task.md +4 -4
- package/dist/expert/cli/generated-names.md +44 -0
- package/dist/expert/cli/git-persistence.md +19 -17
- package/dist/expert/cli/global-dashboard.md +33 -0
- package/dist/expert/cli/goal-discovery.md +1 -1
- package/dist/expert/cli/help.md +1 -1
- package/dist/expert/cli/initialization-ui.md +2 -0
- package/dist/expert/cli/initialization.md +9 -7
- package/dist/expert/cli/interactive-ui.md +9 -5
- package/dist/expert/cli/locking.md +21 -0
- package/dist/expert/cli/migration.md +22 -6
- package/dist/expert/cli/process-modes.md +21 -13
- package/dist/expert/cli/recovery.md +8 -6
- package/dist/expert/cli/recurrence.md +1 -1
- package/dist/expert/cli/rich-input.md +2 -2
- package/dist/expert/cli/service-lifecycle.md +57 -0
- package/dist/expert/cli/start.md +2 -2
- package/dist/expert/cli/status-view.md +16 -12
- package/dist/expert/cli/task-books.md +11 -15
- package/dist/expert/cli/task-identity.md +8 -10
- package/dist/expert/cli/task-markdown.md +6 -10
- package/dist/expert/cli/task-origins.md +3 -1
- package/dist/expert/cli/task-relationships.md +5 -9
- package/dist/expert/cli/team.md +17 -7
- package/dist/expert/cli/terminal.md +20 -12
- package/dist/expert/cli/trace-configuration.md +1 -1
- package/dist/expert/cli/traces.md +19 -23
- package/dist/expert/cli/user-interactions.md +14 -26
- package/dist/expert/cli/workspace.md +15 -9
- package/dist/expert/concepts/engine-and-project.md +11 -0
- package/dist/expert/concepts/project-model.md +39 -0
- package/dist/expert/dictionary.md +21 -15
- package/dist/harness/plugins/claude-code/index.js +1 -0
- package/dist/harness/plugins/claude-code/index.js.map +1 -1
- package/dist/harness/plugins/cline/index.js +1 -0
- package/dist/harness/plugins/cline/index.js.map +1 -1
- package/dist/harness/plugins/openai-codex/index.js +1 -0
- package/dist/harness/plugins/openai-codex/index.js.map +1 -1
- package/dist/harness/plugins/opencode/index.js +1 -0
- package/dist/harness/plugins/opencode/index.js.map +1 -1
- package/dist/harness/types.d.ts +3 -1
- package/dist/project/agents.d.ts +29 -81
- package/dist/project/agents.js +48 -267
- package/dist/project/agents.js.map +1 -1
- package/dist/project/books.d.ts +150 -0
- package/dist/project/books.js +253 -0
- package/dist/project/books.js.map +1 -0
- package/dist/project/config.js +2 -2
- package/dist/project/config.js.map +1 -1
- package/dist/project/defaults.d.ts +35 -6
- package/dist/project/defaults.js +73 -40
- package/dist/project/defaults.js.map +1 -1
- package/dist/project/expert.js +18 -10
- package/dist/project/expert.js.map +1 -1
- package/dist/project/git.d.ts +4 -3
- package/dist/project/git.js +16 -5
- package/dist/project/git.js.map +1 -1
- package/dist/project/setup.d.ts +4 -1
- package/dist/project/setup.js +26 -6
- package/dist/project/setup.js.map +1 -1
- package/dist/service/actions.d.ts +34 -10
- package/dist/service/actions.js +51 -19
- package/dist/service/actions.js.map +1 -1
- package/dist/service/control.d.ts +53 -1
- package/dist/service/control.js +64 -4
- package/dist/service/control.js.map +1 -1
- package/dist/service/discovery.d.ts +133 -0
- package/dist/service/discovery.js +138 -0
- package/dist/service/discovery.js.map +1 -0
- package/dist/service/host.d.ts +8 -1
- package/dist/service/host.js +65 -18
- package/dist/service/host.js.map +1 -1
- package/dist/service/http.d.ts +3 -0
- package/dist/service/http.js +26 -6
- package/dist/service/http.js.map +1 -1
- package/dist/service/launcher.d.ts +66 -13
- package/dist/service/launcher.js +78 -18
- package/dist/service/launcher.js.map +1 -1
- package/dist/service/records.d.ts +12 -2
- package/dist/service/records.js +19 -5
- package/dist/service/records.js.map +1 -1
- package/dist/service/spa/app.css +83 -2
- package/dist/service/spa/app.js +393 -72
- package/dist/service/supervisor.js +7 -1
- package/dist/service/supervisor.js.map +1 -1
- package/dist/service/worker.js +14 -5
- package/dist/service/worker.js.map +1 -1
- package/dist/tasks/authoring.d.ts +3 -5
- package/dist/tasks/authoring.js +6 -7
- package/dist/tasks/authoring.js.map +1 -1
- package/dist/tasks/book-task.d.ts +18 -10
- package/dist/tasks/book-task.js +27 -23
- package/dist/tasks/book-task.js.map +1 -1
- package/dist/tasks/eligibility.d.ts +15 -7
- package/dist/tasks/eligibility.js +41 -14
- package/dist/tasks/eligibility.js.map +1 -1
- package/dist/tasks/identity.d.ts +41 -15
- package/dist/tasks/identity.js +100 -31
- package/dist/tasks/identity.js.map +1 -1
- package/dist/tasks/markdown.d.ts +7 -14
- package/dist/tasks/markdown.js +15 -29
- package/dist/tasks/markdown.js.map +1 -1
- package/dist/tasks/model.d.ts +20 -4
- package/dist/tasks/model.js +17 -0
- package/dist/tasks/model.js.map +1 -1
- package/dist/tasks/sources.d.ts +7 -2
- package/dist/tasks/sources.js +46 -35
- package/dist/tasks/sources.js.map +1 -1
- package/dist/ui/chat-client.d.ts +70 -0
- package/dist/ui/chat-client.js +209 -0
- package/dist/ui/chat-client.js.map +1 -0
- package/dist/ui/dashboard.d.ts +8 -5
- package/dist/ui/dashboard.js +227 -86
- package/dist/ui/dashboard.js.map +1 -1
- package/dist/ui/details.d.ts +64 -0
- package/dist/ui/details.js +175 -0
- package/dist/ui/details.js.map +1 -0
- package/dist/ui/global-dashboard.d.ts +59 -0
- package/dist/ui/global-dashboard.js +307 -0
- package/dist/ui/global-dashboard.js.map +1 -0
- package/dist/ui/status-view.d.ts +7 -0
- package/dist/ui/status-view.js +94 -36
- package/dist/ui/status-view.js.map +1 -1
- package/package.json +1 -1
- package/dist/engine/requests.d.ts +0 -111
- package/dist/engine/requests.js +0 -173
- package/dist/engine/requests.js.map +0 -1
- package/dist/expert/book-language/commitments/task-id.md +0 -9
- package/dist/tasks/prepare.d.ts +0 -33
- package/dist/tasks/prepare.js +0 -90
- package/dist/tasks/prepare.js.map +0 -1
|
@@ -1,27 +1,51 @@
|
|
|
1
1
|
import type { Agenda } from '../engine/agenda.js';
|
|
2
|
-
import type { UserRequest } from '../engine/requests.js';
|
|
3
2
|
/**
|
|
4
|
-
* Runtime actions shared by every channel (terminal, browser, API,
|
|
3
|
+
* Runtime actions shared by every channel (CLI, terminal, browser, API): the engine's lifecycle operations, wait
|
|
4
|
+
* skipping and coordinated project-browser recovery. `stop-now`/`cancel-stop` remain as compatibility aliases.
|
|
5
5
|
*
|
|
6
6
|
* @private shared runtime controls
|
|
7
7
|
*/
|
|
8
|
-
export type ControlAction = 'pause' | 'resume' | 'skip-wait' | 'stop' | 'stop-now' | 'cancel-stop';
|
|
8
|
+
export type ControlAction = 'pause' | 'resume' | 'skip-wait' | 'stop' | 'force-stop' | 'restart' | 'stop-now' | 'cancel-stop' | 'browser-recheck' | 'browser-retry' | 'browser-restart';
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Every control action name (for request validation).
|
|
11
11
|
*
|
|
12
12
|
* @private shared runtime controls
|
|
13
13
|
*/
|
|
14
|
-
export declare
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
export declare const CONTROL_ACTIONS: ReadonlySet<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Outcome of a control action as every client reports it.
|
|
17
|
+
*
|
|
18
|
+
* @private shared runtime controls
|
|
19
|
+
*/
|
|
20
|
+
export type ControlOutcome = {
|
|
21
|
+
readonly action: string;
|
|
22
|
+
readonly outcome: string;
|
|
23
|
+
readonly applied: boolean;
|
|
24
|
+
readonly completed?: boolean;
|
|
25
|
+
readonly state?: string;
|
|
18
26
|
};
|
|
19
27
|
/**
|
|
20
|
-
*
|
|
28
|
+
* Engine-owned browser recovery operations (the service owns the project browser).
|
|
29
|
+
*
|
|
30
|
+
* @private shared runtime controls
|
|
31
|
+
*/
|
|
32
|
+
export type BrowserControls = {
|
|
33
|
+
readonly recheck: () => Promise<ControlOutcome>;
|
|
34
|
+
readonly retry: () => Promise<ControlOutcome>;
|
|
35
|
+
readonly restart: () => Promise<ControlOutcome>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Applies one runtime control action and reports its actual outcome (accepted/pending versus completed).
|
|
39
|
+
*
|
|
40
|
+
* @private shared runtime controls
|
|
41
|
+
*/
|
|
42
|
+
export declare function applyControlAction(agenda: Agenda, action: string, params?: Readonly<Record<string, unknown>>, browser?: BrowserControls): Promise<ControlOutcome>;
|
|
43
|
+
/**
|
|
44
|
+
* Chat operations shared by every channel (terminal, browser, API, CLI); writes go through the agenda's chat store.
|
|
21
45
|
*
|
|
22
46
|
* @private shared runtime controls
|
|
23
47
|
*/
|
|
24
|
-
export declare function
|
|
48
|
+
export declare function applyChatAction(agenda: Agenda, method: string, params: Readonly<Record<string, unknown>>, via: string): Promise<unknown>;
|
|
25
49
|
/**
|
|
26
50
|
* Validates raw setting changes from a channel and applies them (temporary unless saved).
|
|
27
51
|
*
|
package/dist/service/actions.js
CHANGED
|
@@ -1,46 +1,78 @@
|
|
|
1
1
|
import { PtbkError } from '../common/errors.js';
|
|
2
2
|
import { parseSettingValue, SETTING_SPEC_BY_KEY } from '../project/config.js';
|
|
3
|
+
import { defaultChatAgent } from '../chats/service.js';
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* Every control action name (for request validation).
|
|
5
6
|
*
|
|
6
7
|
* @private shared runtime controls
|
|
7
8
|
*/
|
|
8
|
-
export
|
|
9
|
+
export const CONTROL_ACTIONS = new Set(['pause', 'resume', 'skip-wait', 'stop', 'force-stop', 'restart', 'stop-now', 'cancel-stop', 'browser-recheck', 'browser-retry', 'browser-restart']);
|
|
10
|
+
/**
|
|
11
|
+
* Applies one runtime control action and reports its actual outcome (accepted/pending versus completed).
|
|
12
|
+
*
|
|
13
|
+
* @private shared runtime controls
|
|
14
|
+
*/
|
|
15
|
+
export async function applyControlAction(agenda, action, params = {}, browser) {
|
|
9
16
|
switch (action) {
|
|
10
17
|
case 'pause':
|
|
11
|
-
return {
|
|
18
|
+
return agenda.pause({ replaceStop: params.replaceStop === true, revision: typeof params.revision === 'number' ? params.revision : undefined });
|
|
12
19
|
case 'resume':
|
|
13
|
-
agenda.resume();
|
|
14
|
-
return { action, outcome: 'Resumed.', applied: true };
|
|
20
|
+
return agenda.resume();
|
|
15
21
|
case 'skip-wait': {
|
|
16
22
|
const result = agenda.skipWait();
|
|
17
23
|
return { action, outcome: result.applied ? 'Wait skipped.' : (result.reason ?? 'Nothing to skip.'), applied: result.applied };
|
|
18
24
|
}
|
|
19
25
|
case 'stop':
|
|
20
|
-
agenda.requestStop({
|
|
21
|
-
|
|
26
|
+
return agenda.requestStop({});
|
|
27
|
+
case 'force-stop':
|
|
22
28
|
case 'stop-now':
|
|
23
|
-
agenda.requestStop({
|
|
24
|
-
|
|
29
|
+
return agenda.requestStop({ force: true });
|
|
30
|
+
case 'restart':
|
|
31
|
+
return agenda.requestStop({ restart: true });
|
|
25
32
|
case 'cancel-stop':
|
|
26
|
-
agenda.cancelStop();
|
|
27
|
-
|
|
33
|
+
return agenda.cancelStop();
|
|
34
|
+
case 'browser-recheck':
|
|
35
|
+
case 'browser-retry':
|
|
36
|
+
case 'browser-restart': {
|
|
37
|
+
if (!browser)
|
|
38
|
+
return { action, outcome: 'This process does not own a project browser.', applied: false };
|
|
39
|
+
return action === 'browser-recheck' ? await browser.recheck() : action === 'browser-retry' ? await browser.retry() : await browser.restart();
|
|
40
|
+
}
|
|
28
41
|
default:
|
|
29
42
|
throw new PtbkError(`Unknown control action "${action}".`, { kind: 'usage' });
|
|
30
43
|
}
|
|
31
44
|
}
|
|
32
45
|
/**
|
|
33
|
-
*
|
|
46
|
+
* Chat operations shared by every channel (terminal, browser, API, CLI); writes go through the agenda's chat store.
|
|
34
47
|
*
|
|
35
48
|
* @private shared runtime controls
|
|
36
49
|
*/
|
|
37
|
-
export async function
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
export async function applyChatAction(agenda, method, params, via) {
|
|
51
|
+
const text = (key) => (typeof params[key] === 'string' ? params[key] : '');
|
|
52
|
+
switch (method) {
|
|
53
|
+
case 'chat-list':
|
|
54
|
+
return await agenda.chatList();
|
|
55
|
+
case 'chat-agents':
|
|
56
|
+
return agenda.chatAgents();
|
|
57
|
+
case 'chat-get':
|
|
58
|
+
return await agenda.chatGet(text('name'));
|
|
59
|
+
case 'chat-read':
|
|
60
|
+
await agenda.chatRead(text('name'));
|
|
61
|
+
return { read: true };
|
|
62
|
+
case 'chat-create': {
|
|
63
|
+
// A new human chat without an explicit target goes to Chatter (diagnosed, never silently replaced).
|
|
64
|
+
const agent = text('agent') || defaultChatAgent(agenda.chatAgents()).reference;
|
|
65
|
+
const written = await agenda.chatCreate(agent, text('text'), { name: text('title') || undefined, requestKey: text('requestKey') || undefined });
|
|
66
|
+
return { name: written.chat.name, path: written.relativePath, commit: written.commit, messages: written.chat.messages.length };
|
|
67
|
+
}
|
|
68
|
+
case 'chat-send': {
|
|
69
|
+
const expected = typeof params.expected === 'number' ? params.expected : undefined;
|
|
70
|
+
const written = await agenda.chatSend(text('name'), text('text'), { expected, via });
|
|
71
|
+
return { name: written.chat.name, path: written.relativePath, commit: written.commit, messages: written.chat.messages.length, status: written.chat.status };
|
|
72
|
+
}
|
|
73
|
+
default:
|
|
74
|
+
throw new PtbkError(`Unknown chat action "${method}".`, { kind: 'usage' });
|
|
75
|
+
}
|
|
44
76
|
}
|
|
45
77
|
/**
|
|
46
78
|
* Validates raw setting changes from a channel and applies them (temporary unless saved).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/service/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../src/service/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAUvD;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE,iBAAiB,CAAC,CAAC,CAAC;AAoBhO;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,MAAc,EAAE,MAAc,EAAE,SAA4C,EAAE,EAAE,OAAyB;IAC9I,QAAQ,MAAM,EAAE,CAAC;QACb,KAAK,OAAO;YACR,OAAO,MAAM,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,KAAK,IAAI,EAAE,QAAQ,EAAE,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QACnJ,KAAK,QAAQ;YACT,OAAO,MAAM,CAAC,MAAM,EAAE,CAAC;QAC3B,KAAK,WAAW,CAAC,CAAC,CAAC;YACf,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ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YAAE,MAAM,IAAI,SAAS,CAAC,mBAAmB,GAAG,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;QAC7E,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,CAAC,EAAE;YAAE,MAAM,IAAI,SAAS,CAAC,qBAAqB,GAAG,KAAK,MAAM,CAAC,OAAO,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;QACvG,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;IAC/B,CAAC;IACD,OAAO,MAAM,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PtbkError } from '../common/errors.js';
|
|
1
2
|
import { type IpcServer } from '../common/ipc.js';
|
|
2
3
|
import type { Project } from '../project/workspace.js';
|
|
3
4
|
import { type ProcessRecord } from './records.js';
|
|
@@ -7,6 +8,52 @@ import { type ProcessRecord } from './records.js';
|
|
|
7
8
|
* @private service control
|
|
8
9
|
*/
|
|
9
10
|
export declare const READ_ONLY_METHODS: Set<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Version of the control contract: the shapes of snapshots and control replies that clients render.
|
|
13
|
+
*
|
|
14
|
+
* Engines and clients of different ptbk versions interoperate only when their contracts match. Bump it with every
|
|
15
|
+
* change that a client of the previous contract could misread (a removed, renamed or retyped field or method); a new
|
|
16
|
+
* snapshot field keeps the contract only when it is optional, so clients must handle its absence.
|
|
17
|
+
*
|
|
18
|
+
* @private service control
|
|
19
|
+
*/
|
|
20
|
+
export declare const CONTROL_CONTRACT = 2;
|
|
21
|
+
/**
|
|
22
|
+
* Identity of the engine behind a control endpoint, as reported by its `identify` method.
|
|
23
|
+
*
|
|
24
|
+
* @private service control
|
|
25
|
+
*/
|
|
26
|
+
export type EngineIdentity = {
|
|
27
|
+
/** Engine version actually loaded by the service (not this client's version). */
|
|
28
|
+
readonly version: string;
|
|
29
|
+
/** Control contract of the engine (absent for engines that predate it). */
|
|
30
|
+
readonly contract?: number;
|
|
31
|
+
/** Whether this client can read the engine's snapshots. */
|
|
32
|
+
readonly compatible: boolean;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Whether this client can read snapshots of an engine: the same version, or a matching control contract.
|
|
36
|
+
*
|
|
37
|
+
* @private service control
|
|
38
|
+
*/
|
|
39
|
+
export declare function engineIdentityOf(reported: {
|
|
40
|
+
readonly version?: unknown;
|
|
41
|
+
readonly contract?: unknown;
|
|
42
|
+
}, record: ProcessRecord): EngineIdentity;
|
|
43
|
+
/**
|
|
44
|
+
* CLI entry point of the installation that runs a service (it may since have been removed or upgraded).
|
|
45
|
+
*
|
|
46
|
+
* @private service control
|
|
47
|
+
*/
|
|
48
|
+
export declare function engineBin(record: ProcessRecord): string;
|
|
49
|
+
/**
|
|
50
|
+
* Actionable error of a client that cannot read the snapshots of an engine of another version.
|
|
51
|
+
*
|
|
52
|
+
* @private service control
|
|
53
|
+
*/
|
|
54
|
+
export declare function incompatibleEngineError(project: Project, record: ProcessRecord, engine: EngineIdentity, options?: {
|
|
55
|
+
readonly installationGone?: boolean;
|
|
56
|
+
}): PtbkError;
|
|
10
57
|
/**
|
|
11
58
|
* Handler of control methods.
|
|
12
59
|
*
|
|
@@ -27,6 +74,7 @@ export declare function startControlServer(address: string, token: string, handl
|
|
|
27
74
|
export type ServiceLookup = {
|
|
28
75
|
readonly state: 'running';
|
|
29
76
|
readonly record: ProcessRecord;
|
|
77
|
+
readonly engine: EngineIdentity;
|
|
30
78
|
readonly client: ControlClient;
|
|
31
79
|
} | {
|
|
32
80
|
readonly state: 'stopped';
|
|
@@ -44,7 +92,11 @@ export type ServiceLookup = {
|
|
|
44
92
|
export declare class ControlClient {
|
|
45
93
|
private readonly project;
|
|
46
94
|
readonly record: ProcessRecord;
|
|
47
|
-
|
|
95
|
+
/** Verified identity of the engine; snapshots of an incompatible engine are refused instead of misrendered. */
|
|
96
|
+
readonly engine?: EngineIdentity | undefined;
|
|
97
|
+
constructor(project: Project, record: ProcessRecord,
|
|
98
|
+
/** Verified identity of the engine; snapshots of an incompatible engine are refused instead of misrendered. */
|
|
99
|
+
engine?: EngineIdentity | undefined);
|
|
48
100
|
/**
|
|
49
101
|
* Sends a control request. Read-only requests retry briefly (re-authenticating the current record); a lost
|
|
50
102
|
* reply to a mutating request is reported as unconfirmed and never replayed.
|
package/dist/service/control.js
CHANGED
|
@@ -1,13 +1,66 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
1
2
|
import { PtbkError } from '../common/errors.js';
|
|
2
3
|
import { IpcError, ipcRequest, startIpcServer } from '../common/ipc.js';
|
|
3
4
|
import { isProcessAlive } from '../common/process.js';
|
|
5
|
+
import { ENGINE_VERSION } from '../common/version.js';
|
|
4
6
|
import { readProcessRecord } from './records.js';
|
|
5
7
|
/**
|
|
6
8
|
* Control methods that only read state (safe to retry).
|
|
7
9
|
*
|
|
8
10
|
* @private service control
|
|
9
11
|
*/
|
|
10
|
-
export const READ_ONLY_METHODS = new Set(['identify', 'snapshot', 'watch', 'requests', 'devices']);
|
|
12
|
+
export const READ_ONLY_METHODS = new Set(['identify', 'snapshot', 'summary', 'watch', 'requests', 'devices', 'chat-list', 'chat-agents', 'chat-get']);
|
|
13
|
+
/**
|
|
14
|
+
* Version of the control contract: the shapes of snapshots and control replies that clients render.
|
|
15
|
+
*
|
|
16
|
+
* Engines and clients of different ptbk versions interoperate only when their contracts match. Bump it with every
|
|
17
|
+
* change that a client of the previous contract could misread (a removed, renamed or retyped field or method); a new
|
|
18
|
+
* snapshot field keeps the contract only when it is optional, so clients must handle its absence.
|
|
19
|
+
*
|
|
20
|
+
* @private service control
|
|
21
|
+
*/
|
|
22
|
+
export const CONTROL_CONTRACT = 2;
|
|
23
|
+
/**
|
|
24
|
+
* Control methods whose replies are rendered as a service snapshot; reading them from an engine of another
|
|
25
|
+
* contract would misrender (or crash) the client.
|
|
26
|
+
*/
|
|
27
|
+
const SNAPSHOT_METHODS = new Set(['snapshot', 'watch']);
|
|
28
|
+
/**
|
|
29
|
+
* Whether this client can read snapshots of an engine: the same version, or a matching control contract.
|
|
30
|
+
*
|
|
31
|
+
* @private service control
|
|
32
|
+
*/
|
|
33
|
+
export function engineIdentityOf(reported, record) {
|
|
34
|
+
const version = typeof reported.version === 'string' ? reported.version : record.engineVersion;
|
|
35
|
+
const contract = typeof reported.contract === 'number' ? reported.contract : undefined;
|
|
36
|
+
return { version, contract, compatible: version === ENGINE_VERSION || contract === CONTROL_CONTRACT };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* CLI entry point of the installation that runs a service (it may since have been removed or upgraded).
|
|
40
|
+
*
|
|
41
|
+
* @private service control
|
|
42
|
+
*/
|
|
43
|
+
export function engineBin(record) {
|
|
44
|
+
return join(record.installation, 'bin', 'ptbk.js');
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Actionable error of a client that cannot read the snapshots of an engine of another version.
|
|
48
|
+
*
|
|
49
|
+
* @private service control
|
|
50
|
+
*/
|
|
51
|
+
export function incompatibleEngineError(project, record, engine, options = {}) {
|
|
52
|
+
return new PtbkError(`The running service uses ptbk ${engine.version}; this ptbk ${ENGINE_VERSION} cannot read its status.`, {
|
|
53
|
+
kind: 'unsupported',
|
|
54
|
+
project: project.root,
|
|
55
|
+
reason: `The control contract differs (service ${engine.contract ?? 'unknown'}, this client ${CONTROL_CONTRACT})${options.installationGone ? `, and the service's installation at ${record.installation} no longer holds ptbk ${engine.version}` : ''}.`,
|
|
56
|
+
effect: 'Nothing was changed; the service keeps running.',
|
|
57
|
+
next: [
|
|
58
|
+
...(options.installationGone ? [] : [`Use the service's own installation: \`node "${engineBin(record)}" dashboard\`.`]),
|
|
59
|
+
`Switch the service to ptbk ${ENGINE_VERSION}: \`ptbk stop\`, then \`ptbk start\` (unfinished work keeps its recovery record).`,
|
|
60
|
+
`Or view it with its own version: \`npx ptbk@${engine.version} dashboard\`.`,
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
}
|
|
11
64
|
/**
|
|
12
65
|
* Starts the control server of a running process.
|
|
13
66
|
*
|
|
@@ -31,15 +84,21 @@ export async function startControlServer(address, token, handler) {
|
|
|
31
84
|
export class ControlClient {
|
|
32
85
|
project;
|
|
33
86
|
record;
|
|
34
|
-
|
|
87
|
+
engine;
|
|
88
|
+
constructor(project, record,
|
|
89
|
+
/** Verified identity of the engine; snapshots of an incompatible engine are refused instead of misrendered. */
|
|
90
|
+
engine) {
|
|
35
91
|
this.project = project;
|
|
36
92
|
this.record = record;
|
|
93
|
+
this.engine = engine;
|
|
37
94
|
}
|
|
38
95
|
/**
|
|
39
96
|
* Sends a control request. Read-only requests retry briefly (re-authenticating the current record); a lost
|
|
40
97
|
* reply to a mutating request is reported as unconfirmed and never replayed.
|
|
41
98
|
*/
|
|
42
99
|
async request(method, params = {}, timeoutMs = 30_000) {
|
|
100
|
+
if (this.engine && !this.engine.compatible && SNAPSHOT_METHODS.has(method))
|
|
101
|
+
throw incompatibleEngineError(this.project, this.record, this.engine);
|
|
43
102
|
const readOnly = READ_ONLY_METHODS.has(method);
|
|
44
103
|
let record = this.record;
|
|
45
104
|
for (let attempt = 1;; attempt++) {
|
|
@@ -51,7 +110,7 @@ export class ControlClient {
|
|
|
51
110
|
throw error;
|
|
52
111
|
if (error.stage === 'remote') {
|
|
53
112
|
const details = error.details;
|
|
54
|
-
throw new PtbkError(error.message, { kind: details?.kind ?? 'technical', reason: details?.reason, next: details?.next });
|
|
113
|
+
throw new PtbkError(error.message, { kind: details?.kind ?? 'technical', reason: details?.reason, effect: details?.effect, next: details?.next, data: details?.data });
|
|
55
114
|
}
|
|
56
115
|
if (!readOnly) {
|
|
57
116
|
throw new PtbkError(error.stage === 'connect' ? 'The service did not accept the request.' : `The outcome of "${method}" is unconfirmed.`, {
|
|
@@ -92,7 +151,8 @@ export async function lookupService(project) {
|
|
|
92
151
|
const identity = await ipcRequest(record.controlAddress, { token: record.token, method: 'identify', params: {} }, 5000);
|
|
93
152
|
if (identity.instanceId !== record.instanceId)
|
|
94
153
|
return { state: 'unreachable', record, reason: 'The control endpoint belongs to a different instance.' };
|
|
95
|
-
|
|
154
|
+
const engine = engineIdentityOf(identity, record);
|
|
155
|
+
return { state: 'running', record, engine, client: new ControlClient(project, record, engine) };
|
|
96
156
|
}
|
|
97
157
|
catch (error) {
|
|
98
158
|
return { state: 'unreachable', record, reason: error instanceof Error ? error.message : String(error) };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"control.js","sourceRoot":"","sources":["../../src/service/control.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAkB,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,iBAAiB,EAAsB,MAAM,cAAc,CAAC;AAErE;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"control.js","sourceRoot":"","sources":["../../src/service/control.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAkB,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EA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3
|
+
* Version of the host-wide discovery contract (kept interoperable across engine versions).
|
|
4
|
+
*
|
|
5
|
+
* @private service discovery
|
|
6
|
+
*/
|
|
7
|
+
export declare const DISCOVERY_VERSION = 1;
|
|
8
|
+
/**
|
|
9
|
+
* One running engine as registered in the host-wide discovery registry (`<app data>/services/<instance>.json`).
|
|
10
|
+
*
|
|
11
|
+
* It points back to the verified owner of one concrete project. It is not a project lock, a credential (no control
|
|
12
|
+
* token) or a task store: connecting still requires the project's own owner-readable process record.
|
|
13
|
+
*
|
|
14
|
+
* @private service discovery
|
|
15
|
+
*/
|
|
16
|
+
export type DiscoveryEntry = {
|
|
17
|
+
readonly version: typeof DISCOVERY_VERSION;
|
|
18
|
+
/** Unique instance of the engine process. */
|
|
19
|
+
readonly instanceId: string;
|
|
20
|
+
/** PID of the process hosting the engine. */
|
|
21
|
+
readonly pid: number;
|
|
22
|
+
/** PID of the daemon supervisor, when any. */
|
|
23
|
+
readonly supervisorPid?: number;
|
|
24
|
+
/** Placement of the engine. */
|
|
25
|
+
readonly mode: 'daemon' | 'foreground' | 'run';
|
|
26
|
+
/** Canonical project directory the engine owns. */
|
|
27
|
+
readonly projectRoot: string;
|
|
28
|
+
/** Display name of the project. */
|
|
29
|
+
readonly projectName: string;
|
|
30
|
+
/** Engine version actually loaded by the process. */
|
|
31
|
+
readonly engineVersion: string;
|
|
32
|
+
/** Installation running the engine. */
|
|
33
|
+
readonly installation: string;
|
|
34
|
+
/** Local control endpoint (useless without the project's token). */
|
|
35
|
+
readonly controlAddress: string;
|
|
36
|
+
/** Engine start (ISO). */
|
|
37
|
+
readonly startedAt: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Directory of the registry for the current OS user (other users' engines are outside it by design).
|
|
41
|
+
*
|
|
42
|
+
* @private service discovery
|
|
43
|
+
*/
|
|
44
|
+
export declare function discoveryDirectory(env?: NodeJS.ProcessEnv): string;
|
|
45
|
+
/**
|
|
46
|
+
* Registers a running engine; returns the owner's own unregistration (it never touches other entries).
|
|
47
|
+
*
|
|
48
|
+
* @private service discovery
|
|
49
|
+
*/
|
|
50
|
+
export declare function registerEngine(entry: DiscoveryEntry, env?: NodeJS.ProcessEnv): Promise<() => Promise<void>>;
|
|
51
|
+
/**
|
|
52
|
+
* Reads every registration of this OS user. A missing registry is an empty (successful) result; an unreadable one is
|
|
53
|
+
* reported as a problem instead of being presented as zero services.
|
|
54
|
+
*
|
|
55
|
+
* @private service discovery
|
|
56
|
+
*/
|
|
57
|
+
export declare function readRegistry(env?: NodeJS.ProcessEnv): Promise<{
|
|
58
|
+
readonly entries: DiscoveryEntry[];
|
|
59
|
+
readonly problem?: string;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Compact live summary of one engine for the global table (the `summary` control method, or a full snapshot from
|
|
63
|
+
* engines that predate it).
|
|
64
|
+
*
|
|
65
|
+
* @private service discovery
|
|
66
|
+
*/
|
|
67
|
+
export type EngineSummary = {
|
|
68
|
+
readonly state: string;
|
|
69
|
+
readonly phase: string;
|
|
70
|
+
readonly intent?: string;
|
|
71
|
+
readonly work?: string;
|
|
72
|
+
readonly waitingChats: number;
|
|
73
|
+
readonly observedAt: string;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Observed status of one registration.
|
|
77
|
+
*
|
|
78
|
+
* @private service discovery
|
|
79
|
+
*/
|
|
80
|
+
export type DiscoveredEngine = {
|
|
81
|
+
readonly status: 'live';
|
|
82
|
+
readonly entry: DiscoveryEntry;
|
|
83
|
+
readonly client: ControlClient;
|
|
84
|
+
readonly summary: EngineSummary;
|
|
85
|
+
} | {
|
|
86
|
+
readonly status: 'unreachable';
|
|
87
|
+
readonly entry: DiscoveryEntry;
|
|
88
|
+
readonly reason: string;
|
|
89
|
+
} | {
|
|
90
|
+
readonly status: 'ended';
|
|
91
|
+
readonly entry: DiscoveryEntry;
|
|
92
|
+
readonly reason: string;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Verifies a registration against the project's own process record and the engine's control identity before it is
|
|
96
|
+
* shown as live. A proven-dead entry (process gone, or the project verifiably owned by another instance) is removed
|
|
97
|
+
* from the registry; nothing is killed and no project lock or project file is touched.
|
|
98
|
+
*
|
|
99
|
+
* @private service discovery
|
|
100
|
+
*/
|
|
101
|
+
export declare function verifyEngine(entry: DiscoveryEntry, env?: NodeJS.ProcessEnv): Promise<DiscoveredEngine>;
|
|
102
|
+
/**
|
|
103
|
+
* Minimal shape of a full snapshot (engines without the `summary` method).
|
|
104
|
+
*/
|
|
105
|
+
type SnapshotLike = {
|
|
106
|
+
readonly observedAt: string;
|
|
107
|
+
readonly phase: string;
|
|
108
|
+
readonly service: {
|
|
109
|
+
readonly state: string;
|
|
110
|
+
readonly lifecycle?: {
|
|
111
|
+
readonly intent?: string;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
readonly current?: {
|
|
115
|
+
readonly agent: {
|
|
116
|
+
readonly name: string;
|
|
117
|
+
};
|
|
118
|
+
readonly taskTitle: string;
|
|
119
|
+
};
|
|
120
|
+
readonly wait?: {
|
|
121
|
+
readonly reason: string;
|
|
122
|
+
};
|
|
123
|
+
readonly chats?: {
|
|
124
|
+
readonly waiting: readonly unknown[];
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Compact summary of a snapshot.
|
|
129
|
+
*
|
|
130
|
+
* @private service discovery
|
|
131
|
+
*/
|
|
132
|
+
export declare function summaryOfSnapshot(snapshot: SnapshotLike): EngineSummary;
|
|
133
|
+
export {};
|