@agimon-ai/po-profile 0.0.0-alpha.93 → 0.0.0-alpha.95

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 CHANGED
@@ -61,7 +61,9 @@ See the [integration contract](./src/prompts/help-how-to-profile/references/prof
61
61
  `defaultProfile`
62
62
  names the persona a run starts on when nothing else does, mirroring `defaultMajorMode` in
63
63
  `modes.yaml` and `defaultDomains` in `domains.yaml`; `--profile` and an inherited `PO_PROFILE`
64
- both override it. Resolution runs
64
+ both override it. A name no file declares may come from a plugin source: the launch waits for that source
65
+ for at most ten seconds, then starts with no profile and one warning. Sources can also report readiness and a
66
+ workspace default, see the contract's section on plugin sources. Resolution runs
65
67
  from personal discovery to repository discovery, then personal explicit entries to repository
66
68
  explicit entries. A later profile replaces an earlier profile with the same name.
67
69
 
@@ -16,6 +16,25 @@ const apiContracts = (0, _agimon_ai_po_core_apiContracts.defineApiContract)({
16
16
  authentication: "owner",
17
17
  description: "Read the current session selection.",
18
18
  responses: (0, _agimon_ai_po_core_apiContracts.jsonApiResponses)(typebox.Type.Object({ profile: typebox.Type.Union([typebox.Type.Null(), typebox.Type.String()]) }))
19
+ }, {
20
+ id: "profile.launchProfiles",
21
+ scope: "workspace",
22
+ basePath: "profile",
23
+ path: "/launch-profiles",
24
+ method: "GET",
25
+ authentication: "owner",
26
+ description: "List the profiles a new session in this workspace can start with, as names and display data only. Waits up to ten seconds for plugin sources.",
27
+ responses: (0, _agimon_ai_po_core_apiContracts.jsonApiResponses)(typebox.Type.Object({
28
+ profiles: typebox.Type.Array(typebox.Type.Object({
29
+ name: typebox.Type.String(),
30
+ identity: typebox.Type.Optional(typebox.Type.Object({
31
+ name: typebox.Type.Optional(typebox.Type.String()),
32
+ icon: typebox.Type.Optional(typebox.Type.String())
33
+ })),
34
+ sourceId: typebox.Type.String()
35
+ })),
36
+ readiness: typebox.Type.Union([typebox.Type.Literal("ready"), typebox.Type.Literal("unavailable")])
37
+ }))
19
38
  }],
20
39
  sockets: [],
21
40
  dynamic: []
@@ -1 +1 @@
1
- {"version":3,"file":"apiContracts.cjs","names":["defineApiContract","jsonApiResponses","Type"],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\nexport const apiContracts = defineApiContract({\n version: 1,\n http: [\n {\n id: 'profile.current',\n scope: 'session',\n basePath: 'profile',\n path: '/current',\n method: 'GET',\n authentication: 'owner',\n description: 'Read the current session selection.',\n responses: jsonApiResponses(Type.Object({ profile: Type.Union([Type.Null(), Type.String()]) })),\n },\n ],\n sockets: [],\n dynamic: [],\n});\nexport default apiContracts;\n"],"mappings":";;;;;;;AAGA,MAAa,gBAAA,GAAeA,gCAAAA,kBAAAA,CAAkB;CAC5C,SAAS;CACT,MAAM,CACJ;EACE,IAAI;EACJ,OAAO;EACP,UAAU;EACV,MAAM;EACN,QAAQ;EACR,gBAAgB;EAChB,aAAa;EACb,YAAA,GAAWC,gCAAAA,iBAAAA,CAAiBC,QAAAA,KAAK,OAAO,EAAE,SAASA,QAAAA,KAAK,MAAM,CAACA,QAAAA,KAAK,KAAK,GAAGA,QAAAA,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;CAChG,CACF;CACA,SAAS,CAAC;CACV,SAAS,CAAC;AACZ,CAAC"}
1
+ {"version":3,"file":"apiContracts.cjs","names":["defineApiContract","jsonApiResponses","Type"],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\nexport const apiContracts = defineApiContract({\n version: 1,\n http: [\n {\n id: 'profile.current',\n scope: 'session',\n basePath: 'profile',\n path: '/current',\n method: 'GET',\n authentication: 'owner',\n description: 'Read the current session selection.',\n responses: jsonApiResponses(Type.Object({ profile: Type.Union([Type.Null(), Type.String()]) })),\n },\n {\n id: 'profile.launchProfiles',\n scope: 'workspace',\n basePath: 'profile',\n path: '/launch-profiles',\n method: 'GET',\n authentication: 'owner',\n description:\n 'List the profiles a new session in this workspace can start with, as names and display data only. Waits up to ten seconds for plugin sources.',\n responses: jsonApiResponses(\n Type.Object({\n profiles: Type.Array(\n Type.Object({\n name: Type.String(),\n identity: Type.Optional(\n Type.Object({ name: Type.Optional(Type.String()), icon: Type.Optional(Type.String()) }),\n ),\n sourceId: Type.String(),\n }),\n ),\n readiness: Type.Union([Type.Literal('ready'), Type.Literal('unavailable')]),\n }),\n ),\n },\n ],\n sockets: [],\n dynamic: [],\n});\nexport default apiContracts;\n"],"mappings":";;;;;;;AAGA,MAAa,gBAAA,GAAeA,gCAAAA,kBAAAA,CAAkB;CAC5C,SAAS;CACT,MAAM,CACJ;EACE,IAAI;EACJ,OAAO;EACP,UAAU;EACV,MAAM;EACN,QAAQ;EACR,gBAAgB;EAChB,aAAa;EACb,YAAA,GAAWC,gCAAAA,iBAAAA,CAAiBC,QAAAA,KAAK,OAAO,EAAE,SAASA,QAAAA,KAAK,MAAM,CAACA,QAAAA,KAAK,KAAK,GAAGA,QAAAA,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;CAChG,GACA;EACE,IAAI;EACJ,OAAO;EACP,UAAU;EACV,MAAM;EACN,QAAQ;EACR,gBAAgB;EAChB,aACE;EACF,YAAA,GAAWD,gCAAAA,iBAAAA,CACTC,QAAAA,KAAK,OAAO;GACV,UAAUA,QAAAA,KAAK,MACbA,QAAAA,KAAK,OAAO;IACV,MAAMA,QAAAA,KAAK,OAAO;IAClB,UAAUA,QAAAA,KAAK,SACbA,QAAAA,KAAK,OAAO;KAAE,MAAMA,QAAAA,KAAK,SAASA,QAAAA,KAAK,OAAO,CAAC;KAAG,MAAMA,QAAAA,KAAK,SAASA,QAAAA,KAAK,OAAO,CAAC;IAAE,CAAC,CACxF;IACA,UAAUA,QAAAA,KAAK,OAAO;GACxB,CAAC,CACH;GACA,WAAWA,QAAAA,KAAK,MAAM,CAACA,QAAAA,KAAK,QAAQ,OAAO,GAAGA,QAAAA,KAAK,QAAQ,aAAa,CAAC,CAAC;EAC5E,CAAC,CACH;CACF,CACF;CACA,SAAS,CAAC;CACV,SAAS,CAAC;AACZ,CAAC"}
@@ -12,6 +12,25 @@ const apiContracts = defineApiContract({
12
12
  authentication: "owner",
13
13
  description: "Read the current session selection.",
14
14
  responses: jsonApiResponses(Type.Object({ profile: Type.Union([Type.Null(), Type.String()]) }))
15
+ }, {
16
+ id: "profile.launchProfiles",
17
+ scope: "workspace",
18
+ basePath: "profile",
19
+ path: "/launch-profiles",
20
+ method: "GET",
21
+ authentication: "owner",
22
+ description: "List the profiles a new session in this workspace can start with, as names and display data only. Waits up to ten seconds for plugin sources.",
23
+ responses: jsonApiResponses(Type.Object({
24
+ profiles: Type.Array(Type.Object({
25
+ name: Type.String(),
26
+ identity: Type.Optional(Type.Object({
27
+ name: Type.Optional(Type.String()),
28
+ icon: Type.Optional(Type.String())
29
+ })),
30
+ sourceId: Type.String()
31
+ })),
32
+ readiness: Type.Union([Type.Literal("ready"), Type.Literal("unavailable")])
33
+ }))
15
34
  }],
16
35
  sockets: [],
17
36
  dynamic: []
@@ -1 +1 @@
1
- {"version":3,"file":"apiContracts.mjs","names":[],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\nexport const apiContracts = defineApiContract({\n version: 1,\n http: [\n {\n id: 'profile.current',\n scope: 'session',\n basePath: 'profile',\n path: '/current',\n method: 'GET',\n authentication: 'owner',\n description: 'Read the current session selection.',\n responses: jsonApiResponses(Type.Object({ profile: Type.Union([Type.Null(), Type.String()]) })),\n },\n ],\n sockets: [],\n dynamic: [],\n});\nexport default apiContracts;\n"],"mappings":";;;AAGA,MAAa,eAAe,kBAAkB;CAC5C,SAAS;CACT,MAAM,CACJ;EACE,IAAI;EACJ,OAAO;EACP,UAAU;EACV,MAAM;EACN,QAAQ;EACR,gBAAgB;EAChB,aAAa;EACb,WAAW,iBAAiB,KAAK,OAAO,EAAE,SAAS,KAAK,MAAM,CAAC,KAAK,KAAK,GAAG,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;CAChG,CACF;CACA,SAAS,CAAC;CACV,SAAS,CAAC;AACZ,CAAC"}
1
+ {"version":3,"file":"apiContracts.mjs","names":[],"sources":["../src/schemas/apiContracts.ts"],"sourcesContent":["import { defineApiContract, jsonApiResponses } from '@agimon-ai/po-core/apiContracts';\nimport { Type } from 'typebox';\n\nexport const apiContracts = defineApiContract({\n version: 1,\n http: [\n {\n id: 'profile.current',\n scope: 'session',\n basePath: 'profile',\n path: '/current',\n method: 'GET',\n authentication: 'owner',\n description: 'Read the current session selection.',\n responses: jsonApiResponses(Type.Object({ profile: Type.Union([Type.Null(), Type.String()]) })),\n },\n {\n id: 'profile.launchProfiles',\n scope: 'workspace',\n basePath: 'profile',\n path: '/launch-profiles',\n method: 'GET',\n authentication: 'owner',\n description:\n 'List the profiles a new session in this workspace can start with, as names and display data only. Waits up to ten seconds for plugin sources.',\n responses: jsonApiResponses(\n Type.Object({\n profiles: Type.Array(\n Type.Object({\n name: Type.String(),\n identity: Type.Optional(\n Type.Object({ name: Type.Optional(Type.String()), icon: Type.Optional(Type.String()) }),\n ),\n sourceId: Type.String(),\n }),\n ),\n readiness: Type.Union([Type.Literal('ready'), Type.Literal('unavailable')]),\n }),\n ),\n },\n ],\n sockets: [],\n dynamic: [],\n});\nexport default apiContracts;\n"],"mappings":";;;AAGA,MAAa,eAAe,kBAAkB;CAC5C,SAAS;CACT,MAAM,CACJ;EACE,IAAI;EACJ,OAAO;EACP,UAAU;EACV,MAAM;EACN,QAAQ;EACR,gBAAgB;EAChB,aAAa;EACb,WAAW,iBAAiB,KAAK,OAAO,EAAE,SAAS,KAAK,MAAM,CAAC,KAAK,KAAK,GAAG,KAAK,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;CAChG,GACA;EACE,IAAI;EACJ,OAAO;EACP,UAAU;EACV,MAAM;EACN,QAAQ;EACR,gBAAgB;EAChB,aACE;EACF,WAAW,iBACT,KAAK,OAAO;GACV,UAAU,KAAK,MACb,KAAK,OAAO;IACV,MAAM,KAAK,OAAO;IAClB,UAAU,KAAK,SACb,KAAK,OAAO;KAAE,MAAM,KAAK,SAAS,KAAK,OAAO,CAAC;KAAG,MAAM,KAAK,SAAS,KAAK,OAAO,CAAC;IAAE,CAAC,CACxF;IACA,UAAU,KAAK,OAAO;GACxB,CAAC,CACH;GACA,WAAW,KAAK,MAAM,CAAC,KAAK,QAAQ,OAAO,GAAG,KAAK,QAAQ,aAAa,CAAC,CAAC;EAC5E,CAAC,CACH;CACF,CACF;CACA,SAAS,CAAC;CACV,SAAS,CAAC;AACZ,CAAC"}
@@ -24,10 +24,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  enumerable: true
25
25
  }) : target, mod));
