peaks-loop-internal-runtime 0.0.60 → 0.0.61
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/guards/resource-budget.d.ts +31 -0
- package/dist/guards/resource-budget.d.ts.map +1 -1
- package/dist/guards/resource-budget.js +59 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/guards/resource-budget.ts +67 -5
- package/src/index.ts +1 -1
|
@@ -1,6 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* §5.3 performance ceiling rails for the detached runtime.
|
|
3
|
+
*
|
|
4
|
+
* WHY `cpuPct` USED TO LIE. The first version of this guard computed
|
|
5
|
+
* `cpuPct` as `((user + system) / 1_000_000) * 100`. `process.cpuUsage()`
|
|
6
|
+
* reports MICROSECONDS, so that expression yields CENTISECONDS: a field named
|
|
7
|
+
* `cpuPct` that no reader could compare against the documented "idle CPU ≤ 5 %"
|
|
8
|
+
* rail without reverse-engineering the unit first. A threshold of 5 therefore
|
|
9
|
+
* meant 50 ms of CPU rather than 5 %, and the bench that read it compared a
|
|
10
|
+
* number about the RUNNER's startup against a rail written about the PRODUCT.
|
|
11
|
+
*
|
|
12
|
+
* THE UNIT AND THE NAME NOW AGREE. `cpuPct` is a percentage of ONE CPU core
|
|
13
|
+
* over the sampled window, and `cpuCentiseconds` carries the same window's
|
|
14
|
+
* absolute CPU cost under its true unit. `cpuPct` keeps its name and its place
|
|
15
|
+
* in `Sample`, so every existing reader still compiles and still sees a
|
|
16
|
+
* non-negative number; what changed is what the number MEANS — it is now the
|
|
17
|
+
* quantity the documented rail talks about.
|
|
18
|
+
*
|
|
19
|
+
* THE WINDOW IS THE INTERVAL SINCE THE PREVIOUS SAMPLE. The first sample of a
|
|
20
|
+
* process covers the whole process so far, because there is no earlier sample
|
|
21
|
+
* to subtract. A guard that samples every 10 s (design §5) therefore reads the
|
|
22
|
+
* cost of the last 10 s rather than the cost of everything since boot — which
|
|
23
|
+
* is the number a ceiling rail is supposed to judge.
|
|
24
|
+
*/
|
|
1
25
|
export interface Sample {
|
|
2
26
|
rssMb: number;
|
|
27
|
+
/** CPU consumed over the sampled window, as a percentage of ONE CPU core. */
|
|
3
28
|
cpuPct: number;
|
|
29
|
+
/** CPU consumed over the sampled window, in centiseconds (1 centisecond = 10 ms). */
|
|
30
|
+
cpuCentiseconds: number;
|
|
4
31
|
}
|
|
5
32
|
export interface EnforceInput {
|
|
6
33
|
active: number;
|
|
@@ -10,6 +37,10 @@ export interface EnforceOpts {
|
|
|
10
37
|
}
|
|
11
38
|
export declare class ResourceBudgetGuard {
|
|
12
39
|
private readonly cfg;
|
|
40
|
+
/** CPU microseconds at the previous sample; null before the first sample. */
|
|
41
|
+
private lastCpuUs;
|
|
42
|
+
/** Wall-clock milliseconds at the previous sample; null before the first sample. */
|
|
43
|
+
private lastWallMs;
|
|
13
44
|
constructor(cfg: {
|
|
14
45
|
maxRssMb: number;
|
|
15
46
|
maxCpuPct: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-budget.d.ts","sourceRoot":"","sources":["../../src/guards/resource-budget.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"resource-budget.d.ts","sourceRoot":"","sources":["../../src/guards/resource-budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAeH,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,MAAM,EAAE,MAAM,CAAC;IACf,qFAAqF;IACrF,eAAe,EAAE,MAAM,CAAC;CACzB;AACD,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;CAChB;AACD,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,mBAAmB;IAMlB,OAAO,CAAC,QAAQ,CAAC,GAAG;IALhC,6EAA6E;IAC7E,OAAO,CAAC,SAAS,CAAuB;IACxC,oFAAoF;IACpF,OAAO,CAAC,UAAU,CAAuB;gBAEZ,GAAG,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;IAEzE,MAAM,IAAI,MAAM;IAmBhB,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,GAAG;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE;CAIxF"}
|
|
@@ -1,14 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* §5.3 performance ceiling rails for the detached runtime.
|
|
3
|
+
*
|
|
4
|
+
* WHY `cpuPct` USED TO LIE. The first version of this guard computed
|
|
5
|
+
* `cpuPct` as `((user + system) / 1_000_000) * 100`. `process.cpuUsage()`
|
|
6
|
+
* reports MICROSECONDS, so that expression yields CENTISECONDS: a field named
|
|
7
|
+
* `cpuPct` that no reader could compare against the documented "idle CPU ≤ 5 %"
|
|
8
|
+
* rail without reverse-engineering the unit first. A threshold of 5 therefore
|
|
9
|
+
* meant 50 ms of CPU rather than 5 %, and the bench that read it compared a
|
|
10
|
+
* number about the RUNNER's startup against a rail written about the PRODUCT.
|
|
11
|
+
*
|
|
12
|
+
* THE UNIT AND THE NAME NOW AGREE. `cpuPct` is a percentage of ONE CPU core
|
|
13
|
+
* over the sampled window, and `cpuCentiseconds` carries the same window's
|
|
14
|
+
* absolute CPU cost under its true unit. `cpuPct` keeps its name and its place
|
|
15
|
+
* in `Sample`, so every existing reader still compiles and still sees a
|
|
16
|
+
* non-negative number; what changed is what the number MEANS — it is now the
|
|
17
|
+
* quantity the documented rail talks about.
|
|
18
|
+
*
|
|
19
|
+
* THE WINDOW IS THE INTERVAL SINCE THE PREVIOUS SAMPLE. The first sample of a
|
|
20
|
+
* process covers the whole process so far, because there is no earlier sample
|
|
21
|
+
* to subtract. A guard that samples every 10 s (design §5) therefore reads the
|
|
22
|
+
* cost of the last 10 s rather than the cost of everything since boot — which
|
|
23
|
+
* is the number a ceiling rail is supposed to judge.
|
|
24
|
+
*/
|
|
25
|
+
/** Bytes in one kibibyte — the divisor that turns the OS's byte counts into mebibytes. */
|
|
26
|
+
const KIBIBYTE = 1024;
|
|
27
|
+
/** Bytes in one mebibyte. */
|
|
28
|
+
const BYTES_PER_MEGABYTE = KIBIBYTE * KIBIBYTE;
|
|
29
|
+
/** Milliseconds in one second — the scale between `process.uptime()` and the CPU clock. */
|
|
30
|
+
const MILLISECONDS_PER_SECOND = 1000;
|
|
31
|
+
/** Microseconds in one millisecond — the unit `process.cpuUsage()` reports. */
|
|
32
|
+
const MICROSECONDS_PER_MILLISECOND = 1000;
|
|
33
|
+
/** Microseconds in one centisecond — the unit the old `cpuPct` field actually held. */
|
|
34
|
+
const MICROSECONDS_PER_CENTISECOND = 10_000;
|
|
35
|
+
/** A percentage is a ratio out of a hundred. */
|
|
36
|
+
const PERCENT = 100;
|
|
1
37
|
export class ResourceBudgetGuard {
|
|
2
38
|
cfg;
|
|
39
|
+
/** CPU microseconds at the previous sample; null before the first sample. */
|
|
40
|
+
lastCpuUs = null;
|
|
41
|
+
/** Wall-clock milliseconds at the previous sample; null before the first sample. */
|
|
42
|
+
lastWallMs = null;
|
|
3
43
|
constructor(cfg) {
|
|
4
44
|
this.cfg = cfg;
|
|
5
45
|
}
|
|
6
46
|
sample() {
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
47
|
+
const usage = process.cpuUsage();
|
|
48
|
+
const cpuUs = usage.user + usage.system;
|
|
49
|
+
const wallMs = process.uptime() * MILLISECONDS_PER_SECOND;
|
|
50
|
+
const previousCpuUs = this.lastCpuUs;
|
|
51
|
+
const previousWallMs = this.lastWallMs;
|
|
52
|
+
this.lastCpuUs = cpuUs;
|
|
53
|
+
this.lastWallMs = wallMs;
|
|
54
|
+
const windowCpuUs = previousCpuUs === null ? cpuUs : cpuUs - previousCpuUs;
|
|
55
|
+
const windowWallMs = previousWallMs === null ? wallMs : wallMs - previousWallMs;
|
|
56
|
+
const rssMb = Math.round(process.memoryUsage().rss / BYTES_PER_MEGABYTE);
|
|
57
|
+
const cpuCentiseconds = round2(windowCpuUs / MICROSECONDS_PER_CENTISECOND);
|
|
58
|
+
const cpuPct = windowWallMs > 0
|
|
59
|
+
? round2((windowCpuUs / MICROSECONDS_PER_MILLISECOND / windowWallMs) * PERCENT)
|
|
60
|
+
: 0;
|
|
61
|
+
return { rssMb, cpuPct, cpuCentiseconds };
|
|
12
62
|
}
|
|
13
63
|
enforce(input, opts) {
|
|
14
64
|
if (input.active > opts.maxConcurrent)
|
|
@@ -16,3 +66,7 @@ export class ResourceBudgetGuard {
|
|
|
16
66
|
return { throttle: false };
|
|
17
67
|
}
|
|
18
68
|
}
|
|
69
|
+
/** Two decimals: enough to see a change between two samples, few enough to read. */
|
|
70
|
+
function round2(value) {
|
|
71
|
+
return Math.round(value * PERCENT) / PERCENT;
|
|
72
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const RUNTIME_VERSION = "4.1.
|
|
1
|
+
export declare const RUNTIME_VERSION = "4.1.21";
|
|
2
2
|
export declare const RUNTIME_NPM_VERSION = "0.0.21";
|
|
3
3
|
export { ClaudeAdapter } from './vendor/claude-adapter.js';
|
|
4
4
|
export { CodexAdapter } from './vendor/codex-adapter.js';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// API contract: RUNTIME_VERSION tracks peaks-loop root version (4.0.x).
|
|
2
2
|
// This is what consumers (sub-agents dispatched by peaks-code) check at
|
|
3
3
|
// runtime to verify protocol compatibility.
|
|
4
|
-
export const RUNTIME_VERSION = '4.1.
|
|
4
|
+
export const RUNTIME_VERSION = '4.1.21';
|
|
5
5
|
// npm version: independent 0.0.x SemVer. Runtime is its own package
|
|
6
6
|
// (peaks-loop-internal-runtime@NPM_VERSION) on the registry; bumps
|
|
7
7
|
// per peaks release notes when its public surface actually changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "peaks-loop-internal-runtime",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.61",
|
|
4
4
|
"description": "Detached sub-agent runtime: ProcessSupervisor + LifecycleOwner + VendorAdapter (claude/codex/copilot) + G8 infinite-context auto-compact. Slice 2026-08-10.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"peaks-loop-shared": "0.0.
|
|
19
|
+
"peaks-loop-shared": "0.0.110"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"typescript": "^5.4.0",
|
|
@@ -1,6 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* §5.3 performance ceiling rails for the detached runtime.
|
|
3
|
+
*
|
|
4
|
+
* WHY `cpuPct` USED TO LIE. The first version of this guard computed
|
|
5
|
+
* `cpuPct` as `((user + system) / 1_000_000) * 100`. `process.cpuUsage()`
|
|
6
|
+
* reports MICROSECONDS, so that expression yields CENTISECONDS: a field named
|
|
7
|
+
* `cpuPct` that no reader could compare against the documented "idle CPU ≤ 5 %"
|
|
8
|
+
* rail without reverse-engineering the unit first. A threshold of 5 therefore
|
|
9
|
+
* meant 50 ms of CPU rather than 5 %, and the bench that read it compared a
|
|
10
|
+
* number about the RUNNER's startup against a rail written about the PRODUCT.
|
|
11
|
+
*
|
|
12
|
+
* THE UNIT AND THE NAME NOW AGREE. `cpuPct` is a percentage of ONE CPU core
|
|
13
|
+
* over the sampled window, and `cpuCentiseconds` carries the same window's
|
|
14
|
+
* absolute CPU cost under its true unit. `cpuPct` keeps its name and its place
|
|
15
|
+
* in `Sample`, so every existing reader still compiles and still sees a
|
|
16
|
+
* non-negative number; what changed is what the number MEANS — it is now the
|
|
17
|
+
* quantity the documented rail talks about.
|
|
18
|
+
*
|
|
19
|
+
* THE WINDOW IS THE INTERVAL SINCE THE PREVIOUS SAMPLE. The first sample of a
|
|
20
|
+
* process covers the whole process so far, because there is no earlier sample
|
|
21
|
+
* to subtract. A guard that samples every 10 s (design §5) therefore reads the
|
|
22
|
+
* cost of the last 10 s rather than the cost of everything since boot — which
|
|
23
|
+
* is the number a ceiling rail is supposed to judge.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** Bytes in one kibibyte — the divisor that turns the OS's byte counts into mebibytes. */
|
|
27
|
+
const KIBIBYTE = 1024;
|
|
28
|
+
/** Bytes in one mebibyte. */
|
|
29
|
+
const BYTES_PER_MEGABYTE = KIBIBYTE * KIBIBYTE;
|
|
30
|
+
/** Milliseconds in one second — the scale between `process.uptime()` and the CPU clock. */
|
|
31
|
+
const MILLISECONDS_PER_SECOND = 1000;
|
|
32
|
+
/** Microseconds in one millisecond — the unit `process.cpuUsage()` reports. */
|
|
33
|
+
const MICROSECONDS_PER_MILLISECOND = 1000;
|
|
34
|
+
/** Microseconds in one centisecond — the unit the old `cpuPct` field actually held. */
|
|
35
|
+
const MICROSECONDS_PER_CENTISECOND = 10_000;
|
|
36
|
+
/** A percentage is a ratio out of a hundred. */
|
|
37
|
+
const PERCENT = 100;
|
|
38
|
+
|
|
1
39
|
export interface Sample {
|
|
2
40
|
rssMb: number;
|
|
41
|
+
/** CPU consumed over the sampled window, as a percentage of ONE CPU core. */
|
|
3
42
|
cpuPct: number;
|
|
43
|
+
/** CPU consumed over the sampled window, in centiseconds (1 centisecond = 10 ms). */
|
|
44
|
+
cpuCentiseconds: number;
|
|
4
45
|
}
|
|
5
46
|
export interface EnforceInput {
|
|
6
47
|
active: number;
|
|
@@ -10,14 +51,30 @@ export interface EnforceOpts {
|
|
|
10
51
|
}
|
|
11
52
|
|
|
12
53
|
export class ResourceBudgetGuard {
|
|
54
|
+
/** CPU microseconds at the previous sample; null before the first sample. */
|
|
55
|
+
private lastCpuUs: number | null = null;
|
|
56
|
+
/** Wall-clock milliseconds at the previous sample; null before the first sample. */
|
|
57
|
+
private lastWallMs: number | null = null;
|
|
58
|
+
|
|
13
59
|
constructor(private readonly cfg: { maxRssMb: number; maxCpuPct: number }) {}
|
|
14
60
|
|
|
15
61
|
sample(): Sample {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
62
|
+
const usage = process.cpuUsage();
|
|
63
|
+
const cpuUs = usage.user + usage.system;
|
|
64
|
+
const wallMs = process.uptime() * MILLISECONDS_PER_SECOND;
|
|
65
|
+
const previousCpuUs = this.lastCpuUs;
|
|
66
|
+
const previousWallMs = this.lastWallMs;
|
|
67
|
+
this.lastCpuUs = cpuUs;
|
|
68
|
+
this.lastWallMs = wallMs;
|
|
69
|
+
const windowCpuUs = previousCpuUs === null ? cpuUs : cpuUs - previousCpuUs;
|
|
70
|
+
const windowWallMs = previousWallMs === null ? wallMs : wallMs - previousWallMs;
|
|
71
|
+
const rssMb = Math.round(process.memoryUsage().rss / BYTES_PER_MEGABYTE);
|
|
72
|
+
const cpuCentiseconds = round2(windowCpuUs / MICROSECONDS_PER_CENTISECOND);
|
|
73
|
+
const cpuPct =
|
|
74
|
+
windowWallMs > 0
|
|
75
|
+
? round2((windowCpuUs / MICROSECONDS_PER_MILLISECOND / windowWallMs) * PERCENT)
|
|
76
|
+
: 0;
|
|
77
|
+
return { rssMb, cpuPct, cpuCentiseconds };
|
|
21
78
|
}
|
|
22
79
|
|
|
23
80
|
enforce(input: EnforceInput, opts: EnforceOpts): { throttle: boolean; kill?: string[] } {
|
|
@@ -25,3 +82,8 @@ export class ResourceBudgetGuard {
|
|
|
25
82
|
return { throttle: false };
|
|
26
83
|
}
|
|
27
84
|
}
|
|
85
|
+
|
|
86
|
+
/** Two decimals: enough to see a change between two samples, few enough to read. */
|
|
87
|
+
function round2(value: number): number {
|
|
88
|
+
return Math.round(value * PERCENT) / PERCENT;
|
|
89
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// API contract: RUNTIME_VERSION tracks peaks-loop root version (4.0.x).
|
|
2
2
|
// This is what consumers (sub-agents dispatched by peaks-code) check at
|
|
3
3
|
// runtime to verify protocol compatibility.
|
|
4
|
-
export const RUNTIME_VERSION = '4.1.
|
|
4
|
+
export const RUNTIME_VERSION = '4.1.21';
|
|
5
5
|
|
|
6
6
|
// npm version: independent 0.0.x SemVer. Runtime is its own package
|
|
7
7
|
// (peaks-loop-internal-runtime@NPM_VERSION) on the registry; bumps
|