maka-agent 0.2.0-dev.77.20261009 → 0.2.0-dev.78.20261010
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.zh-CN.md +2 -2
- package/dist/pi-tui-pickers.js +5 -2
- package/dist/pi-tui-runner.js +211 -33
- package/dist/runtime-host-session-driver.js +91 -13
- package/dist/session-catalog-limits.js +22 -0
- package/dist/session-driver.js +10 -0
- package/dist/tui-copy-catalog.js +15 -0
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/bot-chat-settings.js +3 -0
- package/node_modules/@maka/core/dist/bot-events.js +1 -8
- package/node_modules/@maka/core/dist/local-memory.js +38 -1
- package/node_modules/@maka/core/dist/scheduled-task.js +14 -15
- package/node_modules/@maka/core/dist/session.js +3 -0
- package/node_modules/@maka/core/dist/text-sanitize.js +8 -3
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +11 -0
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +13 -5
- package/node_modules/@maka/runtime/dist/bots/proxied-fetch.js +29 -1
- package/node_modules/@maka/runtime/dist/file-stable-write.js +15 -3
- package/node_modules/@maka/runtime/dist/model-adapter.js +20 -1
- package/node_modules/@maka/runtime/dist/network/proxy-test.js +28 -1
- package/node_modules/@maka/runtime/dist/network/scoped-fetch-transport.js +13 -2
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +92 -5
- package/node_modules/@maka/runtime/dist/sandbox-boundary-tool.js +12 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +31 -5
- package/node_modules/@maka/runtime/dist/tool-availability.js +22 -16
- package/node_modules/@maka/runtime/dist/tool-call-snapshot.js +142 -0
- package/node_modules/@maka/runtime/dist/tool-runtime.js +25 -83
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.mjs +12 -1
- package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +30 -6
- package/node_modules/@maka/runtime-host/dist/client/index.js +1 -1
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +2 -1
- package/node_modules/@maka/runtime-host/dist/protocol/message.js +1 -13
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +1 -13
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +1 -13
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +4 -7
- package/node_modules/@maka/runtime-host/dist/server/archive-retention-coordinator.js +81 -105
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +17 -43
- package/node_modules/@maka/runtime-host/dist/server/host-maintenance-guards.js +95 -0
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +18 -8
- package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +32 -3
- package/node_modules/@maka/runtime-host/dist/server/project-catalog-coordinator.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +68 -3
- package/node_modules/@maka/runtime-host/dist/server/skill-catalog-coordinator.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +19 -24
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +74 -19
- package/node_modules/@maka/runtime-host/dist/server/workhub-result-coordinator.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/workhub-result-runtime.js +3 -98
- package/node_modules/@maka/runtime-host/dist/server/workhub-target-execution-authority.js +14 -126
- package/node_modules/@maka/storage/dist/git-entry.js +142 -5
- package/package.json +1 -1
|
@@ -16,146 +16,34 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
import {
|
|
20
|
-
import { authorizeConnectionModel, connectionModelChoiceValue, connectionEnabledModelIds, } from '@maka/core/llm-connections';
|
|
19
|
+
import { authorizeConnectionModel } from '@maka/core/llm-connections';
|
|
21
20
|
import { isModelExplicitlyUnsupportedForChat } from '@maka/core/model-catalog';
|
|
22
|
-
import { thinkingVariantsForConnection } from '@maka/core/model-thinking';
|
|
23
|
-
import { WORKHUB_COORDINATION_SESSION_ID } from '@maka/core/session';
|
|
24
21
|
import { WorkHubActionEffectFailure } from './workhub-coordination-action-gate.js';
|
|
25
|
-
/**
|
|
22
|
+
/** Validates the selected model without changing the target's configuration. */
|
|
26
23
|
export class HostWorkHubTargetExecutionAuthority {
|
|
27
|
-
|
|
24
|
+
options;
|
|
28
25
|
constructor(options) {
|
|
29
|
-
this
|
|
26
|
+
this.options = options;
|
|
30
27
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
for (let attempt = 0; attempt < 3; attempt++) {
|
|
34
|
-
const readiness = await this.#readiness(input.targetSessionId);
|
|
35
|
-
if (readiness.kind === 'ready')
|
|
36
|
-
return;
|
|
37
|
-
if (readiness.replacements.length === 0) {
|
|
38
|
-
throw new WorkHubActionEffectFailure('operation_unavailable', `Task “${input.targetSessionName}” has no enabled replacement model`);
|
|
39
|
-
}
|
|
40
|
-
const requestId = createHash('sha256')
|
|
41
|
-
.update(JSON.stringify({
|
|
42
|
-
kind: 'workhub_target_model_repair_v1',
|
|
43
|
-
actionId: input.actionId,
|
|
44
|
-
coordinationRunId: input.coordinationRunId,
|
|
45
|
-
targetSessionId: input.targetSessionId,
|
|
46
|
-
revision: readiness.record.revision,
|
|
47
|
-
replacements: readiness.replacements.map(({ value }) => value),
|
|
48
|
-
rejectedSelections,
|
|
49
|
-
}))
|
|
50
|
-
.digest('hex');
|
|
51
|
-
const choice = await this.#options.requestForm({
|
|
52
|
-
sessionId: WORKHUB_COORDINATION_SESSION_ID,
|
|
53
|
-
turnId: input.coordinationTurnId,
|
|
54
|
-
runId: input.coordinationRunId,
|
|
55
|
-
requestId,
|
|
56
|
-
create: async () => ({
|
|
57
|
-
kind: 'form',
|
|
58
|
-
toolUseId: input.actionId,
|
|
59
|
-
message: rejectedSelections.length === 0
|
|
60
|
-
? `Task “${input.targetSessionName}” uses model “${readiness.record.header.model}”, which is no longer available. Choose a replacement to continue.`
|
|
61
|
-
: `The selected model cannot currently run task “${input.targetSessionName}”. Choose another model to continue.`,
|
|
62
|
-
requester: { name: 'WorkHub' },
|
|
63
|
-
fields: [
|
|
64
|
-
{
|
|
65
|
-
kind: 'string',
|
|
66
|
-
name: 'targetModel',
|
|
67
|
-
label: `Model for ${input.targetSessionName}`,
|
|
68
|
-
required: true,
|
|
69
|
-
presentation: 'model_picker',
|
|
70
|
-
minLength: 1,
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
}),
|
|
74
|
-
});
|
|
75
|
-
if (choice.answer.action !== 'accept') {
|
|
76
|
-
throw new WorkHubActionEffectFailure('operation_conflict', `Model update for task “${input.targetSessionName}” was cancelled`);
|
|
77
|
-
}
|
|
78
|
-
const value = choice.answer.values.targetModel;
|
|
79
|
-
const replacement = readiness.replacements.find(({ value: offered }) => offered === value);
|
|
80
|
-
if (!replacement) {
|
|
81
|
-
if (typeof value === 'string')
|
|
82
|
-
rejectedSelections.push(value);
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
const updated = await this.#options.updateModel({
|
|
86
|
-
sessionId: input.targetSessionId,
|
|
87
|
-
expectedRevision: readiness.record.revision,
|
|
88
|
-
modelTarget: replacement.target,
|
|
89
|
-
}, context);
|
|
90
|
-
if (updated === 'committed') {
|
|
91
|
-
if ((await this.#readiness(input.targetSessionId)).kind === 'ready')
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
throw new WorkHubActionEffectFailure('operation_conflict', rejectedSelections.length > 0
|
|
96
|
-
? 'No executable replacement model was selected for this task'
|
|
97
|
-
: 'Task model changed while WorkHub was preparing the delegation; try again');
|
|
28
|
+
prepare(input, _context) {
|
|
29
|
+
return this.assertReady(input.targetSessionId);
|
|
98
30
|
}
|
|
99
31
|
async assertReady(targetSessionId) {
|
|
100
|
-
const
|
|
101
|
-
if (readiness.kind !== 'ready') {
|
|
102
|
-
throw new WorkHubActionEffectFailure('operation_conflict', 'Target task model is no longer enabled; choose a replacement and try again');
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
async #readiness(targetSessionId) {
|
|
106
|
-
const record = await this.#options.readSession(targetSessionId);
|
|
107
|
-
const header = record.header;
|
|
32
|
+
const { header } = await this.options.readSession(targetSessionId);
|
|
108
33
|
if (header.backend === 'plugin-executor')
|
|
109
|
-
return
|
|
110
|
-
const resolved = await this
|
|
34
|
+
return;
|
|
35
|
+
const resolved = await this.options.runtimePolicy.resolveExecutionConnection(header.llmConnectionId === undefined
|
|
111
36
|
? { kind: 'catalog_slug', connectionSlug: header.llmConnectionSlug }
|
|
112
37
|
: {
|
|
113
38
|
kind: 'bound',
|
|
114
39
|
connectionId: header.llmConnectionId,
|
|
115
40
|
connectionSlug: header.llmConnectionSlug,
|
|
116
41
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
42
|
+
const model = resolved.kind === 'ready'
|
|
43
|
+
? authorizeConnectionModel(resolved.connection, header.model)
|
|
44
|
+
: undefined;
|
|
45
|
+
if (!model || isModelExplicitlyUnsupportedForChat(model)) {
|
|
46
|
+
throw new WorkHubActionEffectFailure('operation_unavailable', `Task “${header.name}” uses unavailable model “${header.model}”. Update its model in the task settings, then retry.`);
|
|
121
47
|
}
|
|
122
|
-
const catalog = await this.#options.runtimePolicy.connectionCatalog.getSnapshot();
|
|
123
|
-
const resolvedConnections = await Promise.all(catalog.connections.map((connection) => this.#options.runtimePolicy.resolveExecutionConnection({
|
|
124
|
-
kind: 'bound',
|
|
125
|
-
connectionId: connection.connectionId,
|
|
126
|
-
connectionSlug: connection.slug,
|
|
127
|
-
})));
|
|
128
|
-
const replacements = resolvedConnections
|
|
129
|
-
.flatMap((candidate) => {
|
|
130
|
-
if (candidate.kind !== 'ready')
|
|
131
|
-
return [];
|
|
132
|
-
const connection = candidate.connection;
|
|
133
|
-
return connectionEnabledModelIds(connection).flatMap((modelId) => {
|
|
134
|
-
const model = authorizeConnectionModel(connection, modelId);
|
|
135
|
-
if (!model || isModelExplicitlyUnsupportedForChat(model))
|
|
136
|
-
return [];
|
|
137
|
-
if (header.thinkingLevel !== undefined &&
|
|
138
|
-
!thinkingVariantsForConnection({
|
|
139
|
-
providerType: connection.providerType,
|
|
140
|
-
modelOverrides: connection.modelOverrides,
|
|
141
|
-
}, modelId).includes(header.thinkingLevel)) {
|
|
142
|
-
return [];
|
|
143
|
-
}
|
|
144
|
-
const target = {
|
|
145
|
-
kind: 'explicit',
|
|
146
|
-
connectionId: connection.connectionId,
|
|
147
|
-
connectionSlug: connection.slug,
|
|
148
|
-
model: modelId,
|
|
149
|
-
};
|
|
150
|
-
return [
|
|
151
|
-
{
|
|
152
|
-
value: connectionModelChoiceValue(target.connectionId, target.connectionSlug, target.model),
|
|
153
|
-
target,
|
|
154
|
-
},
|
|
155
|
-
];
|
|
156
|
-
});
|
|
157
|
-
})
|
|
158
|
-
.sort((left, right) => left.value.localeCompare(right.value));
|
|
159
|
-
return { kind: 'model_repair_required', record, replacements };
|
|
160
48
|
}
|
|
161
49
|
}
|
|
@@ -16,23 +16,160 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
19
|
+
import { constants as fsConstants } from 'node:fs';
|
|
20
|
+
import { access, lstat, open } from 'node:fs/promises';
|
|
21
|
+
import { join, parse, resolve } from 'node:path';
|
|
22
|
+
import { execGitText } from './git-exec.js';
|
|
23
|
+
/**
|
|
24
|
+
* True means Git recognized an entry, not that every repository operation will
|
|
25
|
+
* succeed. False requires exhausting the ancestors; ambiguous failures throw.
|
|
26
|
+
*/
|
|
21
27
|
export async function hasEnclosingGitEntry(path) {
|
|
22
|
-
|
|
28
|
+
// The git probes below anchor on entry directories, so the walk needs an
|
|
29
|
+
// absolute path: a relative parent would ask Git to resolve -C against the
|
|
30
|
+
// child's inherited cwd, which may be deleted or unsearchable.
|
|
31
|
+
let current = resolve(path);
|
|
23
32
|
while (true) {
|
|
33
|
+
const gitPath = join(current, '.git');
|
|
34
|
+
let entryStat;
|
|
24
35
|
try {
|
|
25
|
-
await lstat(
|
|
26
|
-
return true;
|
|
36
|
+
entryStat = await lstat(gitPath);
|
|
27
37
|
}
|
|
28
38
|
catch (error) {
|
|
29
39
|
const code = error.code;
|
|
30
40
|
if (code !== 'ENOENT' && code !== 'ENOTDIR')
|
|
31
41
|
throw error;
|
|
32
42
|
}
|
|
43
|
+
if (entryStat && (await isGitEntry(gitPath, entryStat, current !== path))) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
// Git skips invalid ancestor directories, but gitfiles can stop discovery.
|
|
33
47
|
const parent = parse(current).dir;
|
|
34
48
|
if (parent === current)
|
|
35
49
|
return false;
|
|
36
50
|
current = parent;
|
|
37
51
|
}
|
|
38
52
|
}
|
|
53
|
+
async function isGitEntry(gitPath, before, ancestor) {
|
|
54
|
+
try {
|
|
55
|
+
// Validate the exact entry: discovery could hide a broken own marker by
|
|
56
|
+
// finding an outer repository instead.
|
|
57
|
+
await assertGitEntry(gitPath);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (!ancestor || !before.isDirectory() || error.code !== 128) {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Preserve Git's format verdict, but only after auditing its recognition
|
|
66
|
+
// inputs. Repeat the probe inside the snapshot checks rather than applying
|
|
67
|
+
// a stale rejection to metadata that may have been repaired or replaced.
|
|
68
|
+
const snapshot = await assertGitDirectoryReadable(gitPath, before);
|
|
69
|
+
let recognized = true;
|
|
70
|
+
try {
|
|
71
|
+
await assertGitEntry(gitPath);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error.code !== 128)
|
|
75
|
+
throw error;
|
|
76
|
+
recognized = false;
|
|
77
|
+
}
|
|
78
|
+
for (const [path, stat] of snapshot) {
|
|
79
|
+
assertUnchanged(path, stat, await statIfPresent(path));
|
|
80
|
+
}
|
|
81
|
+
return recognized;
|
|
82
|
+
}
|
|
83
|
+
async function assertGitEntry(gitPath) {
|
|
84
|
+
// Let Git interpret directories and gitfiles, including linked worktrees. -C
|
|
85
|
+
// only chooses where Git starts; --resolve-git-dir judges gitPath itself.
|
|
86
|
+
// Anchor on the directory containing the entry (lstat proved it exists)
|
|
87
|
+
// instead of the host's ambient cwd, which may have been deleted or made
|
|
88
|
+
// unsearchable since the process started.
|
|
89
|
+
await execGitText(parse(gitPath).dir, ['rev-parse', '--resolve-git-dir', gitPath], {
|
|
90
|
+
maxBuffer: 64 * 1024,
|
|
91
|
+
timeoutMs: 3_000,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Audit the ordinary directory layout recognized by Git's is_git_directory:
|
|
96
|
+
* HEAD is read (at most 255 bytes), and objects/refs require search permission.
|
|
97
|
+
* Missing members and wrong ordinary-file/directory types are format failures;
|
|
98
|
+
* permission, read and unexpected filesystem errors must still surface.
|
|
99
|
+
* Failed probes involving indirection remain unclassified: success for valid
|
|
100
|
+
* worktrees/symlinks is handled by Git above, not by this fallback.
|
|
101
|
+
*/
|
|
102
|
+
async function assertGitDirectoryReadable(gitPath, before) {
|
|
103
|
+
await access(gitPath, fsConstants.R_OK | fsConstants.X_OK);
|
|
104
|
+
const snapshot = new Map([[gitPath, before]]);
|
|
105
|
+
const commonPath = join(gitPath, 'commondir');
|
|
106
|
+
const commonStat = await statIfPresent(commonPath);
|
|
107
|
+
if (commonStat || process.env.GIT_OBJECT_DIRECTORY !== undefined) {
|
|
108
|
+
throw new Error(`Cannot classify Git metadata with redirected storage: ${gitPath}`);
|
|
109
|
+
}
|
|
110
|
+
snapshot.set(commonPath, commonStat);
|
|
111
|
+
for (const name of ['HEAD', 'objects', 'refs']) {
|
|
112
|
+
const path = join(gitPath, name);
|
|
113
|
+
const stat = await statIfPresent(path);
|
|
114
|
+
snapshot.set(path, stat);
|
|
115
|
+
if (!stat)
|
|
116
|
+
continue;
|
|
117
|
+
if (stat.isDirectory()) {
|
|
118
|
+
await access(path, fsConstants.R_OK | fsConstants.X_OK);
|
|
119
|
+
}
|
|
120
|
+
else if (stat.isFile()) {
|
|
121
|
+
await access(path, fsConstants.R_OK);
|
|
122
|
+
if (name === 'HEAD')
|
|
123
|
+
await assertHeadReadable(path, stat);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
throw new Error(`Cannot classify Git metadata with special file: ${path}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return snapshot;
|
|
130
|
+
}
|
|
131
|
+
async function assertHeadReadable(path, before) {
|
|
132
|
+
// Do not follow a replacement symlink or block opening a replacement FIFO.
|
|
133
|
+
const file = await open(path, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW | fsConstants.O_NONBLOCK);
|
|
134
|
+
try {
|
|
135
|
+
assertUnchanged(path, before, await file.stat());
|
|
136
|
+
const buffer = Buffer.alloc(255);
|
|
137
|
+
let offset = 0;
|
|
138
|
+
while (offset < buffer.length) {
|
|
139
|
+
const { bytesRead } = await file.read(buffer, offset, buffer.length - offset, offset);
|
|
140
|
+
if (bytesRead === 0)
|
|
141
|
+
break;
|
|
142
|
+
offset += bytesRead;
|
|
143
|
+
}
|
|
144
|
+
assertUnchanged(path, before, await file.stat());
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
await file.close();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async function statIfPresent(path) {
|
|
151
|
+
try {
|
|
152
|
+
// lstat distinguishes a dangling symlink from a missing member. ENOTDIR
|
|
153
|
+
// here means a parent changed, not that the member was simply absent.
|
|
154
|
+
return await lstat(path);
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
if (error.code !== 'ENOENT')
|
|
158
|
+
throw error;
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function assertUnchanged(path, before, after) {
|
|
163
|
+
if (!before && !after)
|
|
164
|
+
return;
|
|
165
|
+
if (!before ||
|
|
166
|
+
!after ||
|
|
167
|
+
before.dev !== after.dev ||
|
|
168
|
+
before.ino !== after.ino ||
|
|
169
|
+
before.mode !== after.mode ||
|
|
170
|
+
before.size !== after.size ||
|
|
171
|
+
before.mtimeMs !== after.mtimeMs ||
|
|
172
|
+
before.ctimeMs !== after.ctimeMs) {
|
|
173
|
+
throw new Error(`Git metadata changed during discovery: ${path}`);
|
|
174
|
+
}
|
|
175
|
+
}
|