26
26
  //#endregion
27
- const require_profileText = require("../profileText-CiTmnfKH.cjs");
27
+ const require_profileText = require("../profileText-D_VL4Sd4.cjs");
28
+ let _agimon_ai_po_core_extensionFile = require("@agimon-ai/po-core/extensionFile");
28
29
  let _agimon_ai_po_config_profiles = require("@agimon-ai/po-config/profiles");
29
30
  let _agimon_ai_po_core_serverPlugin = require("@agimon-ai/po-core/serverPlugin");
30
- let _agimon_ai_po_core_extensionFile = require("@agimon-ai/po-core/extensionFile");
31
31
  let node_path = require("node:path");
32
32
  node_path = __toESM(node_path, 1);
33
33
  let _agimon_ai_po_core_piSettings = require("@agimon-ai/po-core/piSettings");
@@ -438,80 +438,6 @@ function createProfileMemoryNamespace(options) {
438
438
  };
439
439
  }
440
440
  //#endregion
441
- //#region src/extensions/workspaces/sessions/(backend)/root.server.ts
442
- var root_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoot)(({ agent, host, signal, context }) => {
443
- if (!agent) return { value: void 0 };
444
- const execution = agent.context;
445
- const scope = { workspaceId: host.context.workspaceId };
446
- const readProfiles = () => (0, _agimon_ai_po_config_profiles.loadProfiles)(execution.repoRoot, execution.environment.HOME ?? _agimon_ai_po_core_platform.nodeHost.homeDirectory());
447
- const readProfile = (profileName) => require_profileText.findProfile(readProfiles(), require_profileText.readProfileSources(context, scope), profileName);
448
- const unregisterResolver = agent.registerInitialSelectionResolver((selection) => {
449
- if (selection.profile === void 0) return selection;
450
- return require_profileText.mergeProfiles(readProfiles(), require_profileText.readProfileSources(context, scope)).some(({ name }) => name === selection.profile) ? selection : {
451
- ...selection,
452
- profile: void 0
453
- };
454
- });
455
- const runtime = require_profileText.createProfileRuntime({
456
- readBinding: (profileName) => readProfile(profileName).integration,
457
- readEnv: (profileName) => readProfile(profileName).env
458
- });
459
- const unsubscribe = agent.subscribeSelection(async (selection, applied) => {
460
- try {
461
- await runtime.select(selection.profile, { force: applied?.refresh?.includes("profile") === true });
462
- } catch (error) {
463
- throw new _agimon_ai_po_core_headless.PoHeadlessPromptAdmissionError(error);
464
- }
465
- });
466
- const invalidate = () => runtime.invalidate();
467
- signal.addEventListener("abort", invalidate, { once: true });
468
- if (signal.aborted) runtime.invalidate();
469
- return {
470
- value: runtime,
471
- services: [require_profileText.createProfileRuntimePlugin(runtime), (serviceContext) => {
472
- serviceContext.inject([_agimon_ai_po_core_codemode.PO_CODEMODE_SERVICE, PROFILE_MEMORY_STORE_SERVICE], (injected) => {
473
- const codemode = (0, _agimon_ai_po_core_codemode.readPoCodemode)(injected);
474
- if (!codemode) return void 0;
475
- const registration = codemode.register(PROFILE_MEMORY_NAMESPACE_SOURCE, createProfileMemoryNamespace({
476
- store: requireProfileMemoryStore(injected),
477
- runtime,
478
- sessionId: execution.sessionId,
479
- assertAvailable: () => {
480
- if (signal.aborted) throw new Error("Profile memory session is unavailable.");
481
- }
482
- }));
483
- return () => registration.dispose();
484
- });
485
- }],
486
- async onDispose() {
487
- await (0, _agimon_ai_po_core_extensionFile.runCleanups)([
488
- unregisterResolver,
489
- unsubscribe,
490
- () => signal.removeEventListener("abort", invalidate),
491
- () => runtime.dispose()
492
- ], "Profile cleanup failed.");
493
- }
494
- };
495
- });
496
- //#endregion
497
- //#region src/extensions/workspaces/sessions/(backend)/api/profile/route.server.ts
498
- var route_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoute)(({ agent }) => ({
499
- basePath: "profile",
500
- start: () => ({
501
- fetch(request) {
502
- if (new URL(request.url).pathname !== "/current") return Response.json({ error: "Not found" }, { status: 404 });
503
- if (request.method !== "GET") return Response.json({ error: "Method not allowed" }, {
504
- status: 405,
505
- headers: { Allow: "GET" }
506
- });
507
- if (!agent) return Response.json({ error: "Session agent unavailable" }, { status: 404 });
508
- const selection = agent.context.selection;
509
- return Response.json({ profile: selection.profile ?? null });
510
- },
511
- close() {}
512
- })
513
- }));
514
- //#endregion
515
441
  //#region src/extensions/workspaces/sessions/(backend)/_lib/profileServer.ts
