dsh-artel 0.1.0 → 0.2.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/CHANGELOG.md +52 -0
- package/README.md +55 -35
- package/docs/artel-in-chat/screens/changes.png +0 -0
- package/docs/artel-in-chat/screens/hero.png +0 -0
- package/docs/artel-in-chat/screens/run.png +0 -0
- package/docs/guide.md +169 -87
- package/docs/guide.ru.md +134 -59
- package/docs/guide.zh.md +146 -72
- package/docs/publishing.md +46 -27
- package/lib/client.js +3100 -1526
- package/lib/engine.js +93 -5
- package/lib/host-driver.js +84 -2
- package/lib/index.js +18 -1
- package/lib/prompts.js +1 -0
- package/lib/routes.js +53 -1
- package/lib/run-store.js +31 -0
- package/locale/en.json +1 -1
- package/locale/ru.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +2 -1
package/lib/engine.js
CHANGED
|
@@ -22,8 +22,24 @@ import { applyChanges, collectChanges, copyProjectTree, preflightApply, removeCo
|
|
|
22
22
|
import { parseClaim, parseOwnership, assignOwnership, describeOwnership } from './ownership.js'
|
|
23
23
|
import { collisionNotice, soloPrompt, swarmGoPrompt, swarmPlanPrompt, userMessagePrompt } from './prompts.js'
|
|
24
24
|
import { diffFile } from './diff.js'
|
|
25
|
-
import { newRunId, toSummary } from './run-store.js'
|
|
25
|
+
import { newRunId, phaseOfFeedEvent, toSummary } from './run-store.js'
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Tells whether a path exists, without throwing on a missing entry.
|
|
29
|
+
*
|
|
30
|
+
* The isolated copy of a run is deleted once the run is applied or discarded,
|
|
31
|
+
* so change detection and terminal accounting must tolerate a retired copy.
|
|
32
|
+
* @param {string} target - path to probe.
|
|
33
|
+
* @returns {Promise<boolean>} true when the path can be stat-ed.
|
|
34
|
+
*/
|
|
35
|
+
async function pathExists(target) {
|
|
36
|
+
try {
|
|
37
|
+
await fs.stat(target)
|
|
38
|
+
return true
|
|
39
|
+
} catch {
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
}
|
|
27
43
|
/** Names for swarm members: short, pronounceable, stable across a run. */
|
|
28
44
|
export const AGENT_NAMES = ['Vega', 'Orion', 'Lyra', 'Atlas', 'Nova', 'Rhea', 'Mira', 'Kai']
|
|
29
45
|
|
|
@@ -254,6 +270,7 @@ export class ArtelEngine {
|
|
|
254
270
|
projectPath: project,
|
|
255
271
|
copyPath,
|
|
256
272
|
agentId: agent.id,
|
|
273
|
+
parentSessionId: sessionId,
|
|
257
274
|
title: `Artel · ${agent.name} — ${task.length > 48 ? `${task.slice(0, 48)}…` : task}`,
|
|
258
275
|
})
|
|
259
276
|
this.#register(runId, runtime, agent, handle)
|
|
@@ -311,6 +328,7 @@ export class ArtelEngine {
|
|
|
311
328
|
projectPath: project,
|
|
312
329
|
copyPath,
|
|
313
330
|
agentId: lead.id,
|
|
331
|
+
parentSessionId: run.sessionId,
|
|
314
332
|
title: `Artel · ${lead.name} — ${title}`,
|
|
315
333
|
})
|
|
316
334
|
this.#register(runId, runtime, lead, leadHandle)
|
|
@@ -453,7 +471,14 @@ export class ArtelEngine {
|
|
|
453
471
|
await Promise.resolve(this.#driver.interrupt(rt.handle)).catch(() => {})
|
|
454
472
|
}
|
|
455
473
|
}
|
|
456
|
-
|
|
474
|
+
// A stopped run keeps its diff available, so the session rail must show the
|
|
475
|
+
// same count the review panel will list — recalculate it before the run
|
|
476
|
+
// becomes terminal, not only when the agents go idle by themselves.
|
|
477
|
+
const changeCount = await this.#countChangesQuietly(runId)
|
|
478
|
+
await this.#store.patch(runId, {
|
|
479
|
+
status: 'interrupted',
|
|
480
|
+
...(changeCount === undefined ? {} : { changeCount }),
|
|
481
|
+
})
|
|
457
482
|
await this.#feed(runId, { kind: 'status', text: 'You stopped the run. The copy is still here, so the diff stays available.' })
|
|
458
483
|
return this.#summary(this.#requireRun(runId))
|
|
459
484
|
}
|
|
@@ -463,6 +488,7 @@ export class ArtelEngine {
|
|
|
463
488
|
async changes(runId) {
|
|
464
489
|
const run = this.#requireRun(runId)
|
|
465
490
|
if (!run.copyPath) return []
|
|
491
|
+
if (!(await pathExists(run.copyPath))) return []
|
|
466
492
|
const changes = await collectChanges({
|
|
467
493
|
copyRoot: run.copyPath,
|
|
468
494
|
beforeRoot: run.projectPath,
|
|
@@ -495,6 +521,24 @@ export class ArtelEngine {
|
|
|
495
521
|
return changes.length
|
|
496
522
|
}
|
|
497
523
|
|
|
524
|
+
/**
|
|
525
|
+
* Best-effort change count for a run that is about to become terminal.
|
|
526
|
+
*
|
|
527
|
+
* A run stopped before its copy finished must keep the stored count: hashing a
|
|
528
|
+
* missing or partial copy would report every project file as changed, which is
|
|
529
|
+
* not what the user can review. Only a fully copied run is counted, and a
|
|
530
|
+
* failure while hashing keeps the previous value instead of blocking the
|
|
531
|
+
* status transition.
|
|
532
|
+
* @param {string} runId - run id.
|
|
533
|
+
* @returns {Promise<number | undefined>} count to store, or undefined to keep it.
|
|
534
|
+
*/
|
|
535
|
+
async #countChangesQuietly(runId) {
|
|
536
|
+
const run = this.#store.get(runId)
|
|
537
|
+
if (!run || typeof run.copyPath !== 'string' || run.copyPath === '' || run.copyKind !== 'directory') return undefined
|
|
538
|
+
const changes = await this.changes(runId).catch(() => null)
|
|
539
|
+
return changes === null ? undefined : changes.length
|
|
540
|
+
}
|
|
541
|
+
|
|
498
542
|
async apply(runId, paths) {
|
|
499
543
|
const run = this.#requireRun(runId)
|
|
500
544
|
if (!['waiting', 'finished', 'interrupted', 'failed'].includes(run.status)) {
|
|
@@ -536,6 +580,7 @@ export class ArtelEngine {
|
|
|
536
580
|
text: `Applied ${result.applied.length} file${result.applied.length === 1 ? '' : 's'} to your project.`,
|
|
537
581
|
})
|
|
538
582
|
await this.#retire(runId)
|
|
583
|
+
await removeCopy(this.#copyRoot, run.copyPath).catch(() => {})
|
|
539
584
|
return { applied: result.applied, skipped: result.skipped }
|
|
540
585
|
}
|
|
541
586
|
|
|
@@ -853,15 +898,49 @@ export class ArtelEngine {
|
|
|
853
898
|
}
|
|
854
899
|
}
|
|
855
900
|
|
|
901
|
+
/**
|
|
902
|
+
* Append one feed event and keep the run's phase hint in step with it.
|
|
903
|
+
*
|
|
904
|
+
* Feeds from different agents arrive concurrently, so appends are queued per
|
|
905
|
+
* run: sequence numbers stay ordered and the phase always ends up matching the
|
|
906
|
+
* last status/plan line that was stored.
|
|
907
|
+
* @param {string} runId - run id.
|
|
908
|
+
* @param {object} event - feed event.
|
|
909
|
+
* @returns {Promise<void>} completes once the event and its phase are stored.
|
|
910
|
+
*/
|
|
856
911
|
async #feed(runId, event) {
|
|
857
912
|
const previous = this.#feedQueues.get(runId) ?? Promise.resolve()
|
|
858
913
|
const next = previous
|
|
859
|
-
.then(() =>
|
|
914
|
+
.then(async () => {
|
|
915
|
+
await this.#store.appendFeed(runId, event)
|
|
916
|
+
// Only a stored event may become the phase: a failed append must not
|
|
917
|
+
// advertise a line the client can never read from the feed.
|
|
918
|
+
await this.#publishPhase(runId, event)
|
|
919
|
+
})
|
|
860
920
|
.catch((error) => this.#log.warn?.(`artel: could not append feed for ${runId}: ${error.message}`))
|
|
861
921
|
this.#feedQueues.set(runId, next)
|
|
862
922
|
await next
|
|
863
923
|
}
|
|
864
924
|
|
|
925
|
+
/**
|
|
926
|
+
* Mirror the latest phase line into the run record, where the client's
|
|
927
|
+
* session rail reads it without loading the feed.
|
|
928
|
+
*
|
|
929
|
+
* Patching only `phase` never re-runs the status machine, so this stays safe
|
|
930
|
+
* on terminal runs: the final "Applied …" line lands after `status: applied`.
|
|
931
|
+
* A run pruned meanwhile is simply ignored.
|
|
932
|
+
* @param {string} runId - run id.
|
|
933
|
+
* @param {object} event - feed event that was just appended.
|
|
934
|
+
* @returns {Promise<void>} always completes.
|
|
935
|
+
*/
|
|
936
|
+
async #publishPhase(runId, event) {
|
|
937
|
+
const phase = phaseOfFeedEvent(event)
|
|
938
|
+
if (phase === undefined) return
|
|
939
|
+
const run = this.#store.get(runId)
|
|
940
|
+
if (!run || run.phase === phase) return
|
|
941
|
+
await this.#store.patch(runId, { phase }).catch(() => {})
|
|
942
|
+
}
|
|
943
|
+
|
|
865
944
|
async #fail(runId, error) {
|
|
866
945
|
const message = error instanceof Error ? error.message : String(error)
|
|
867
946
|
const run = this.#store.get(runId)
|
|
@@ -876,7 +955,12 @@ export class ArtelEngine {
|
|
|
876
955
|
}
|
|
877
956
|
this.#runs.delete(runId)
|
|
878
957
|
}
|
|
879
|
-
await this.#
|
|
958
|
+
const changeCount = await this.#countChangesQuietly(runId)
|
|
959
|
+
await this.#store.patch(runId, {
|
|
960
|
+
status: 'failed',
|
|
961
|
+
error: message,
|
|
962
|
+
...(changeCount === undefined ? {} : { changeCount }),
|
|
963
|
+
}).catch(() => {})
|
|
880
964
|
await this.#feed(runId, { kind: 'error', text: message }).catch(() => {})
|
|
881
965
|
}
|
|
882
966
|
|
|
@@ -890,7 +974,11 @@ export class ArtelEngine {
|
|
|
890
974
|
}
|
|
891
975
|
const run = this.#store.get(runId)
|
|
892
976
|
if (run && ['preparing', 'planning', 'running', 'waiting'].includes(run.status)) {
|
|
893
|
-
await this.#
|
|
977
|
+
const changeCount = await this.#countChangesQuietly(runId)
|
|
978
|
+
await this.#store.patch(runId, {
|
|
979
|
+
status: 'interrupted',
|
|
980
|
+
...(changeCount === undefined ? {} : { changeCount }),
|
|
981
|
+
}).catch(() => {})
|
|
894
982
|
await this.#store.appendFeed(runId, { kind: 'status', text: 'The plugin stopped. The diff is still available.' }).catch(() => {})
|
|
895
983
|
}
|
|
896
984
|
}
|
package/lib/host-driver.js
CHANGED
|
@@ -37,6 +37,10 @@ const PEER_PREFIX = /^Agent\s+.+?\s+sent a message:\s*/i
|
|
|
37
37
|
/** How many times a member prompt is retried while its activation closes. */
|
|
38
38
|
const DELIVERY_ATTEMPTS = 8
|
|
39
39
|
|
|
40
|
+
/** How often to look for a just-created child Session, and how long to wait. */
|
|
41
|
+
const SESSION_LOOKUP_ATTEMPTS = 4
|
|
42
|
+
const SESSION_LOOKUP_DELAY_MS = 25
|
|
43
|
+
|
|
40
44
|
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
41
45
|
|
|
42
46
|
/**
|
|
@@ -216,12 +220,84 @@ export class HostDriver {
|
|
|
216
220
|
throw new Error('This chat session has no project directory yet, so there is nothing to copy')
|
|
217
221
|
}
|
|
218
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Find the live Session behind a Session id, whichever host service exposes it.
|
|
225
|
+
* @param {string} sessionId - Session id.
|
|
226
|
+
* @returns {object | undefined} live Session, or undefined when it is not mounted.
|
|
227
|
+
*/
|
|
228
|
+
#sessionOf(sessionId) {
|
|
229
|
+
if (typeof sessionId !== 'string' || sessionId === '') return undefined
|
|
230
|
+
const agent = this.#ctx.get?.('agents')?.get?.(sessionId)
|
|
231
|
+
if (agent !== null && agent !== undefined && agent.session !== undefined) return agent.session
|
|
232
|
+
return this.#ctx.get?.('sessions')?.get?.(sessionId)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Make a freshly created child Session unattended.
|
|
237
|
+
*
|
|
238
|
+
* An Artel run has no human watching its own agents: a child that inherits the
|
|
239
|
+
* profile's `ask` approval policy would block forever on the first escalation
|
|
240
|
+
* (`sandbox_permissions` or an apply decision) and the whole run would hang.
|
|
241
|
+
* The child therefore gets approval policy `never` — the tool call is refused
|
|
242
|
+
* at once and the agent keeps going — and, when the chat Session is known, the
|
|
243
|
+
* sandbox mode the user runs that chat under.
|
|
244
|
+
*
|
|
245
|
+
* Both writes are the durable events the host services use themselves:
|
|
246
|
+
* `ApprovalService.setPolicy(agent, 'never')` appends `approval/policy` (and
|
|
247
|
+
* tells the agent about it), `setSandboxMode` appends `sandbox/mode`. Artel
|
|
248
|
+
* appends them directly so the driver imports no package that only exists
|
|
249
|
+
* inside the running profile. Every step is best-effort: a stripped profile or
|
|
250
|
+
* a Session that is already gone must never break agent creation.
|
|
251
|
+
* @param {{ sessionId: string, parentSessionId?: string, name: string }} request
|
|
252
|
+
* @returns {Promise<void>} completes once both policies were attempted.
|
|
253
|
+
*/
|
|
254
|
+
async #adoptChildSession({ sessionId, parentSessionId, name }) {
|
|
255
|
+
// The subagent runtime may attach a just-spawned child a moment after
|
|
256
|
+
// `startActivation` resolves, so a new child is looked up a few times.
|
|
257
|
+
let session
|
|
258
|
+
for (let attempt = 0; attempt < SESSION_LOOKUP_ATTEMPTS; attempt += 1) {
|
|
259
|
+
session = this.#sessionOf(sessionId)
|
|
260
|
+
if (session !== undefined) break
|
|
261
|
+
if (attempt < SESSION_LOOKUP_ATTEMPTS - 1) await delay(SESSION_LOOKUP_DELAY_MS)
|
|
262
|
+
}
|
|
263
|
+
if (session === undefined) {
|
|
264
|
+
this.#log?.warn?.(`dsh-artel: could not reach Session "${sessionId}" of ${name} to make it unattended`)
|
|
265
|
+
return
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
try {
|
|
269
|
+
const agent = this.#ctx.get?.('agents')?.get?.(sessionId)
|
|
270
|
+
const approval = this.#ctx.get?.('approval')
|
|
271
|
+
if (agent !== null && agent !== undefined && typeof approval?.setPolicy === 'function') {
|
|
272
|
+
approval.setPolicy(agent, 'never')
|
|
273
|
+
} else if (typeof session.append === 'function') {
|
|
274
|
+
// The durable form of the same policy write, for profiles where the
|
|
275
|
+
// approval service is not the one holding this agent.
|
|
276
|
+
session.append('approval/policy', { policy: 'never' })
|
|
277
|
+
}
|
|
278
|
+
} catch (error) {
|
|
279
|
+
this.#log?.warn?.(`dsh-artel: could not set the approval policy of ${name}: ${error?.message ?? error}`)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (typeof parentSessionId !== 'string' || parentSessionId === '') return
|
|
283
|
+
try {
|
|
284
|
+
const parent = this.#sessionOf(parentSessionId)
|
|
285
|
+
const sandboxPolicy = this.#ctx.get?.('sandboxPolicy')
|
|
286
|
+
if (parent === undefined || typeof sandboxPolicy?.resolve !== 'function') return
|
|
287
|
+
const mode = sandboxPolicy.resolve({ session: parent })?.mode
|
|
288
|
+
if (typeof mode !== 'string' || mode === '') return
|
|
289
|
+
if (typeof session.append === 'function') session.append('sandbox/mode', { mode })
|
|
290
|
+
} catch (error) {
|
|
291
|
+
this.#log?.warn?.(`dsh-artel: could not copy the sandbox mode to ${name}: ${error?.message ?? error}`)
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
219
295
|
/**
|
|
220
296
|
* Create one ordinary Session whose working directory is the run copy.
|
|
221
|
-
* @param {{ name: string, mode: string, projectPath: string, copyPath: string, agentId: string, title?: string }} request
|
|
297
|
+
* @param {{ name: string, mode: string, projectPath: string, copyPath: string, agentId: string, title?: string, parentSessionId?: string }} request
|
|
222
298
|
* @returns {Promise<DriverHandle>} handle used for later prompts.
|
|
223
299
|
*/
|
|
224
|
-
async createAgent({ name, mode, projectPath, copyPath, agentId, title }) {
|
|
300
|
+
async createAgent({ name, mode, projectPath, copyPath, agentId, title, parentSessionId }) {
|
|
225
301
|
if (this.#closed) throw new Error('artel driver is closed')
|
|
226
302
|
// An explicit identity keeps the controller from reusing a blank Session,
|
|
227
303
|
// so every agent really gets its own conversation.
|
|
@@ -248,6 +324,7 @@ export class HostDriver {
|
|
|
248
324
|
copyPath,
|
|
249
325
|
}
|
|
250
326
|
this.#entries.set(handle.sessionId, { handle, listener: null, chain: Promise.resolve() })
|
|
327
|
+
await this.#adoptChildSession({ sessionId, parentSessionId, name })
|
|
251
328
|
return handle
|
|
252
329
|
}
|
|
253
330
|
|
|
@@ -297,6 +374,11 @@ export class HostDriver {
|
|
|
297
374
|
activation,
|
|
298
375
|
}
|
|
299
376
|
this.#entries.set(handle.sessionId, { handle, listener: null, chain: Promise.resolve() })
|
|
377
|
+
await this.#adoptChildSession({
|
|
378
|
+
sessionId: handle.sessionId,
|
|
379
|
+
parentSessionId: parent.sessionId,
|
|
380
|
+
name: displayName,
|
|
381
|
+
})
|
|
300
382
|
return handle
|
|
301
383
|
}
|
|
302
384
|
|
package/lib/index.js
CHANGED
|
@@ -27,7 +27,7 @@ export const name = 'dsh-artel'
|
|
|
27
27
|
export const inject = ['webServer']
|
|
28
28
|
|
|
29
29
|
/** Version reported by the health route. */
|
|
30
|
-
export const version = '0.
|
|
30
|
+
export const version = '0.2.0'
|
|
31
31
|
|
|
32
32
|
/** Directory under `<DSH_HOME>` that holds every profile's copies and run state. */
|
|
33
33
|
const DATA_DIR = 'artel'
|
|
@@ -268,6 +268,22 @@ export async function apply(ctx, config = {}) {
|
|
|
268
268
|
return
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Fallback project directory of the profile: a fresh chat session may not
|
|
273
|
+
* have a working directory of its own yet, and the hero still needs a
|
|
274
|
+
* project to start the first run in.
|
|
275
|
+
* @returns {string | undefined} profile default working directory.
|
|
276
|
+
*/
|
|
277
|
+
const defaultProjectDirectory = () => {
|
|
278
|
+
try {
|
|
279
|
+
const service = scope?.get?.('workingDirectory') ?? ctx.get?.('workingDirectory')
|
|
280
|
+
const directory = service?.defaultDirectory
|
|
281
|
+
return typeof directory === 'string' && directory !== '' ? directory : undefined
|
|
282
|
+
} catch {
|
|
283
|
+
return undefined
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
271
287
|
const disposers = registerArtelRoutes({
|
|
272
288
|
webServer,
|
|
273
289
|
engine,
|
|
@@ -275,6 +291,7 @@ export async function apply(ctx, config = {}) {
|
|
|
275
291
|
log,
|
|
276
292
|
diagnostics,
|
|
277
293
|
resolveProjectPath: (sessionId) => driver.projectPathOf(sessionId),
|
|
294
|
+
defaultDirectory: defaultProjectDirectory,
|
|
278
295
|
writeClientReport: (body) => {
|
|
279
296
|
const line = `${JSON.stringify({ at: new Date().toISOString(), report: body })}\n`
|
|
280
297
|
appendFileSync(path.join(settings.stateDir, 'client.log'), line)
|
package/lib/prompts.js
CHANGED
|
@@ -72,6 +72,7 @@ export function swarmPlanPrompt({ copyPath, projectPath, task, peers, selfName,
|
|
|
72
72
|
const talk = canMessage
|
|
73
73
|
? `- You are a live team, not three separate conversations: every other agent READS what you send, and you read what they send. Talk with send_message({ agent: "<address>", message: "<text>" }) — the address is the short lowercase name quoted in the list above and it is case-sensitive ("orion", not "Orion"). list_agents({}) shows the whole team${selfLine}. Every message is also shown to the user in the shared feed.
|
|
74
74
|
- Use messaging for real coordination only: announce the area you are taking, answer one concrete question, or warn a peer about a clash. Two short messages is the ceiling — never wait for a reply and never start a chat.
|
|
75
|
+
- Do not call wait_agent in this turn: the go-ahead arrives from Artel only after every agent ends its turn, so waiting here stalls the whole team. Announce, then end your turn.
|
|
75
76
|
- The ownership decision itself still goes into the OWNERSHIP line below: Artel collects those lines, resolves overlaps (first claim wins) and sends everyone the final map. Files nobody claimed are handed to agents that claimed nothing.`
|
|
76
77
|
: `- Do not try to reach the other agents with send_message or list_agents: each agent is a separate conversation and those calls fail. Coordination happens through the OWNERSHIP line below — Artel collects the claims, resolves overlaps (first claim wins) and sends everyone the final map. Files nobody claimed are handed to agents that claimed nothing.`
|
|
77
78
|
const shared = canMessage
|
package/lib/routes.js
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* machine, from the page this Host serves.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
import path from 'node:path'
|
|
14
|
+
|
|
13
15
|
/** Prefix shared by every artel route. */
|
|
14
16
|
export const API_PREFIX = '/api/dsh-artel'
|
|
15
17
|
|
|
@@ -123,6 +125,41 @@ export function queryParam(url, name) {
|
|
|
123
125
|
return value === null ? undefined : value
|
|
124
126
|
}
|
|
125
127
|
|
|
128
|
+
/**
|
|
129
|
+
* Resolve the project a chat session belongs to, for the Artel hero.
|
|
130
|
+
*
|
|
131
|
+
* The session's own working directory wins; a fresh session may not have one
|
|
132
|
+
* yet, so the profile's `workingDirectory.defaultDirectory` is the fallback.
|
|
133
|
+
* When neither exists the answer is null and the client shows its "no project"
|
|
134
|
+
* state instead of an error.
|
|
135
|
+
* @param {object} request - resolution inputs.
|
|
136
|
+
* @param {string | undefined} request.sessionId - chat session id from the query string.
|
|
137
|
+
* @param {(sessionId: string) => Promise<string> | string} [request.resolveProjectPath] - project lookup used by POST /runs.
|
|
138
|
+
* @param {string | (() => string | undefined)} [request.defaultDirectory] - profile fallback working directory.
|
|
139
|
+
* @returns {Promise<{ projectPath: string | null, name: string | null }>} project path and its basename.
|
|
140
|
+
*/
|
|
141
|
+
export async function resolveProject({ sessionId, resolveProjectPath, defaultDirectory }) {
|
|
142
|
+
if (typeof sessionId !== 'string' || sessionId === '') {
|
|
143
|
+
throw new RouteError('sessionId is required', 400, 'artel/bad-request')
|
|
144
|
+
}
|
|
145
|
+
let projectPath
|
|
146
|
+
if (typeof resolveProjectPath === 'function') {
|
|
147
|
+
try {
|
|
148
|
+
projectPath = await resolveProjectPath(sessionId)
|
|
149
|
+
} catch {
|
|
150
|
+
// The session may be too fresh to have a project directory: try the fallback.
|
|
151
|
+
projectPath = undefined
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (typeof projectPath !== 'string' || projectPath === '') {
|
|
155
|
+
const fallback = typeof defaultDirectory === 'function' ? defaultDirectory() : defaultDirectory
|
|
156
|
+
projectPath = typeof fallback === 'string' && fallback !== '' ? fallback : undefined
|
|
157
|
+
}
|
|
158
|
+
if (typeof projectPath !== 'string' || projectPath === '') return { projectPath: null, name: null }
|
|
159
|
+
const resolved = path.resolve(projectPath)
|
|
160
|
+
return { projectPath: resolved, name: path.basename(resolved) }
|
|
161
|
+
}
|
|
162
|
+
|
|
126
163
|
/**
|
|
127
164
|
* Build one route handler that adds the fence and the error mapping.
|
|
128
165
|
* @param {(request: import('node:http').IncomingMessage, response: import('node:http').ServerResponse, url: URL) => Promise<void> | void} handler
|
|
@@ -177,12 +214,13 @@ export function tailSegments(pathname, prefix) {
|
|
|
177
214
|
* @param {{ register(route: { kind: 'prefix' | 'exact', path: string, handler: Function }): () => void }} options.webServer - Host web server.
|
|
178
215
|
* @param {import('./engine.js').ArtelEngine} options.engine - run orchestrator.
|
|
179
216
|
* @param {(sessionId: string) => Promise<string> | string} [options.resolveProjectPath] - looks the project directory up from the chat session.
|
|
217
|
+
* @param {string | (() => string | undefined)} [options.defaultDirectory] - profile working directory used when the session has none yet.
|
|
180
218
|
* @param {() => Record<string, unknown>} [options.diagnostics] - reports how the Host wired this package.
|
|
181
219
|
* @param {string} options.version - plugin version reported by the API.
|
|
182
220
|
* @param {Pick<Console, 'warn' | 'info'>} [options.log] - logger.
|
|
183
221
|
* @returns {Array<() => void>} disposers for the registered routes.
|
|
184
222
|
*/
|
|
185
|
-
export function registerArtelRoutes({ webServer, engine, resolveProjectPath, version, diagnostics, writeClientReport, log = console }) {
|
|
223
|
+
export function registerArtelRoutes({ webServer, engine, resolveProjectPath, defaultDirectory, version, diagnostics, writeClientReport, log = console }) {
|
|
186
224
|
const disposers = []
|
|
187
225
|
|
|
188
226
|
disposers.push(webServer.register({
|
|
@@ -220,6 +258,20 @@ export function registerArtelRoutes({ webServer, engine, resolveProjectPath, ver
|
|
|
220
258
|
}, { log }),
|
|
221
259
|
}))
|
|
222
260
|
|
|
261
|
+
disposers.push(webServer.register({
|
|
262
|
+
kind: 'exact',
|
|
263
|
+
path: `${API_PREFIX}/project`,
|
|
264
|
+
handler: fenced(async (request, response, url) => {
|
|
265
|
+
const method = (request.method ?? 'GET').toUpperCase()
|
|
266
|
+
if (method !== 'GET') throw new RouteError('Method not allowed', 405, 'artel/method')
|
|
267
|
+
writeJson(response, 200, await resolveProject({
|
|
268
|
+
sessionId: queryParam(url, 'sessionId'),
|
|
269
|
+
resolveProjectPath,
|
|
270
|
+
defaultDirectory,
|
|
271
|
+
}))
|
|
272
|
+
}, { log }),
|
|
273
|
+
}))
|
|
274
|
+
|
|
223
275
|
disposers.push(webServer.register({
|
|
224
276
|
kind: 'prefix',
|
|
225
277
|
path: `${API_PREFIX}/runs`,
|
package/lib/run-store.js
CHANGED
|
@@ -43,6 +43,36 @@ export function newRunId(now = Date.now(), random = Math.random) {
|
|
|
43
43
|
return `fg-${stamp}-${suffix}`
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/** Longest phase hint kept on a run: one short line for the client's session rail. */
|
|
47
|
+
export const PHASE_MAX_LENGTH = 120
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Normalize one phase text: the rail has room for a single short line, so
|
|
51
|
+
* newlines and repeated spaces collapse into one space and the result is capped.
|
|
52
|
+
* @param {unknown} text - raw phase text.
|
|
53
|
+
* @returns {string | undefined} single-line hint of at most PHASE_MAX_LENGTH characters, or undefined when there is no text.
|
|
54
|
+
*/
|
|
55
|
+
export function phaseText(text) {
|
|
56
|
+
if (typeof text !== 'string') return undefined
|
|
57
|
+
const line = text.replace(/\s+/g, ' ').trim()
|
|
58
|
+
if (line === '') return undefined
|
|
59
|
+
return line.length > PHASE_MAX_LENGTH ? line.slice(0, PHASE_MAX_LENGTH) : line
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Turn one feed event into the "what is happening now" hint of a run.
|
|
64
|
+
*
|
|
65
|
+
* Only `status` and `plan` lines are phases: they describe the stage of the run
|
|
66
|
+
* itself, while agent messages and tool calls are conversation, not a phase.
|
|
67
|
+
* @param {{ kind?: unknown, text?: unknown }} event - feed event.
|
|
68
|
+
* @returns {string | undefined} phase hint, or undefined when the event is not a phase.
|
|
69
|
+
*/
|
|
70
|
+
export function phaseOfFeedEvent(event) {
|
|
71
|
+
if (event === null || typeof event !== 'object') return undefined
|
|
72
|
+
if (event.kind !== 'status' && event.kind !== 'plan') return undefined
|
|
73
|
+
return phaseText(event.text)
|
|
74
|
+
}
|
|
75
|
+
|
|
46
76
|
/** Client-facing view of a run: no path hashes, no feed. */
|
|
47
77
|
export function toSummary(run) {
|
|
48
78
|
return {
|
|
@@ -54,6 +84,7 @@ export function toSummary(run) {
|
|
|
54
84
|
copyPath: run.copyPath,
|
|
55
85
|
status: run.status,
|
|
56
86
|
error: run.error,
|
|
87
|
+
phase: phaseText(run.phase) ?? null,
|
|
57
88
|
agents: (run.agents ?? []).map((agent) => ({
|
|
58
89
|
id: agent.id,
|
|
59
90
|
name: agent.name,
|
package/locale/en.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Artel",
|
|
4
|
-
"description": "Run a development task in an isolated copy of your project: one agent on its own, or three agents sharing one copy and dividing the files first while they message each other. Watch the live feed, review the diff line by line, then apply
|
|
4
|
+
"description": "Run a development task in an isolated copy of your project: one agent on its own, or three agents sharing one copy and dividing the files first while they message each other. Watch the live feed of full agent replies, review the diff line by line, then apply the result or discard it. Open Artel with the button next to the chat composer.",
|
|
5
5
|
"detail": "docs/guide.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/locale/ru.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Artel",
|
|
4
|
-
"description": "Выполняет задачу по разработке в изолированной копии проекта: один агент сам по себе или трое в общей копии, которые сначала делят файлы и переписываются друг с другом. Смотрите
|
|
4
|
+
"description": "Выполняет задачу по разработке в изолированной копии проекта: один агент сам по себе или трое в общей копии, которые сначала делят файлы и переписываются друг с другом. Смотрите живую ленту полноценных реплик агентов, проверяйте разницу построчно и примените результат или отклоните его. Откройте «Артель» кнопкой рядом с композером в чате.",
|
|
5
5
|
"detail": "docs/guide.ru.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Artel",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "在项目的隔离副本中执行开发任务:一个智能体独立完成,或三个智能体共用一份副本、先划分文件并互相发消息。查看智能体完整回复的实时动态,逐行检查差异,然后应用结果或放弃它。用聊天输入框旁的按钮打开 Artel。",
|
|
5
5
|
"detail": "docs/guide.zh.md"
|
|
6
6
|
}
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-artel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Run coding agents in a separate copy of your project: Solo or Swarm, review the changes, apply them yourself.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"cordis.patch.yml",
|
|
33
33
|
"docs/*.md",
|
|
34
34
|
"docs/*.svg",
|
|
35
|
+
"docs/artel-in-chat/screens/",
|
|
35
36
|
"LICENSE"
|
|
36
37
|
],
|
|
37
38
|
"keywords": [
|