larkin 0.4.25 → 0.4.27

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.
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.piDistributionLabel = piDistributionLabel;
4
+ function piDistributionLabel(distribution) {
5
+ return distribution === "builtin" ? "内置 Pi" : "用户安装的 Pi";
6
+ }
@@ -0,0 +1,3 @@
1
+ export function piDistributionLabel(distribution) {
2
+ return distribution === "builtin" ? "内置 Pi" : "用户安装的 Pi";
3
+ }
@@ -3,19 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PI_PROVIDER_PRESETS = exports.BUNDLED_PI_VERSION = void 0;
6
+ exports.PI_PROVIDER_PRESETS = exports.BUNDLED_PI_VERSION = exports.piDistributionLabel = void 0;
7
7
  exports.validatePiBaseUrl = validatePiBaseUrl;
8
8
  exports.listProviderModels = listProviderModels;
9
9
  exports.resolveBuiltinPiProviderSetupSelection = resolveBuiltinPiProviderSetupSelection;
10
10
  exports.validateBuiltinPiProviderSelection = validateBuiltinPiProviderSelection;
11
11
  exports.piAgentDirectory = piAgentDirectory;
12
+ exports.ownedPiCatalogAgentDir = ownedPiCatalogAgentDir;
13
+ exports.piCatalogCommandSpec = piCatalogCommandSpec;
12
14
  exports.assertBuiltinPiAgentDirectory = assertBuiltinPiAgentDirectory;
13
15
  exports.configureBuiltinPiProviderModel = configureBuiltinPiProviderModel;
14
16
  exports.stageBuiltinPiProvider = stageBuiltinPiProvider;
15
17
  const node_crypto_1 = __importDefault(require("node:crypto"));
16
18
  const node_fs_1 = __importDefault(require("node:fs"));
17
19
  const node_path_1 = __importDefault(require("node:path"));
20
+ const internal_command_js_1 = require("../app/internal-command.cjs");
18
21
  const secure_metadata_js_1 = require("../platform/secure-metadata.cjs");
22
+ var pi_distribution_label_js_1 = require("./pi-distribution-label.cjs");
23
+ Object.defineProperty(exports, "piDistributionLabel", { enumerable: true, get: function () { return pi_distribution_label_js_1.piDistributionLabel; } });
19
24
  exports.BUNDLED_PI_VERSION = "0.84.2";
20
25
  // These values mirror the catalog shipped by the pinned official Pi distribution.
21
26
  // Keeping the user-facing defaults here makes endpoint changes reviewable in Larkin.
@@ -137,6 +142,20 @@ function piAgentDirectory(configDir, agentId) {
137
142
  throw new Error("Pi Agent ID 格式无效");
138
143
  return node_path_1.default.join(node_path_1.default.resolve(configDir), "providers", "pi", agentId);
139
144
  }