516
442
  const resolveSelected = (execution, sources, name) => require_profileText.findProfile((0, _agimon_ai_po_config_profiles.loadProfiles)(execution.repoRoot, execution.environment?.HOME), sources, name);
517
443
  async function readSelectedPersona(execution, sources) {
@@ -522,15 +448,38 @@ async function readSelectedPersona(execution, sources) {
522
448
  if (!prompt) throw new Error(`Profile "${name}" has no readable persona text`);
523
449
  return prompt;
524
450
  }
525
- async function publishSelectedIdentity(execution, sources, profile) {
451
+ async function journalIdentity(execution, sources, profile, state) {
526
452
  const identity = profile === void 0 ? void 0 : resolveSelected(execution, sources, profile).identity;
527
453
  await execution.session.appendCustomEntry(_agimon_ai_po_core_profileIdentity.PO_PROFILE_IDENTITY_ENTRY_TYPE, {
528
454
  profile: profile ?? null,
529
455
  ...identity?.name === void 0 ? {} : { name: identity.name },
530
456
  ...identity?.icon === void 0 ? {} : { icon: identity.icon }
531
457
  });
458
+ state.journaled = { profile };
459
+ }
460
+ /**
461
+ * Journals the marker once per selection: the command and the host both report a change, and the second
462
+ * report finds it already journaled.
463
+ */
464
+ async function publishSelectedIdentity(execution, sources, profile, state) {
465
+ if (state.journaled !== void 0 && state.journaled.profile === profile) return;
466
+ await journalIdentity(execution, sources, profile, state);
467
+ }
468
+ /** Shows why the session started without its profile, exactly once. A notice failure never blocks the session. */
469
+ async function deliverProfileWarning(execution, state) {
470
+ const warning = state.warning;
471
+ if (warning === void 0 || state.warned) return;
472
+ state.warned = true;
473
+ try {
474
+ await execution.client.notify({
475
+ level: "warning",
476
+ body: require_profileText.profileWarningText(warning)
477
+ });
478
+ } catch {
479
+ console.warn("[po-profile] Profile notice delivery unavailable.");
480
+ }
532
481
  }
533
- function createProfileServerCommand(host, sources) {
482
+ function createProfileServerCommand(host, state, sources) {
534
483
  return {
535
484
  name: require_profileText.PROFILE_COMMAND,
536
485
  description: "Show or change the active Po profile.",
@@ -559,7 +508,7 @@ function createProfileServerCommand(host, sources) {
559
508
  if ((0, _agimon_ai_po_core_headless.isPoHeadlessPromptAdmissionError)(error)) throw new _agimon_ai_po_core_headless.PoSessionSetupError("Profile integration is unavailable. Restore its credential or choose another profile.");
560
509
  throw error;
561
510
  }
562
- await publishSelectedIdentity(execution, sources, profile);
511
+ await publishSelectedIdentity(execution, sources, profile, state);
563
512
  }
564
513
  };
565
514
  }
@@ -570,17 +519,226 @@ async function assertProfileReady(runtime) {
570
519
  throw new _agimon_ai_po_core_headless.PoHeadlessPromptAdmissionError(error);
571
520
  }
572
521
  }
573
- function createProfileIdentityHook(sources) {
522
+ function createProfileIdentityHook(state, sources) {
574
523
  return {
575
524
  event: "session_start",
576
525
  async handle(_event, execution) {
577
- await publishSelectedIdentity(execution, sources, execution.selection.profile);
526
+ await journalIdentity(execution, sources, execution.selection.profile, state);
527
+ state.started = true;
528
+ await deliverProfileWarning(execution, state);
529
+ }
530
+ };
531
+ }
532
+ //#endregion
533
+ //#region src/extensions/workspaces/sessions/(backend)/_lib/profileSession.ts
534
+ const PROFILE_SESSION_STATE_SERVICE = "po/profile-session-state";
535
+ function profileSessionState(context) {
536
+ let state = context.get(PROFILE_SESSION_STATE_SERVICE, false);
537
+ if (state === void 0) {
538
+ state = {
539
+ started: false,
540
+ warned: false
541
+ };
542
+ context.provide(PROFILE_SESSION_STATE_SERVICE, state);
543
+ }
544
+ return state;
545
+ }
546
+ //#endregion
547
+ //#region src/extensions/workspaces/sessions/(backend)/root.server.ts
548
+ var root_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoot)(({ agent, host, signal, context }) => {
549
+ if (!agent) return { value: void 0 };
550
+ const execution = agent.context;
551
+ const scope = { workspaceId: host.context.workspaceId };
552
+ const state = profileSessionState(context);
553
+ const homeDirectory = execution.environment.HOME ?? _agimon_ai_po_core_platform.nodeHost.homeDirectory();
554
+ const readProfiles = () => (0, _agimon_ai_po_config_profiles.loadProfiles)(execution.repoRoot, homeDirectory);
555
+ const readProfile = (profileName) => require_profileText.findProfile(readProfiles(), require_profileText.readProfileSources(context, scope), profileName);
556
+ const handoff = require_profileText.readInitialProfileOutcome(context);
557
+ let publishOutcome;
558
+ const applyHandoff = (selection, outcome) => {
559
+ state.warning = outcome.warning;
560
+ const name = outcome.resolvedProfile;
561
+ if (name === void 0) return {
562
+ ...selection,
563
+ profile: void 0
564
+ };
565
+ if (require_profileText.mergeProfiles(readProfiles(), require_profileText.readProfileSources(context, scope)).some((profile) => profile.name === name)) return {
566
+ ...selection,
567
+ profile: name
568
+ };
569
+ state.warning = {
570
+ code: "missing",
571
+ requested: name
572
+ };
573
+ return {
574
+ ...selection,
575
+ profile: void 0
576
+ };
577
+ };
578
+ const resolveStartup = async (selection) => {
579
+ const intent = selection.profile === void 0 ? { kind: "unspecified" } : {
580
+ kind: "named",
581
+ name: selection.profile
582
+ };
583
+ const files = await (0, _agimon_ai_po_config_profiles.loadProfilesAsync)((0, _agimon_ai_po_core_platform.requirePoFs)(context), execution.repoRoot, _agimon_ai_po_core_platform.BACKGROUND_CONTEXT, homeDirectory);
584
+ const outcome = await require_profileText.resolveInitialProfile(files, require_profileText.readProfileSources(context, scope), {
585
+ intent,
586
+ scope,
587
+ signal
588
+ });
589
+ state.warning = outcome.warning;
590
+ publishOutcome?.(outcome);
591
+ return {
592
+ ...selection,
593
+ profile: outcome.resolvedProfile
594
+ };
595
+ };
596
+ const unregisterResolver = agent.registerInitialSelectionResolver((selection) => handoff === void 0 ? resolveStartup(selection) : applyHandoff(selection, handoff));
597
+ const runtime = require_profileText.createProfileRuntime({
598
+ readBinding: (profileName) => readProfile(profileName).integration,
599
+ readEnv: (profileName) => readProfile(profileName).env
600
+ });
601
+ const unsubscribe = agent.subscribeSelection(async (selection, applied) => {
602
+ try {
603
+ await runtime.select(selection.profile, { force: applied?.refresh?.includes("profile") === true });
604
+ } catch (error) {
605
+ throw new _agimon_ai_po_core_headless.PoHeadlessPromptAdmissionError(error);
606
+ }
607
+ if (state.started) await publishSelectedIdentity(agent.context, require_profileText.readProfileSources(context, scope), selection.profile, state);
608
+ });
609
+ const invalidate = () => runtime.invalidate();
610
+ signal.addEventListener("abort", invalidate, { once: true });
611
+ if (signal.aborted) runtime.invalidate();
612
+ return {
613
+ value: runtime,
614
+ services: [
615
+ require_profileText.createProfileRuntimePlugin(runtime),
616
+ (serviceContext) => {
617
+ if (handoff !== void 0) return;
618
+ serviceContext.provide(require_profileText.PROFILE_INITIAL_OUTCOME_SERVICE, void 0);
619
+ publishOutcome = (outcome) => serviceContext.set(require_profileText.PROFILE_INITIAL_OUTCOME_SERVICE, outcome);
620
+ },
621
+ (serviceContext) => {
622
+ serviceContext.inject([_agimon_ai_po_core_codemode.PO_CODEMODE_SERVICE, PROFILE_MEMORY_STORE_SERVICE], (injected) => {
623
+ const codemode = (0, _agimon_ai_po_core_codemode.readPoCodemode)(injected);
624
+ if (!codemode) return void 0;
625
+ const registration = codemode.register(PROFILE_MEMORY_NAMESPACE_SOURCE, createProfileMemoryNamespace({
626
+ store: requireProfileMemoryStore(injected),
627
+ runtime,
628
+ sessionId: execution.sessionId,
629
+ assertAvailable: () => {
630
+ if (signal.aborted) throw new Error("Profile memory session is unavailable.");
631
+ }
632
+ }));
633
+ return () => registration.dispose();
634
+ });
635
+ }
636
+ ],
637
+ async onDispose() {
638
+ await (0, _agimon_ai_po_core_extensionFile.runCleanups)([
639
+ unregisterResolver,
640
+ unsubscribe,
641
+ () => signal.removeEventListener("abort", invalidate),
642
+ () => runtime.dispose()
643
+ ], "Profile cleanup failed.");
644
+ }
645
+ };
646
+ });
647
+ //#endregion
648
+ //#region src/services/launchProfiles/index.ts
649
+ /** Name and icon only: the persona, voice, environment and binding of a profile never leave the host. */
650
+ function launchItem(profile, sourceId) {
651
+ const { name, icon } = profile.identity ?? {};
652
+ const identity = {
653
+ ...name === void 0 ? {} : { name },
654
+ ...icon === void 0 ? {} : { icon }
655
+ };
656
+ return {
657
+ name: profile.name,
658
+ ...Object.keys(identity).length === 0 ? {} : { identity },
659
+ sourceId
660
+ };
661
+ }
662
+ /**
663
+ * The profiles a new session in a workspace can start with, for a launcher to offer.
664
+ *
665
+ * Waits for the sources of the workspace under one deadline, then lists what exists: a source that is slow or
666
+ * failed costs `readiness`, never the profiles that are already there. A file profile keeps a name a source also holds.
667
+ */
668
+ async function listLaunchProfiles(input) {
669
+ input.signal.throwIfAborted();
670
+ const { files, sources, scope } = input;
671
+ let readiness = "ready";
672
+ if (sources !== void 0) {
673
+ const deadline = require_profileText.createDeadline(input.signal, input.timeoutMs ?? 1e4);
674
+ try {
675
+ if ((await deadline.within((signal) => sources.ready(scope, signal))).status !== "done") readiness = "unavailable";
676
+ } finally {
677
+ deadline.dispose();
578
678
  }
679
+ }
680
+ const items = /* @__PURE__ */ new Map();
681
+ for (const profile of files) items.set(profile.name, launchItem(profile, require_profileText.FILE_PROFILE_SOURCE_ID));
682
+ for (const { sourceId, profile } of sources?.listSourced(scope) ?? []) if (!items.has(profile.name)) items.set(profile.name, launchItem(profile, sourceId));
683
+ return {
684
+ profiles: [...items.values()].sort((left, right) => left.name.localeCompare(right.name)),
685
+ readiness
579
686
  };
580
687
  }
581
688
  //#endregion
689
+ //#region src/extensions/workspaces/(backend)/api/profile/route.server.ts
690
+ const LAUNCH_PROFILES_PATH = "/launch-profiles";
691
+ /** What a launcher may offer before any session exists: names and display data only. */
692
+ var route_server_default$1 = (0, _agimon_ai_po_core_extensionFile.defineRoute)(({ context, signal }) => ({
693
+ basePath: "profile",
694
+ start: (api) => ({
695
+ async fetch(request) {
696
+ if (new URL(request.url).pathname !== LAUNCH_PROFILES_PATH) return Response.json({ error: "Not found" }, { status: 404 });
697
+ if (request.method !== "GET") return Response.json({ error: "Method not allowed" }, {
698
+ status: 405,
699
+ headers: { Allow: "GET" }
700
+ });
701
+ const { workspaceId, workspaceRoot } = api;
702
+ if (workspaceId === void 0 || workspaceRoot === void 0) return Response.json({ error: "Workspace unavailable" }, { status: 404 });
703
+ let files;
704
+ try {
705
+ files = (0, _agimon_ai_po_config_profiles.loadProfiles)(workspaceRoot, api.homeDirectory ?? api.environment?.HOME ?? _agimon_ai_po_core_platform.nodeHost.homeDirectory());
706
+ } catch {
707
+ return Response.json({ error: "Profile configuration is unavailable" }, { status: 500 });
708
+ }
709
+ const scope = { workspaceId };
710
+ const catalog = await listLaunchProfiles({
711
+ files,
712
+ sources: require_profileText.readProfileSources(context, scope),
713
+ scope,
714
+ signal: AbortSignal.any([request.signal, signal])
715
+ });
716
+ return Response.json(catalog);
717
+ },
718
+ close() {}
719
+ })
720
+ }));
721
+ //#endregion
722
+ //#region src/extensions/workspaces/sessions/(backend)/api/profile/route.server.ts
723
+ var route_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoute)(({ agent }) => ({
724
+ basePath: "profile",
725
+ start: () => ({
726
+ fetch(request) {
727
+ if (new URL(request.url).pathname !== "/current") return Response.json({ error: "Not found" }, { status: 404 });
728
+ if (request.method !== "GET") return Response.json({ error: "Method not allowed" }, {
729
+ status: 405,
730
+ headers: { Allow: "GET" }
731
+ });
732
+ if (!agent) return Response.json({ error: "Session agent unavailable" }, { status: 404 });
733
+ const selection = agent.context.selection;
734
+ return Response.json({ profile: selection.profile ?? null });
735
+ },
736
+ close() {}
737
+ })
738
+ }));
739
+ //#endregion
582
740
  //#region src/extensions/workspaces/sessions/(backend)/command/profile.server.ts
