@1agents/acp-service 0.8.2 → 0.9.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/README.md +6 -0
- package/dist/bin/a2a.js +10 -2
- package/dist/bin/acp-service.js +6 -0
- package/dist/bin/roles.d.ts +1 -0
- package/dist/bin/roles.js +24 -0
- package/dist/src/a2a/executor.d.ts +16 -1
- package/dist/src/a2a/executor.js +205 -19
- package/dist/src/a2a/gateway.d.ts +77 -0
- package/dist/src/a2a/gateway.js +349 -27
- package/dist/src/a2a/index.d.ts +7 -1
- package/dist/src/a2a/index.js +4 -0
- package/dist/src/a2a/result-metadata.d.ts +3 -0
- package/dist/src/a2a/result-metadata.js +2 -1
- package/dist/src/a2a/server.js +2 -1
- package/dist/src/a2a/store.js +7 -1
- package/dist/src/a2a/types.d.ts +32 -1
- package/dist/src/a2a/types.js +11 -1
- package/dist/src/acp-connection.js +93 -12
- package/dist/src/bridge.js +127 -4
- package/dist/src/capacity-lifecycle.d.ts +5 -0
- package/dist/src/capacity-lifecycle.js +57 -0
- package/dist/src/capacity-queue.d.ts +23 -0
- package/dist/src/capacity-queue.js +251 -0
- package/dist/src/capacity.d.ts +76 -0
- package/dist/src/capacity.js +377 -0
- package/dist/src/execution/human-review.d.ts +103 -0
- package/dist/src/execution/human-review.js +87 -0
- package/dist/src/execution/ledger.d.ts +5 -0
- package/dist/src/execution/ledger.js +39 -8
- package/dist/src/execution/ppt-delivery.d.ts +36 -3
- package/dist/src/execution/ppt-delivery.js +243 -53
- package/dist/src/execution/project-discovery.d.ts +56 -0
- package/dist/src/execution/project-discovery.js +429 -0
- package/dist/src/execution/report-review.d.ts +60 -0
- package/dist/src/execution/report-review.js +173 -0
- package/dist/src/execution/targets.d.ts +5 -0
- package/dist/src/execution/targets.js +1 -0
- package/dist/src/execution/workbench.d.ts +131 -0
- package/dist/src/execution/workbench.js +265 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +3 -0
- package/dist/src/roles/index.d.ts +1 -0
- package/dist/src/roles/index.js +1 -0
- package/dist/src/roles/skills.d.ts +71 -0
- package/dist/src/roles/skills.js +427 -0
- package/package.json +5 -1
- package/skills/acp-service/SKILL.md +21 -7
- package/skills/acp-service/references/a2a.md +9 -5
- package/skills/acp-service/references/async-caller.md +48 -0
- package/skills/acp-service/references/roles-and-tasks.md +120 -0
- package/skills/acp-service/scripts/a2a-caller.py +242 -0
- package/vendor/dsh/README.md +2 -0
- package/vendor/dsh/a2a-executor.d.ts +4 -1
- package/vendor/dsh/a2a-executor.js +46 -2
- package/vendor/dsh/adapter.d.ts +10 -0
- package/vendor/dsh/adapter.js +67 -3
- package/vendor/dsh/client.js +84 -24
- package/vendor/dsh/index.js +2 -1
- package/vendor/runtime/dist/{cli-DeOpE2Xz.js → cli-DXmYwv3U.js} +4 -4
- package/vendor/runtime/dist/{cli-DeOpE2Xz.js.map → cli-DXmYwv3U.js.map} +1 -1
- package/vendor/runtime/dist/cli.js +7 -7
- package/vendor/runtime/dist/client-VQsqcIOJ.d.ts.map +1 -1
- package/vendor/runtime/dist/docs-site/runtime-process-lifecycle.html +1 -0
- package/vendor/runtime/dist/{flows-oaBGn31w.js → flows-DJ17ajbw.js} +3 -3
- package/vendor/runtime/dist/{flows-oaBGn31w.js.map → flows-DJ17ajbw.js.map} +1 -1
- package/vendor/runtime/dist/flows.js +1 -1
- package/vendor/runtime/dist/{invocation-options-CUDEE8vW.js → invocation-options-PBfCgrdi.js} +3 -3
- package/vendor/runtime/dist/{invocation-options-CUDEE8vW.js.map → invocation-options-PBfCgrdi.js.map} +1 -1
- package/vendor/runtime/dist/{output-CFv3jcOQ.js → output-B3MDn7kv.js} +2 -2
- package/vendor/runtime/dist/{output-CFv3jcOQ.js.map → output-B3MDn7kv.js.map} +1 -1
- package/vendor/runtime/dist/{queue-owner-runtime-DvMJiGbP.js → queue-owner-runtime-DXCVngwU.js} +15 -8
- package/vendor/runtime/dist/queue-owner-runtime-DXCVngwU.js.map +1 -0
- package/vendor/runtime/dist/runtime.js +1 -1
- package/vendor/runtime/dist/{session-watch-Di-wIdCH.js → session-watch-DURyCw31.js} +2 -2
- package/vendor/runtime/dist/{session-watch-Di-wIdCH.js.map → session-watch-DURyCw31.js.map} +1 -1
- package/vendor/runtime/dist/queue-owner-runtime-DvMJiGbP.js.map +0 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/** The runtime owns child termination; capacity remains reserved until its exit is observed. */
|
|
2
|
+
export function createCapacityLifecycle(governor, source = 'automatic') {
|
|
3
|
+
const reservations = new Map();
|
|
4
|
+
const release = (launchId) => {
|
|
5
|
+
const entry = reservations.get(launchId);
|
|
6
|
+
if (!entry)
|
|
7
|
+
return Promise.resolve();
|
|
8
|
+
if (entry.releasing)
|
|
9
|
+
return entry.releasing;
|
|
10
|
+
const operation = (async () => {
|
|
11
|
+
try {
|
|
12
|
+
const lease = await entry.lease;
|
|
13
|
+
await lease.release();
|
|
14
|
+
if (reservations.get(launchId) === entry)
|
|
15
|
+
reservations.delete(launchId);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// Retain the entry and durable reservation so a later observation can retry.
|
|
19
|
+
console.warn('ACP capacity reservation cleanup failed; the reservation remains recorded.');
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
entry.releasing = undefined;
|
|
23
|
+
}
|
|
24
|
+
})();
|
|
25
|
+
entry.releasing = operation;
|
|
26
|
+
return operation;
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
async onBeforeSpawn(launch) {
|
|
30
|
+
if (reservations.has(launch.launchId))
|
|
31
|
+
throw new Error('ACP process launch already has a capacity reservation');
|
|
32
|
+
// Install the entry before awaiting admission so concurrent duplicate callbacks cannot leak a slot.
|
|
33
|
+
const entry = {
|
|
34
|
+
lease: Promise.resolve().then(() => governor.acquire({ kind: 'process', source, id: launch.launchId })),
|
|
35
|
+
};
|
|
36
|
+
reservations.set(launch.launchId, entry);
|
|
37
|
+
try {
|
|
38
|
+
await entry.lease;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (reservations.get(launch.launchId) === entry)
|
|
42
|
+
reservations.delete(launch.launchId);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
async onSpawned(process) {
|
|
47
|
+
const entry = reservations.get(process.launchId);
|
|
48
|
+
if (!entry)
|
|
49
|
+
throw new Error('ACP process launch has no capacity reservation');
|
|
50
|
+
const lease = await entry.lease;
|
|
51
|
+
// Propagate registration failures: the runtime then stops the child and reports its exit.
|
|
52
|
+
await lease.spawned(process.pid);
|
|
53
|
+
},
|
|
54
|
+
onSpawnFailed: failure => release(failure.launchId),
|
|
55
|
+
onExit: exit => release(exit.launchId),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type CapacityLease, type CapacityOptions, type CapacityRequest } from './capacity.js';
|
|
2
|
+
export interface CapacityQueueWaitOptions {
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
/** Called once only when admission actually has to wait. */
|
|
5
|
+
onPending?: () => void;
|
|
6
|
+
}
|
|
7
|
+
export interface CapacityQueueTimingOptions {
|
|
8
|
+
pollIntervalMs?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class CapacityQueue {
|
|
11
|
+
private readonly directory;
|
|
12
|
+
private readonly governor;
|
|
13
|
+
private readonly pollIntervalMs;
|
|
14
|
+
constructor(options?: CapacityOptions, timing?: CapacityQueueTimingOptions);
|
|
15
|
+
acquire(request: CapacityRequest, { signal, onPending }?: CapacityQueueWaitOptions): Promise<CapacityLease>;
|
|
16
|
+
private entryPath;
|
|
17
|
+
private readState;
|
|
18
|
+
private readJson;
|
|
19
|
+
private readEntry;
|
|
20
|
+
private removeEntry;
|
|
21
|
+
private writeJson;
|
|
22
|
+
private transaction;
|
|
23
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/** Durable device-wide FIFO admission for automatically invoked ACP work. */
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { closeSync, constants, fstatSync, fsyncSync, openSync, readFileSync, readdirSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
6
|
+
import { DirectoryLease } from './a2a/lease.js';
|
|
7
|
+
import { CapacityError, CapacityGovernor, resolveCapacityDirectory } from './capacity.js';
|
|
8
|
+
const tokenPattern = /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/;
|
|
9
|
+
const stateMessage = 'ACP capacity queue state is unavailable; check the local host queue state before retrying.';
|
|
10
|
+
const validRequest = (value) => !!value &&
|
|
11
|
+
(value.kind === 'task' || value.kind === 'process') &&
|
|
12
|
+
(value.source === 'automatic' || value.source === 'interactive') &&
|
|
13
|
+
typeof value.id === 'string' && !!value.id.trim() && value.id.length <= 4096;
|
|
14
|
+
const isPositiveInteger = (value) => Number.isSafeInteger(value) && value > 0;
|
|
15
|
+
/** Permission failures do not prove that a queued owner has exited. */
|
|
16
|
+
function isDead(pid) {
|
|
17
|
+
try {
|
|
18
|
+
process.kill(pid, 0);
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return error.code === 'ESRCH';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class CapacityQueue {
|
|
26
|
+
directory;
|
|
27
|
+
governor;
|
|
28
|
+
pollIntervalMs;
|
|
29
|
+
constructor(options = {}, timing = {}) {
|
|
30
|
+
this.directory = join(resolveCapacityDirectory(options), 'queue');
|
|
31
|
+
this.governor = new CapacityGovernor(options);
|
|
32
|
+
this.pollIntervalMs = timing.pollIntervalMs ?? 750;
|
|
33
|
+
if (!isPositiveInteger(this.pollIntervalMs))
|
|
34
|
+
throw new Error('ACP capacity queue poll interval must be a positive safe integer');
|
|
35
|
+
}
|
|
36
|
+
async acquire(request, { signal, onPending } = {}) {
|
|
37
|
+
if (!validRequest(request))
|
|
38
|
+
throw new Error('Invalid ACP capacity request');
|
|
39
|
+
signal?.throwIfAborted();
|
|
40
|
+
// Manual work keeps the governor's reserved interactive room even while automatic work waits.
|
|
41
|
+
if (request.source === 'interactive') {
|
|
42
|
+
const lease = await this.governor.acquire(request);
|
|
43
|
+
if (signal?.aborted) {
|
|
44
|
+
await lease.release();
|
|
45
|
+
signal.throwIfAborted();
|
|
46
|
+
}
|
|
47
|
+
return lease;
|
|
48
|
+
}
|
|
49
|
+
const entry = { ...request, version: 1, token: randomUUID(), ownerPid: process.pid,
|
|
50
|
+
enqueuedAt: Date.now(), sequence: 0 };
|
|
51
|
+
let queued = false;
|
|
52
|
+
let acquired;
|
|
53
|
+
let returned = false;
|
|
54
|
+
let reportedPending = false;
|
|
55
|
+
try {
|
|
56
|
+
await this.transaction(() => {
|
|
57
|
+
signal?.throwIfAborted();
|
|
58
|
+
const state = this.readState();
|
|
59
|
+
if (state.lastSequence >= Number.MAX_SAFE_INTEGER)
|
|
60
|
+
throw new Error(stateMessage);
|
|
61
|
+
entry.sequence = state.lastSequence + 1;
|
|
62
|
+
// Advance the durable counter before publishing the entry; a crash may leave a harmless gap.
|
|
63
|
+
this.writeJson(join(this.directory, 'counter.json'), { version: 1, lastSequence: entry.sequence });
|
|
64
|
+
queued = true;
|
|
65
|
+
this.writeJson(this.entryPath(entry.token), entry);
|
|
66
|
+
}, signal);
|
|
67
|
+
while (true) {
|
|
68
|
+
signal?.throwIfAborted();
|
|
69
|
+
await this.transaction(async () => {
|
|
70
|
+
signal?.throwIfAborted();
|
|
71
|
+
const state = this.readState();
|
|
72
|
+
const own = state.entries.find(item => item.token === entry.token);
|
|
73
|
+
if (!own || own.ownerPid !== process.pid || own.sequence !== entry.sequence)
|
|
74
|
+
throw new Error(stateMessage);
|
|
75
|
+
// Task and child-process capacity have separate FIFOs, avoiding a waiting parent blocking its child.
|
|
76
|
+
const head = state.entries.find(item => item.kind === request.kind);
|
|
77
|
+
if (head?.token !== entry.token)
|
|
78
|
+
return;
|
|
79
|
+
try {
|
|
80
|
+
acquired = await this.governor.acquire(request);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error instanceof CapacityError)
|
|
84
|
+
return;
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
signal?.throwIfAborted();
|
|
88
|
+
this.removeEntry(entry);
|
|
89
|
+
queued = false;
|
|
90
|
+
}, signal);
|
|
91
|
+
if (acquired) {
|
|
92
|
+
signal?.throwIfAborted();
|
|
93
|
+
returned = true;
|
|
94
|
+
return acquired;
|
|
95
|
+
}
|
|
96
|
+
if (!reportedPending) {
|
|
97
|
+
reportedPending = true;
|
|
98
|
+
onPending?.();
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
await delay(this.pollIntervalMs, undefined, { signal });
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
signal?.throwIfAborted();
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
// An abort or storage failure between admission and delivery must not leak a capacity slot.
|
|
111
|
+
try {
|
|
112
|
+
if (acquired && !returned)
|
|
113
|
+
await acquired.release();
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
if (queued)
|
|
117
|
+
await this.transaction(() => this.removeEntry(entry));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
entryPath(token) { return join(this.directory, `entry-${token}.json`); }
|
|
122
|
+
readState() {
|
|
123
|
+
const entries = [];
|
|
124
|
+
let lastSequence;
|
|
125
|
+
for (const name of readdirSync(this.directory)) {
|
|
126
|
+
if (name === '.lock')
|
|
127
|
+
continue;
|
|
128
|
+
// Only a completed atomic rename can publish a queue record.
|
|
129
|
+
if (/^pending-[a-f0-9-]{36}\.json$/.test(name)) {
|
|
130
|
+
unlinkSync(join(this.directory, name));
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (name === 'counter.json') {
|
|
134
|
+
const value = this.readJson(join(this.directory, name));
|
|
135
|
+
if (!value || value.version !== 1 || !Number.isSafeInteger(value.lastSequence) || value.lastSequence < 0)
|
|
136
|
+
throw new Error(stateMessage);
|
|
137
|
+
lastSequence = value.lastSequence;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (!/^entry-[a-f0-9-]{36}\.json$/.test(name))
|
|
141
|
+
throw new Error(stateMessage);
|
|
142
|
+
const entry = this.readEntry(join(this.directory, name));
|
|
143
|
+
if (name !== `entry-${entry.token}.json`)
|
|
144
|
+
throw new Error(stateMessage);
|
|
145
|
+
if (isDead(entry.ownerPid))
|
|
146
|
+
unlinkSync(this.entryPath(entry.token));
|
|
147
|
+
else
|
|
148
|
+
entries.push(entry);
|
|
149
|
+
}
|
|
150
|
+
// Missing/regressed/duplicated sequence state cannot safely establish FIFO order.
|
|
151
|
+
const sequences = new Set(entries.map(item => item.sequence));
|
|
152
|
+
if (sequences.size !== entries.length || entries.some(item => item.sequence > (lastSequence ?? -1)))
|
|
153
|
+
throw new Error(stateMessage);
|
|
154
|
+
entries.sort((a, b) => a.sequence - b.sequence);
|
|
155
|
+
return { entries, lastSequence: lastSequence ?? 0 };
|
|
156
|
+
}
|
|
157
|
+
readJson(path) {
|
|
158
|
+
const fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
159
|
+
try {
|
|
160
|
+
const stat = fstatSync(fd);
|
|
161
|
+
if (!stat.isFile() || stat.size > 64 * 1024)
|
|
162
|
+
throw new Error(stateMessage);
|
|
163
|
+
return JSON.parse(readFileSync(fd, 'utf8'));
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
closeSync(fd);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
readEntry(path) {
|
|
170
|
+
const value = this.readJson(path);
|
|
171
|
+
if (!validRequest(value) || value.version !== 1 || typeof value.token !== 'string' || !tokenPattern.test(value.token) ||
|
|
172
|
+
!isPositiveInteger(value.ownerPid) || !isPositiveInteger(value.sequence) ||
|
|
173
|
+
!Number.isSafeInteger(value.enqueuedAt) || value.enqueuedAt < 0 || value.source !== 'automatic')
|
|
174
|
+
throw new Error(stateMessage);
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
removeEntry(entry) {
|
|
178
|
+
const path = this.entryPath(entry.token);
|
|
179
|
+
try {
|
|
180
|
+
const current = this.readEntry(path);
|
|
181
|
+
if (current.token !== entry.token || current.ownerPid !== process.pid || current.sequence !== entry.sequence)
|
|
182
|
+
throw new Error(stateMessage);
|
|
183
|
+
unlinkSync(path);
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
if (error.code !== 'ENOENT')
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
writeJson(path, value) {
|
|
191
|
+
const temporary = join(this.directory, `pending-${randomUUID()}.json`);
|
|
192
|
+
const fd = openSync(temporary, 'wx', 0o600);
|
|
193
|
+
try {
|
|
194
|
+
writeFileSync(fd, JSON.stringify(value));
|
|
195
|
+
fsyncSync(fd);
|
|
196
|
+
}
|
|
197
|
+
finally {
|
|
198
|
+
closeSync(fd);
|
|
199
|
+
}
|
|
200
|
+
try {
|
|
201
|
+
renameSync(temporary, path);
|
|
202
|
+
}
|
|
203
|
+
finally {
|
|
204
|
+
try {
|
|
205
|
+
unlinkSync(temporary);
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
if (error.code !== 'ENOENT')
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
async transaction(operation, signal) {
|
|
214
|
+
let lease;
|
|
215
|
+
const deadline = performance.now() + 5000;
|
|
216
|
+
do {
|
|
217
|
+
signal?.throwIfAborted();
|
|
218
|
+
try {
|
|
219
|
+
lease = new DirectoryLease(this.directory);
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
if (performance.now() >= deadline)
|
|
224
|
+
throw new Error(stateMessage);
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
await delay(10 + Math.floor(Math.random() * 20), undefined, { signal });
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
signal?.throwIfAborted();
|
|
231
|
+
throw error;
|
|
232
|
+
}
|
|
233
|
+
} while (true);
|
|
234
|
+
try {
|
|
235
|
+
return await operation();
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
if (signal?.aborted && error === signal.reason)
|
|
239
|
+
throw error;
|
|
240
|
+
throw new Error(stateMessage);
|
|
241
|
+
}
|
|
242
|
+
finally {
|
|
243
|
+
try {
|
|
244
|
+
lease.close();
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
throw new Error(stateMessage);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export type CapacityKind = 'process' | 'task';
|
|
2
|
+
export type CapacitySource = 'automatic' | 'interactive';
|
|
3
|
+
export interface CapacityMemoryReading {
|
|
4
|
+
totalBytes: number;
|
|
5
|
+
availableBytes: number;
|
|
6
|
+
source?: 'system-available' | 'macos-reclaimable-estimate' | 'host-provider';
|
|
7
|
+
}
|
|
8
|
+
export interface CapacityOptions {
|
|
9
|
+
directory?: string;
|
|
10
|
+
softLimit?: number;
|
|
11
|
+
hardLimit?: number;
|
|
12
|
+
memoryReserveBytes?: number;
|
|
13
|
+
estimatedInstanceBytes?: number;
|
|
14
|
+
/** Host-owned memory reader, useful for deterministic admission tests. Never populate from a task payload. */
|
|
15
|
+
memoryProvider?: () => CapacityMemoryReading;
|
|
16
|
+
}
|
|
17
|
+
export interface CapacityRequest {
|
|
18
|
+
kind: CapacityKind;
|
|
19
|
+
source: CapacitySource;
|
|
20
|
+
id: string;
|
|
21
|
+
}
|
|
22
|
+
export interface CapacityLimits {
|
|
23
|
+
soft: number;
|
|
24
|
+
hard: number;
|
|
25
|
+
basis: 'hardware-estimate' | 'configured';
|
|
26
|
+
}
|
|
27
|
+
export interface CapacitySnapshot {
|
|
28
|
+
limits: CapacityLimits;
|
|
29
|
+
used: number;
|
|
30
|
+
automatic: number;
|
|
31
|
+
interactive: number;
|
|
32
|
+
availableAutomatic: number;
|
|
33
|
+
availableInteractive: number;
|
|
34
|
+
memory: CapacityMemoryReading & {
|
|
35
|
+
reserveBytes: number;
|
|
36
|
+
estimatedInstanceBytes: number;
|
|
37
|
+
startupReservedBytes: number;
|
|
38
|
+
availableForStartupBytes: number;
|
|
39
|
+
availableSlots: number;
|
|
40
|
+
startupWindowMs: number;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface CapacityLease {
|
|
44
|
+
spawned(pid: number): Promise<void>;
|
|
45
|
+
recheck(): Promise<void>;
|
|
46
|
+
release(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
export type CapacityErrorCode = 'ACP_CAPACITY_SOFT_LIMIT' | 'ACP_CAPACITY_HARD_LIMIT' | 'ACP_CAPACITY_MEMORY_LIMIT';
|
|
49
|
+
export declare class CapacityError extends Error {
|
|
50
|
+
readonly code: CapacityErrorCode;
|
|
51
|
+
constructor(code: CapacityErrorCode);
|
|
52
|
+
}
|
|
53
|
+
/** Allow roughly one automatic agent per two CPUs and 3 GiB, then keep at least one manual slot. */
|
|
54
|
+
export declare function estimateCapacityLimits(): CapacityLimits;
|
|
55
|
+
/** Darwin's raw free count excludes reclaimable inactive caches. Purgeable pages are not added twice. */
|
|
56
|
+
export declare function parseMacOSAvailableMemory(output: string, totalBytes: number): number;
|
|
57
|
+
export declare function resolveCapacityDirectory(options?: CapacityOptions): string;
|
|
58
|
+
export declare class CapacityGovernor {
|
|
59
|
+
private readonly directory;
|
|
60
|
+
private readonly limits;
|
|
61
|
+
private readonly memoryProvider;
|
|
62
|
+
private readonly memoryReserveBytes;
|
|
63
|
+
private readonly estimatedInstanceBytes;
|
|
64
|
+
constructor(options?: CapacityOptions);
|
|
65
|
+
acquire(request: CapacityRequest): Promise<CapacityLease>;
|
|
66
|
+
snapshot(kind: CapacityKind): Promise<CapacitySnapshot>;
|
|
67
|
+
private count;
|
|
68
|
+
private readReservations;
|
|
69
|
+
private reservationPath;
|
|
70
|
+
private ensurePolicy;
|
|
71
|
+
private readJson;
|
|
72
|
+
private readReservation;
|
|
73
|
+
private writeReservation;
|
|
74
|
+
private writeJson;
|
|
75
|
+
private transaction;
|
|
76
|
+
}
|