@unieai/rabi-subagent-fork-in-process 0.0.0-stage → 0.2.2-rc.5
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/README.md +7 -2
- package/lib/index.js +54 -0
- package/lib/types/index.d.ts +20 -0
- package/locale/de.json +6 -0
- package/locale/en.json +5 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +37 -4
- package/src/index.ts +83 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @unieai/rabi-subagent-fork-in-process
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
In-process fork subagent backend: runs a child agent seeded with a prefix of the parent's log
|
|
4
|
+
|
|
5
|
+
Part of Rabi, the agent harness UnieAI Code runs on. Installed as a dependency of `@unieai/rabi`;
|
|
6
|
+
not meant to be used on its own.
|
|
7
|
+
|
|
8
|
+
See LICENSE for the license and copyright of this package.
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import z from "@unieai/schemastery";
|
|
2
|
+
//#region lib/types/index.js
|
|
3
|
+
/**
|
|
4
|
+
* The in-process FORK subagent backend: registers a {@link SubagentProvider} on
|
|
5
|
+
* `ctx.subagents` that runs each child as a child {@link Agent} SEEDED with a prefix of the
|
|
6
|
+
* parent's session log — so the child inherits the parent's conversation context instead of
|
|
7
|
+
* starting fresh. The seed ends at the last `turn/end`: the current tool-call turn is
|
|
8
|
+
* unbalanced and cannot be replayed as a valid child session.
|
|
9
|
+
* @module @unieai/rabi-subagent-fork-in-process
|
|
10
|
+
*/
|
|
11
|
+
const name = "subagent-fork-in-process";
|
|
12
|
+
const inject = ["subagents"];
|
|
13
|
+
const Config = z.object({ providerName: z.string().default("fork") });
|
|
14
|
+
/**
|
|
15
|
+
* The balanced completed-turn prefix of `parent`'s log: every event up to and including the
|
|
16
|
+
* last `turn/end`. The in-flight turn is excluded; before any completed turn the child starts
|
|
17
|
+
* fresh. Because live sequence numbers equal array indexes, the result remains a valid seed
|
|
18
|
+
* beginning at sequence zero.
|
|
19
|
+
* @param parent - the agent whose session log to slice.
|
|
20
|
+
* @returns the seed events, contiguous from seq 0; empty when no turn has completed.
|
|
21
|
+
*/
|
|
22
|
+
function completedTurnPrefix(parent) {
|
|
23
|
+
const events = parent.session.snapshotEvents();
|
|
24
|
+
const lastEnd = events.findLast((e) => e.type === "turn/end");
|
|
25
|
+
if (lastEnd === void 0) return [];
|
|
26
|
+
return events.slice(0, lastEnd.seq + 1);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The fork provider. Supports `depthLimit` and `outputSchema` (via the shared
|
|
30
|
+
* in-process structured runtime), `agentOptions` (merged over the parent
|
|
31
|
+
* route). The child inherits its parent's preset composition.
|
|
32
|
+
*/
|
|
33
|
+
var ForkInProcessProvider = class {
|
|
34
|
+
name;
|
|
35
|
+
capabilities = {
|
|
36
|
+
agentOptions: true,
|
|
37
|
+
agentPreset: false,
|
|
38
|
+
outputSchema: true,
|
|
39
|
+
depthLimit: true
|
|
40
|
+
};
|
|
41
|
+
inheritsParentContext = true;
|
|
42
|
+
constructor(name) {
|
|
43
|
+
this.name = name;
|
|
44
|
+
}
|
|
45
|
+
prepareContinuable(request) {
|
|
46
|
+
const seed = completedTurnPrefix(request.parent);
|
|
47
|
+
return Promise.resolve(seed.length > 0 ? { seed } : {});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
function apply(ctx, config) {
|
|
51
|
+
ctx.subagents.registerProvider(new ForkInProcessProvider(config.providerName));
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { Config, apply, inject, name };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The in-process FORK subagent backend: registers a {@link SubagentProvider} on
|
|
3
|
+
* `ctx.subagents` that runs each child as a child {@link Agent} SEEDED with a prefix of the
|
|
4
|
+
* parent's session log — so the child inherits the parent's conversation context instead of
|
|
5
|
+
* starting fresh. The seed ends at the last `turn/end`: the current tool-call turn is
|
|
6
|
+
* unbalanced and cannot be replayed as a valid child session.
|
|
7
|
+
* @module @unieai/rabi-subagent-fork-in-process
|
|
8
|
+
*/
|
|
9
|
+
import type { Context } from '@unieai/cordis';
|
|
10
|
+
import z from '@unieai/schemastery';
|
|
11
|
+
export declare const name = "subagent-fork-in-process";
|
|
12
|
+
export declare const inject: string[];
|
|
13
|
+
/** Config: the registry name to register the provider under. */
|
|
14
|
+
export interface Config {
|
|
15
|
+
/** Provider name on `ctx.subagents` (default `fork`). */
|
|
16
|
+
providerName: string;
|
|
17
|
+
}
|
|
18
|
+
export declare const Config: z<Config>;
|
|
19
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
package/locale/de.json
ADDED
package/locale/en.json
ADDED
package/locale/es.json
ADDED
package/locale/fr.json
ADDED
package/locale/ja.json
ADDED
package/locale/pt.json
ADDED
package/locale/ru.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unieai/rabi-subagent-fork-in-process",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"description": "In-process fork subagent backend: runs a child agent seeded with a prefix of the parent's log",
|
|
4
|
+
"version": "0.2.2-rc.5",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "lib/index.js",
|
|
10
|
+
"types": "lib/types/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/types/index.d.ts",
|
|
14
|
+
"default": "./lib/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./src/*": "./src/*",
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
"./locale/*.json": "./locale/*.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"locale/*.json",
|
|
22
|
+
"lib/index.js",
|
|
23
|
+
"lib/types/**/*.d.ts",
|
|
24
|
+
"lib/types/**/*.d.ts.map",
|
|
25
|
+
"lib/**/*.js.map",
|
|
26
|
+
"src",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@unieai/rabi-agent": "0.2.2-rc.5",
|
|
32
|
+
"@unieai/rabi-session": "0.2.2-rc.5",
|
|
33
|
+
"@unieai/rabi-subagent": "0.2.2-rc.5",
|
|
34
|
+
"@unieai/cordis": "4.1.0"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@unieai/schemastery": "3.19.0"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The in-process FORK subagent backend: registers a {@link SubagentProvider} on
|
|
3
|
+
* `ctx.subagents` that runs each child as a child {@link Agent} SEEDED with a prefix of the
|
|
4
|
+
* parent's session log — so the child inherits the parent's conversation context instead of
|
|
5
|
+
* starting fresh. The seed ends at the last `turn/end`: the current tool-call turn is
|
|
6
|
+
* unbalanced and cannot be replayed as a valid child session.
|
|
7
|
+
* @module @unieai/rabi-subagent-fork-in-process
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Context } from '@unieai/cordis'
|
|
11
|
+
import z from '@unieai/schemastery'
|
|
12
|
+
import type { SessionEvent } from '@unieai/rabi-session'
|
|
13
|
+
import type { Agent } from '@unieai/rabi-agent'
|
|
14
|
+
import type {
|
|
15
|
+
ContinuableCreateRequest,
|
|
16
|
+
ContinuableCreateSpec,
|
|
17
|
+
SubagentCapabilities,
|
|
18
|
+
SubagentProvider,
|
|
19
|
+
} from '@unieai/rabi-subagent'
|
|
20
|
+
|
|
21
|
+
export const name = 'subagent-fork-in-process'
|
|
22
|
+
// `tools` is deliberately NOT injected — same rationale as subagent-spawn-in-process: the
|
|
23
|
+
// per-run structured runtime gates its capture-tool registration on `tools`
|
|
24
|
+
// itself, so this backend's apply timing (and the delegation tool's position
|
|
25
|
+
// in the model-visible tool list) is unchanged by structured output.
|
|
26
|
+
export const inject = ['subagents']
|
|
27
|
+
|
|
28
|
+
/** Config: the registry name to register the provider under. */
|
|
29
|
+
export interface Config {
|
|
30
|
+
/** Provider name on `ctx.subagents` (default `fork`). */
|
|
31
|
+
providerName: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const Config: z<Config> = z.object({
|
|
35
|
+
providerName: z.string().default('fork'),
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The balanced completed-turn prefix of `parent`'s log: every event up to and including the
|
|
40
|
+
* last `turn/end`. The in-flight turn is excluded; before any completed turn the child starts
|
|
41
|
+
* fresh. Because live sequence numbers equal array indexes, the result remains a valid seed
|
|
42
|
+
* beginning at sequence zero.
|
|
43
|
+
* @param parent - the agent whose session log to slice.
|
|
44
|
+
* @returns the seed events, contiguous from seq 0; empty when no turn has completed.
|
|
45
|
+
*/
|
|
46
|
+
function completedTurnPrefix(parent: Agent): SessionEvent[] {
|
|
47
|
+
// oxlint-disable-next-line typescript/no-deprecated -- Existing Session history read; migration deferred.
|
|
48
|
+
const events = parent.session.snapshotEvents()
|
|
49
|
+
const lastEnd = events.findLast(e => e.type === 'turn/end')
|
|
50
|
+
if (lastEnd === undefined) return []
|
|
51
|
+
// seq === array index (the append contract), so slice up to and including it.
|
|
52
|
+
return events.slice(0, lastEnd.seq + 1)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The fork provider. Supports `depthLimit` and `outputSchema` (via the shared
|
|
57
|
+
* in-process structured runtime), `agentOptions` (merged over the parent
|
|
58
|
+
* route). The child inherits its parent's preset composition.
|
|
59
|
+
*/
|
|
60
|
+
class ForkInProcessProvider implements SubagentProvider {
|
|
61
|
+
readonly capabilities: SubagentCapabilities = {
|
|
62
|
+
agentOptions: true,
|
|
63
|
+
agentPreset: false,
|
|
64
|
+
outputSchema: true,
|
|
65
|
+
depthLimit: true,
|
|
66
|
+
}
|
|
67
|
+
// Context contract: a forked child IS seeded with the parent's completed-turn prefix.
|
|
68
|
+
readonly inheritsParentContext = true
|
|
69
|
+
|
|
70
|
+
constructor(readonly name: string) {}
|
|
71
|
+
|
|
72
|
+
prepareContinuable(request: ContinuableCreateRequest): Promise<ContinuableCreateSpec> {
|
|
73
|
+
// The fork prefix is captured ONCE, at creation: it becomes part of the
|
|
74
|
+
// child's own durable transcript, so a later cold resume replays that
|
|
75
|
+
// prefix instead of re-forking the parent's newer history.
|
|
76
|
+
const seed = completedTurnPrefix(request.parent)
|
|
77
|
+
return Promise.resolve(seed.length > 0 ? { seed } : {})
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function apply(ctx: Context, config: Config): void {
|
|
82
|
+
ctx.subagents.registerProvider(new ForkInProcessProvider(config.providerName))
|
|
83
|
+
}
|