583
- var profile_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoutedContribution)(({ agent, host, context }) => agent ? createProfileServerCommand(agent, require_profileText.readProfileSources(context, { workspaceId: host.context.workspaceId })) : void 0, { cardinality: "optional" });
741
+ var profile_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoutedContribution)(({ agent, host, context }) => agent ? createProfileServerCommand(agent, profileSessionState(context), require_profileText.readProfileSources(context, { workspaceId: host.context.workspaceId })) : void 0, { cardinality: "optional" });
584
742
  //#endregion
585
743
  //#region src/services/profileMemoryExtraction/index.ts
586
744
  const ROOT_CURSOR = "root";
@@ -732,7 +890,7 @@ var beforeAgentStart_server_default = (0, _agimon_ai_po_core_extensionFile.defin
732
890
  //#endregion
733
891
  //#region src/extensions/workspaces/sessions/(backend)/hook/sessionStart.server.ts
734
892
  var sessionStart_server_default = (0, _agimon_ai_po_core_extensionFile.defineHook)(({ root, host, context }) => {
735
- const identityHook = createProfileIdentityHook(require_profileText.readProfileSources(context, { workspaceId: host.context.workspaceId }));
893
+ const identityHook = createProfileIdentityHook(profileSessionState(context), require_profileText.readProfileSources(context, { workspaceId: host.context.workspaceId }));
736
894
  return {
737
895
  ...identityHook,
738
896
  async handle(event, execution) {
@@ -800,8 +958,15 @@ const serverPlugin = (0, _agimon_ai_po_core_serverPlugin.defineServerPlugin)({
800
958
  },
801
959
  workspace: async (context) => {
802
960
  const scopeGlobal = await context.scopeRoot("global", root_server_default$1, context);
961
+ const contextGlobal = {
962
+ ...context,
963
+ root: scopeGlobal.value
964
+ };
803
965
  return {
804
966
  ...(0, _agimon_ai_po_core_extensionFile.composeRootHooks)(scopeGlobal),
967
+ get api() {
968
+ return [at(route_server_default$1, contextGlobal)];
969
+ },
805
970
  services: [...scopeGlobal.services ?? []]
806
971
  };
807
972
  },