145
+ /** Catalog/CLI/dashboard must use the Agent-owned provider dir, never host ~/.pi. */
146
+ function ownedPiCatalogAgentDir(configDir, agentId) {
147
+ return piAgentDirectory(configDir, agentId);
148
+ }
149
+ function piCatalogCommandSpec(distribution, env = process.env) {
150
+ if (distribution === "builtin") {
151
+ const spec = (0, internal_command_js_1.internalCommandSpec)("pi-rpc", [], env);
152
+ return { command: spec.command, commandArgs: spec.args };
153
+ }
154
+ return {
155
+ command: env.LARKIN_PI_COMMAND ?? process.env.LARKIN_PI_COMMAND ?? "pi",
156
+ commandArgs: [],
157
+ };
158
+ }
140
159
  function assertPrivateDirectory(directory) {
141
160
  if (secure_metadata_js_1.isWindows) {
142
161
  // Windows 无 POSIX 权限位:icacls 收紧为「当前用户 + SYSTEM」并回读校验。
@@ -1,7 +1,9 @@
1
1
  import crypto from "node:crypto";
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
+ import { internalCommandSpec } from "../app/internal-command.mjs";
4
5
  import { isWindows, secureWindowsDirectoryAcl } from "../platform/secure-metadata.mjs";
6
+ export { piDistributionLabel } from "./pi-distribution-label.mjs";
5
7
  export const BUNDLED_PI_VERSION = "0.84.2";
6
8
  // These values mirror the catalog shipped by the pinned official Pi distribution.
7
9
  // Keeping the user-facing defaults here makes endpoint changes reviewable in Larkin.
@@ -123,6 +125,20 @@ export function piAgentDirectory(configDir, agentId) {
123
125
  throw new Error("Pi Agent ID 格式无效");
124
126
  return path.join(path.resolve(configDir), "providers", "pi", agentId);
125
127
  }
128
+ /** Catalog/CLI/dashboard must use the Agent-owned provider dir, never host ~/.pi. */
129
+ export function ownedPiCatalogAgentDir(configDir, agentId) {
130
+ return piAgentDirectory(configDir, agentId);
131
+ }
132
+ export function piCatalogCommandSpec(distribution, env = process.env) {
133
+ if (distribution === "builtin") {
134
+ const spec = internalCommandSpec("pi-rpc", [], env);
135
+ return { command: spec.command, commandArgs: spec.args };
136
+ }
137
+ return {
138
+ command: env.LARKIN_PI_COMMAND ?? process.env.LARKIN_PI_COMMAND ?? "pi",
139
+ commandArgs: [],
140
+ };
141
+ }
126
142
  function assertPrivateDirectory(directory) {
127
143
  if (isWindows) {
128
144
  // Windows 无 POSIX 权限位:icacls 收紧为「当前用户 + SYSTEM」并回读校验。
@@ -42,8 +42,10 @@ exports.resolveRuntimeExecutable = resolveRuntimeExecutable;
42
42
  exports.classifyRuntimePrerequisite = classifyRuntimePrerequisite;
43
43
  exports.probeNativeRuntimeReadiness = probeNativeRuntimeReadiness;
44
44
  const node_fs_1 = __importDefault(require("node:fs"));
45
+ const node_os_1 = __importDefault(require("node:os"));
45
46
  const node_path_1 = __importDefault(require("node:path"));
46
47
  const node_child_process_1 = require("node:child_process");
48
+ const root_layout_js_1 = require("../platform/root-layout.cjs");
47
49
  const builtin_pi_assets_js_1 = require("./builtin-pi-assets.cjs");
48
50
  const pi_provider_config_js_1 = require("./pi-provider-config.cjs");
49
51
  const process_boundary_trace_js_1 = require("../platform/process-boundary-trace.cjs");
@@ -162,11 +164,27 @@ async function probeNativeRuntimeReadiness(options) {
162
164
  ? "Install Pi and ensure `pi` is on PATH, or set LARKIN_PI_COMMAND."
163
165
  : `Install ${options.runtime} and ensure it is on PATH.`,
164
166
  };
167
+ const piAgentId = options.agentId;
168
+ if (options.runtime === "pi" && !piAgentId) {
169
+ return {
170
+ runtime: "pi",
171
+ state: "unavailable",
172
+ executable,
173
+ reason: "Pi catalog readiness requires Agent ID",
174
+ nextAction: "Retry setup or start so Larkin can probe the Agent-owned Pi provider directory.",
175
+ };
176
+ }
165
177
  const version = executableVersion(executable, env, options.commandArgs);
166
178
  try {
167
179
  if (options.runtime === "pi") {
168
180
  const { discoverPiModelCatalog } = await Promise.resolve().then(() => __importStar(require("./pi-model-catalog.cjs")));
169
- await discoverPiModelCatalog({ cwd: options.cwd, command: executable, commandArgs: options.commandArgs, env });
181
+ await discoverPiModelCatalog({
182
+ cwd: options.cwd,
183
+ command: executable,
184
+ commandArgs: options.commandArgs,
185
+ env,
186
+ agentDir: (0, pi_provider_config_js_1.ownedPiCatalogAgentDir)((0, root_layout_js_1.resolveConfigDir)(env, node_os_1.default.homedir()), piAgentId),
187
+ });
170
188
  }
171
189
  else if (options.runtime === "codex") {
172
190
  const { discoverCodexModelCatalog } = await Promise.resolve().then(() => __importStar(require("./codex-model-catalog.cjs")));
@@ -1,8 +1,10 @@
1
1
  import fs from "node:fs";
2
+ import os from "node:os";
2
3
  import path from "node:path";
3
4
  import { spawnSync } from "node:child_process";
5
+ import { resolveConfigDir as resolveRootConfigDir } from "../platform/root-layout.mjs";
4
6
  import { applyPiPackageDirForChild, piChildDistributionFromOverrides } from "./builtin-pi-assets.mjs";
5
- import { assertBuiltinPiAgentDirectory, BUNDLED_PI_VERSION, piAgentDirectory } from "./pi-provider-config.mjs";
7
+ import { assertBuiltinPiAgentDirectory, BUNDLED_PI_VERSION, ownedPiCatalogAgentDir, piAgentDirectory } from "./pi-provider-config.mjs";
6
8
  import { traceProcessBoundary } from "../platform/process-boundary-trace.mjs";
7
9
  function safeProviderLabel(value) {
8
10
  const provider = typeof value === "string" ? value.trim() : "";
@@ -118,11 +120,27 @@ export async function probeNativeRuntimeReadiness(options) {
118
120
  ? "Install Pi and ensure `pi` is on PATH, or set LARKIN_PI_COMMAND."
119
121
  : `Install ${options.runtime} and ensure it is on PATH.`,
120
122
  };
123
+ const piAgentId = options.agentId;
124
+ if (options.runtime === "pi" && !piAgentId) {
125
+ return {
126
+ runtime: "pi",
127
+ state: "unavailable",
128
+ executable,
129
+ reason: "Pi catalog readiness requires Agent ID",
130
+ nextAction: "Retry setup or start so Larkin can probe the Agent-owned Pi provider directory.",
131
+ };
132
+ }
121
133
  const version = executableVersion(executable, env, options.commandArgs);
122
134
  try {
123
135
  if (options.runtime === "pi") {
124
136
  const { discoverPiModelCatalog } = await import("./pi-model-catalog.mjs");
125
- await discoverPiModelCatalog({ cwd: options.cwd, command: executable, commandArgs: options.commandArgs, env });
137
+ await discoverPiModelCatalog({
138
+ cwd: options.cwd,
139
+ command: executable,
140
+ commandArgs: options.commandArgs,
141
+ env,
142
+ agentDir: ownedPiCatalogAgentDir(resolveRootConfigDir(env, os.homedir()), piAgentId),
143
+ });
126
144
  }
127
145
  else if (options.runtime === "codex") {
128
146
  const { discoverCodexModelCatalog } = await import("./codex-model-catalog.mjs");
@@ -666,7 +666,8 @@ Lark 必须用 --tenant lark:授权二维码是官方 /page/cli(begin 仍走
666
666
  const choice = injectedAgentChoice
667
667
  ? requested
668
668
  : await recoverUnavailableExternalPi(requested, questioner, () => probeNativeRuntimeReadiness({
669
- runtime: "pi", agentId: id, cwd: path.join(CFG_DIR, "agents", id), env: process.env,
669
+ runtime: "pi", agentId: id, cwd: path.join(CFG_DIR, "agents", id),
670
+ env: { ...process.env, LARKIN_CONFIG_DIR: CFG_DIR, LARKIN_PI_DISTRIBUTION: "external" },
670
671
  }), (message) => say(`! ${message}`), authServices);
671
672
  if (choice) {
672
673
  let serializedChoice = choice;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "larkin",
3
- "version": "0.4.25",
3
+ "version": "0.4.27",
4
4
  "private": false,
5
5
  "larkinPackageRole": "npm-published",
6
6
  "files": [