{"version":3,"file":"pi.cjs","names":["createAuthorCatalogMonitor","authorMinorMode","AUTHOR_PACKAGE_SOURCE","authorToolRestriction","defineRoot","createAuthorCatalog","DOOM_HELP_SERVICE","requireDoomHelpService","AUTHOR_PACKAGE_SOURCE","DOOM_TOOL_SURFACE_SERVICE","requireDoomToolSurface","piMinorModes","defineCliCommand","createAuthorCommand","defineCliHook","AUTHOR_PI_GUIDANCE","defineCliHook","defineTool","createAuthorTools","AUTHOR_TOOL_WHEN","defineTool","createAuthorTools","AUTHOR_TOOL_WHEN","defineTool","createAuthorTools","AUTHOR_TOOL_WHEN","definePiExtension","rootSession","composeRootHooks","commandAuthor","hookBeforeAgentStart","hookSessionStart","piToolContributions","toolDescribeAuthorTools","toolOpenAuthoringFile","toolUseAuthorTools"],"sources":["../../src/extensions/workspaces/sessions/(backend)/_lib/authorPiMode.ts","../../src/extensions/workspaces/sessions/(backend)/root.cli.ts","../../src/extensions/workspaces/sessions/(backend)/command/author.cli.ts","../../src/extensions/workspaces/sessions/(backend)/hook/before-agent-start.cli.ts","../../src/extensions/workspaces/sessions/(backend)/hook/session-start.cli.ts","../../src/extensions/workspaces/sessions/(backend)/tool/describe-author-tools.cli.ts","../../src/extensions/workspaces/sessions/(backend)/tool/open-authoring-file.cli.ts","../../src/extensions/workspaces/sessions/(backend)/tool/use-author-tools.cli.ts","../../generated/pi.ts"],"sourcesContent":["import type { PiToolRestriction } from '@agimon-ai/doompi-core/piExtension';\n\nimport { AUTHOR_PACKAGE_SOURCE } from '../../../../../constants/author';\nimport { authorMinorMode } from '../../../../../models/authorMode';\nimport { authorToolRestriction, createAuthorCatalogMonitor } from '../../../../../services/authorCatalog/monitor';\nimport type { AuthorCatalog } from '../../../../../services/authorCatalog/type';\n\nexport interface AuthorPiMode {\n  readonly mode: ReturnType<typeof authorMinorMode.createOwner>;\n  readonly restriction: PiToolRestriction;\n  isActive(): boolean;\n  assertAvailable(this: void): void;\n  onStart(this: void): void;\n  onStop(this: void): void;\n  onDispose(this: void): void;\n}\n\n/** Own Author's viewport polling independently from host registration. */\nexport function createAuthorPiMode(catalog: AuthorCatalog, signal: AbortSignal): AuthorPiMode {\n  const monitor = createAuthorCatalogMonitor(catalog, {\n    schedule(callback, delayMs) {\n      const timer = setTimeout(callback, delayMs);\n      timer.unref?.();\n      return () => clearTimeout(timer);\n    },\n  });\n  let active = false;\n  let started = false;\n  let unsubscribe: (() => void) | undefined;\n  const listeners = new Set<() => void>();\n  const publish = () => {\n    mode.publish();\n    listeners.forEach((listener) => listener());\n  };\n  const mode = authorMinorMode.createOwner({\n    isActive: () => active,\n    detail: () => (monitor.snapshot()?.canvases?.length ? 'Author canvases available' : 'open a document canvas'),\n    setActive(enabled) {\n      signal.throwIfAborted();\n      if (active === enabled) return;\n      active = enabled;\n      if (active && started) monitor.start();\n      else monitor.stop();\n      publish();\n    },\n  });\n  const restriction: PiToolRestriction = {\n    source: AUTHOR_PACKAGE_SOURCE,\n    restrict: (incoming, context) => authorToolRestriction(active, !!monitor.snapshot())(incoming, context),\n    subscribe(listener) {\n      listeners.add(listener);\n      return () => {\n        listeners.delete(listener);\n      };\n    },\n  };\n  return {\n    mode,\n    restriction,\n    isActive: () => active,\n    assertAvailable() {\n      if (signal.aborted) throw new Error('The Author runtime is disposed.');\n      if (!active) throw new Error('Author mode is not active.');\n    },\n    onStart() {\n      started = true;\n      unsubscribe = monitor.subscribe(publish);\n      if (active) monitor.start();\n    },\n    onStop() {\n      started = false;\n      active = false;\n      unsubscribe?.();\n      unsubscribe = undefined;\n      monitor.stop();\n    },\n    onDispose() {\n      monitor.dispose();\n      listeners.clear();\n    },\n  };\n}\n","import { defineRoot } from '@agimon-ai/doompi-core/extensionFile';\nimport { DOOM_HELP_SERVICE, requireDoomHelpService } from '@agimon-ai/doompi-core/help';\nimport type { PiPluginContext } from '@agimon-ai/doompi-core/piExtension';\nimport { DOOM_TOOL_SURFACE_SERVICE, requireDoomToolSurface } from '@agimon-ai/doompi-core/toolSurface';\nimport { piMinorModes } from '@agimon-ai/doompi-minor-mode';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport { AUTHOR_PACKAGE_SOURCE } from '../../../../constants/author';\nimport { createAuthorCatalog } from '../../../../services/authorCatalog';\nimport type { AuthorExtensionDependencies } from '../../../../types/extension';\nimport { createAuthorPiMode } from './_lib/authorPiMode';\n\nexport default defineRoot((context: PiPluginContext<Partial<AuthorExtensionDependencies>>) => {\n  const catalog = context.options?.catalog ?? createAuthorCatalog();\n  const mode = createAuthorPiMode(catalog, context.signal);\n  const registrations = (cordis: Context): void => {\n    cordis.inject([DOOM_HELP_SERVICE], (child) => {\n      const handle = requireDoomHelpService(child).register({\n        source: AUTHOR_PACKAGE_SOURCE,\n        moduleUrl: import.meta.url,\n        skills: [\n          {\n            name: 'doompi-use-author',\n            description:\n              'Use @agimon-ai/doompi-author: Visual steering workspace for focused document review and bounded authoring',\n          },\n        ],\n      });\n      child.effect(() => () => handle.dispose());\n    });\n    cordis.inject([DOOM_TOOL_SURFACE_SERVICE], (child) => {\n      const surface = requireDoomToolSurface(child);\n      const handle = surface.register(mode.restriction);\n      child.effect(() => () => handle.dispose());\n      child.effect(() =>\n        mode.restriction.subscribe\n          ? mode.restriction.subscribe(() => handle.update(mode.restriction.restrict))\n          : () => undefined,\n      );\n    });\n  };\n\n  return {\n    value: {\n      catalog,\n      assertAvailable: mode.assertAvailable,\n      mode,\n      service: context.options?.service,\n    },\n    services: [piMinorModes([mode.mode]), registrations],\n    onStart: mode.onStart,\n    onStop: mode.onStop,\n    onDispose: mode.onDispose,\n  };\n});\n","import { defineCliCommand, type WithRoot } from '@agimon-ai/doompi-core/extensionFile';\n\nimport { createAuthorCommand } from '../../../../../services/authorCommand';\nimport type { AuthorExtensionService } from '../../../../../types/extension';\n\n// The terminal takes the command as a native Pi declaration, so this half names\n// itself through createAuthorCommand rather than through the generated entry.\nexport default defineCliCommand((context: WithRoot<unknown, { readonly service?: AuthorExtensionService }>) =>\n  createAuthorCommand(context.root.service),\n);\n","import { defineCliHook, type WithRoot } from '@agimon-ai/doompi-core/extensionFile';\nimport type { PiPluginContext } from '@agimon-ai/doompi-core/piExtension';\n\nimport { AUTHOR_PI_GUIDANCE } from '../../../../../constants/author';\nimport type { AuthorExtensionDependencies } from '../../../../../types/extension';\ntype AuthorPiScope = Awaited<ReturnType<typeof import('../root.cli').default>>['value'];\n\nexport default defineCliHook(\n  (context: WithRoot<PiPluginContext<Partial<AuthorExtensionDependencies>>, AuthorPiScope>) =>\n    (event: { systemPrompt: string }) =>\n      context.root.mode.isActive() ? { systemPrompt: `${event.systemPrompt}\\n\\n${AUTHOR_PI_GUIDANCE}` } : undefined,\n);\n","import { defineCliHook, type WithRoot } from '@agimon-ai/doompi-core/extensionFile';\nimport type { PiPluginContext } from '@agimon-ai/doompi-core/piExtension';\n\nimport type { AuthorExtensionDependencies } from '../../../../../types/extension';\ntype AuthorPiScope = Awaited<ReturnType<typeof import('../root.cli').default>>['value'];\n\nexport default defineCliHook(\n  (context: WithRoot<PiPluginContext<Partial<AuthorExtensionDependencies>>, AuthorPiScope>) => () =>\n    context.root.mode.mode.publish(),\n);\n","import { defineTool, type WithRoot } from '@agimon-ai/doompi-core/extensionFile';\n\nimport { AUTHOR_TOOL_WHEN, createAuthorTools, type AuthorToolRoot } from '../../../../../services/authorTools';\n\nexport default defineTool((context: WithRoot<unknown, AuthorToolRoot>) => ({\n  ...createAuthorTools(context.root.catalog, context.root.assertAvailable)[1]!,\n  when: AUTHOR_TOOL_WHEN,\n}));\n","import { defineTool, type WithRoot } from '@agimon-ai/doompi-core/extensionFile';\n\nimport { AUTHOR_TOOL_WHEN, createAuthorTools, type AuthorToolRoot } from '../../../../../services/authorTools';\n\nexport default defineTool((context: WithRoot<unknown, AuthorToolRoot>) => ({\n  ...createAuthorTools(context.root.catalog, context.root.assertAvailable)[0]!,\n  when: AUTHOR_TOOL_WHEN,\n}));\n","import { defineTool, type WithRoot } from '@agimon-ai/doompi-core/extensionFile';\n\nimport { AUTHOR_TOOL_WHEN, createAuthorTools, type AuthorToolRoot } from '../../../../../services/authorTools';\n\nexport default defineTool((context: WithRoot<unknown, AuthorToolRoot>) => ({\n  ...createAuthorTools(context.root.catalog, context.root.assertAvailable)[2]!,\n  when: AUTHOR_TOOL_WHEN,\n}));\n","// Generated by @agimon-ai/doompi-build. Do not edit by hand.\nimport { definePiExtension, piToolContributions, type PiPluginContext, type PiPluginContributions } from '@agimon-ai/doompi-core/piExtension';\nimport { composeRootHooks } from '@agimon-ai/doompi-core/extensionFile';\n\nimport rootSession from '../src/extensions/workspaces/sessions/(backend)/root.cli';\nimport commandAuthor from '../src/extensions/workspaces/sessions/(backend)/command/author.cli';\nimport hookBeforeAgentStart from '../src/extensions/workspaces/sessions/(backend)/hook/before-agent-start.cli';\nimport hookSessionStart from '../src/extensions/workspaces/sessions/(backend)/hook/session-start.cli';\nimport toolDescribeAuthorTools from '../src/extensions/workspaces/sessions/(backend)/tool/describe-author-tools.cli';\nimport toolOpenAuthoringFile from '../src/extensions/workspaces/sessions/(backend)/tool/open-authoring-file.cli';\nimport toolUseAuthorTools from '../src/extensions/workspaces/sessions/(backend)/tool/use-author-tools.cli';\n\ntype OptionsOf<T> = T extends (context: PiPluginContext<infer Options>) => unknown ? Options : never;\ntype InferredOptions = Exclude<OptionsOf<typeof rootSession> | OptionsOf<typeof commandAuthor> | OptionsOf<typeof hookBeforeAgentStart> | OptionsOf<typeof hookSessionStart> | OptionsOf<typeof toolDescribeAuthorTools> | OptionsOf<typeof toolOpenAuthoringFile> | OptionsOf<typeof toolUseAuthorTools>, undefined>;\ntype Intersect<Union> =\n  (Union extends unknown ? (value: Union) => void : never) extends (value: infer Value) => void ? Value : never;\ntype ExtensionOptions = [InferredOptions] extends [never] ? undefined : Intersect<InferredOptions>;\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n  typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\nconst via = <T>(identity: Record<string, unknown>, value: unknown): T =>\n  (value === undefined ? undefined : { ...identity, ...(value as object) }) as T;\n\nexport const extension = definePiExtension<ExtensionOptions>('@agimon-ai/doompi-author', async (context) => {\n  const scopeSession = await rootSession(context);\n  const contextSession = { ...context, root: scopeSession.value };\n  return {\n    ...composeRootHooks(scopeSession),\n    get commands(): PiPluginContributions['commands'] { return [at(commandAuthor, contextSession)]; },\n    events: {\n      before_agent_start: at(hookBeforeAgentStart, contextSession) as NonNullable<PiPluginContributions['events']>['before_agent_start'],\n      session_start: at(hookSessionStart, contextSession) as NonNullable<PiPluginContributions['events']>['session_start'],\n    },\n    ...piToolContributions('@agimon-ai/doompi-author', [via({ name: 'describe_author_tools' }, at(toolDescribeAuthorTools, contextSession)), via({ name: 'open_authoring_file' }, at(toolOpenAuthoringFile, contextSession)), via({ name: 'use_author_tools' }, at(toolUseAuthorTools, contextSession))]),\n    services: [...(scopeSession.services ?? [])],\n  };\n});\n\nexport default extension;\n"],"mappings":";;;;;;;;;;;;;AAkBA,SAAgB,mBAAmB,SAAwB,QAAmC;CAC5F,MAAM,UAAUA,gBAAAA,2BAA2B,SAAS,EAClD,SAAS,UAAU,SAAS;EAC1B,MAAM,QAAQ,WAAW,UAAU,OAAO;EAC1C,MAAM,QAAQ;EACd,aAAa,aAAa,KAAK;CACjC,EACF,CAAC;CACD,IAAI,SAAS;CACb,IAAI,UAAU;CACd,IAAI;CACJ,MAAM,4BAAY,IAAI,IAAgB;CACtC,MAAM,gBAAgB;EACpB,KAAK,QAAQ;EACb,UAAU,SAAS,aAAa,SAAS,CAAC;CAC5C;CACA,MAAM,OAAOC,sBAAAA,gBAAgB,YAAY;EACvC,gBAAgB;EAChB,cAAe,QAAQ,SAAS,CAAC,EAAE,UAAU,SAAS,8BAA8B;EACpF,UAAU,SAAS;GACjB,OAAO,eAAe;GACtB,IAAI,WAAW,SAAS;GACxB,SAAS;GACT,IAAI,UAAU,SAAS,QAAQ,MAAM;QAChC,QAAQ,KAAK;GAClB,QAAQ;E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