Compare commits
2 Commits
410ada409c
...
fix/pi-tok
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37d3b6e425 | ||
|
|
3ff3f20b70 |
@@ -58,6 +58,8 @@ mosaic yolo pi # Pi in yolo mode
|
|||||||
|
|
||||||
The launcher verifies your config, checks for `SOUL.md`, injects your `AGENTS.md` standards into the runtime, and forwards all arguments.
|
The launcher verifies your config, checks for `SOUL.md`, injects your `AGENTS.md` standards into the runtime, and forwards all arguments.
|
||||||
|
|
||||||
|
Pi launches default to a token-lean skill posture: `mosaic pi` passes `--no-skills` so Pi does not preload every global skill description into the system prompt. Use `MOSAIC_PI_SKILL_MODE=all mosaic pi` for the legacy all-skills catalog, or `MOSAIC_PI_SKILL_MODE=discover mosaic pi` to let Pi use its native settings/project skill discovery.
|
||||||
|
|
||||||
### TUI & Gateway
|
### TUI & Gateway
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -52,20 +52,6 @@ _mosaic_sync_woodpecker_env() {
|
|||||||
printf '%s\n' "$expected" > "$env_file"
|
printf '%s\n' "$expected" > "$env_file"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Load legacy flat Woodpecker credentials (.woodpecker.url / .woodpecker.token).
|
|
||||||
# Some environments export WOODPECKER_INSTANCE=mosaic, but the current
|
|
||||||
# credentials.json may still use the legacy flat schema. Treat "mosaic" as the
|
|
||||||
# default flat instance when a nested .woodpecker.mosaic object is absent.
|
|
||||||
_mosaic_load_woodpecker_legacy() {
|
|
||||||
export WOODPECKER_URL="$(_mosaic_read_cred '.woodpecker.url')"
|
|
||||||
export WOODPECKER_TOKEN="$(_mosaic_read_cred '.woodpecker.token')"
|
|
||||||
export WOODPECKER_INSTANCE="${WOODPECKER_INSTANCE:-mosaic}"
|
|
||||||
WOODPECKER_URL="${WOODPECKER_URL%/}"
|
|
||||||
[[ -n "$WOODPECKER_URL" ]] || { echo "Error: woodpecker.url not found" >&2; return 1; }
|
|
||||||
[[ -n "$WOODPECKER_TOKEN" ]] || { echo "Error: woodpecker.token not found" >&2; return 1; }
|
|
||||||
_mosaic_sync_woodpecker_env "$WOODPECKER_INSTANCE" "$WOODPECKER_URL" "$WOODPECKER_TOKEN"
|
|
||||||
}
|
|
||||||
|
|
||||||
load_credentials() {
|
load_credentials() {
|
||||||
local service="$1"
|
local service="$1"
|
||||||
|
|
||||||
@@ -169,14 +155,7 @@ EOF
|
|||||||
;;
|
;;
|
||||||
woodpecker-*)
|
woodpecker-*)
|
||||||
local wp_instance="${service#woodpecker-}"
|
local wp_instance="${service#woodpecker-}"
|
||||||
# credentials.json is authoritative — always read from it, ignore env.
|
# credentials.json is authoritative — always read from it, ignore env
|
||||||
# Backward compatibility: the default Mosaic Woodpecker instance may be
|
|
||||||
# stored in the legacy flat schema (.woodpecker.url/.token) instead of
|
|
||||||
# .woodpecker.mosaic.url/.token.
|
|
||||||
if [[ "$wp_instance" == "mosaic" ]] && [[ -z "$(_mosaic_read_cred '.woodpecker.mosaic.url')" ]] && [[ -n "$(_mosaic_read_cred '.woodpecker.url')" ]]; then
|
|
||||||
WOODPECKER_INSTANCE="mosaic" _mosaic_load_woodpecker_legacy
|
|
||||||
return $?
|
|
||||||
fi
|
|
||||||
export WOODPECKER_URL="$(_mosaic_read_cred ".woodpecker.${wp_instance}.url")"
|
export WOODPECKER_URL="$(_mosaic_read_cred ".woodpecker.${wp_instance}.url")"
|
||||||
export WOODPECKER_TOKEN="$(_mosaic_read_cred ".woodpecker.${wp_instance}.token")"
|
export WOODPECKER_TOKEN="$(_mosaic_read_cred ".woodpecker.${wp_instance}.token")"
|
||||||
export WOODPECKER_INSTANCE="$wp_instance"
|
export WOODPECKER_INSTANCE="$wp_instance"
|
||||||
@@ -187,10 +166,7 @@ EOF
|
|||||||
_mosaic_sync_woodpecker_env "$wp_instance" "$WOODPECKER_URL" "$WOODPECKER_TOKEN"
|
_mosaic_sync_woodpecker_env "$wp_instance" "$WOODPECKER_URL" "$WOODPECKER_TOKEN"
|
||||||
;;
|
;;
|
||||||
woodpecker)
|
woodpecker)
|
||||||
# Resolve default instance, then load it. If WOODPECKER_INSTANCE is set to
|
# Resolve default instance, then load it
|
||||||
# "mosaic" by a shell/profile but credentials.json still uses the legacy
|
|
||||||
# flat .woodpecker.url/.token schema, load the flat credentials instead of
|
|
||||||
# failing with "woodpecker.mosaic.url not found".
|
|
||||||
local wp_default
|
local wp_default
|
||||||
wp_default="${WOODPECKER_INSTANCE:-$(_mosaic_read_cred '.woodpecker.default')}"
|
wp_default="${WOODPECKER_INSTANCE:-$(_mosaic_read_cred '.woodpecker.default')}"
|
||||||
if [[ -z "$wp_default" ]]; then
|
if [[ -z "$wp_default" ]]; then
|
||||||
@@ -198,18 +174,18 @@ EOF
|
|||||||
local legacy_url
|
local legacy_url
|
||||||
legacy_url="$(_mosaic_read_cred '.woodpecker.url')"
|
legacy_url="$(_mosaic_read_cred '.woodpecker.url')"
|
||||||
if [[ -n "$legacy_url" ]]; then
|
if [[ -n "$legacy_url" ]]; then
|
||||||
_mosaic_load_woodpecker_legacy
|
export WOODPECKER_URL="${WOODPECKER_URL:-$legacy_url}"
|
||||||
|
export WOODPECKER_TOKEN="${WOODPECKER_TOKEN:-$(_mosaic_read_cred '.woodpecker.token')}"
|
||||||
|
WOODPECKER_URL="${WOODPECKER_URL%/}"
|
||||||
|
[[ -n "$WOODPECKER_URL" ]] || { echo "Error: woodpecker.url not found" >&2; return 1; }
|
||||||
|
[[ -n "$WOODPECKER_TOKEN" ]] || { echo "Error: woodpecker.token not found" >&2; return 1; }
|
||||||
else
|
else
|
||||||
echo "Error: woodpecker.default not set and no WOODPECKER_INSTANCE env var" >&2
|
echo "Error: woodpecker.default not set and no WOODPECKER_INSTANCE env var" >&2
|
||||||
echo "Available instances: $(jq -r '.woodpecker | keys | join(", ")' "$MOSAIC_CREDENTIALS_FILE" 2>/dev/null)" >&2
|
echo "Available instances: $(jq -r '.woodpecker | keys | join(", ")' "$MOSAIC_CREDENTIALS_FILE" 2>/dev/null)" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ "$wp_default" == "mosaic" ]] && [[ -z "$(_mosaic_read_cred '.woodpecker.mosaic.url')" ]] && [[ -n "$(_mosaic_read_cred '.woodpecker.url')" ]]; then
|
load_credentials "woodpecker-${wp_default}"
|
||||||
WOODPECKER_INSTANCE="mosaic" _mosaic_load_woodpecker_legacy
|
|
||||||
else
|
|
||||||
load_credentials "woodpecker-${wp_default}"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
cloudflare-*)
|
cloudflare-*)
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ gitea_get_branch_head_sha() {
|
|||||||
local branch="$3"
|
local branch="$3"
|
||||||
local token="$4"
|
local token="$4"
|
||||||
local url="https://${host}/api/v1/repos/${repo}/branches/${branch}"
|
local url="https://${host}/api/v1/repos/${repo}/branches/${branch}"
|
||||||
curl -fsS -H "Authorization: token ${token}" "$url" | python3 -c '
|
curl -fsSL -H "Authorization: token ${token}" "$url" | python3 -c '
|
||||||
import json, sys
|
import json, sys
|
||||||
data = json.load(sys.stdin)
|
data = json.load(sys.stdin)
|
||||||
commit = data.get("commit") or {}
|
commit = data.get("commit") or {}
|
||||||
@@ -151,7 +151,7 @@ gitea_get_commit_status_json() {
|
|||||||
local sha="$3"
|
local sha="$3"
|
||||||
local token="$4"
|
local token="$4"
|
||||||
local url="https://${host}/api/v1/repos/${repo}/commits/${sha}/status"
|
local url="https://${host}/api/v1/repos/${repo}/commits/${sha}/status"
|
||||||
curl -fsS -H "Authorization: token ${token}" "$url"
|
curl -fsSL -H "Authorization: token ${token}" "$url"
|
||||||
}
|
}
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ gitea_get_pr_head_sha() {
|
|||||||
local repo="$2"
|
local repo="$2"
|
||||||
local token="$3"
|
local token="$3"
|
||||||
local url="https://${host}/api/v1/repos/${repo}/pulls/${PR_NUMBER}"
|
local url="https://${host}/api/v1/repos/${repo}/pulls/${PR_NUMBER}"
|
||||||
curl -fsS -H "Authorization: token ${token}" "$url" | python3 -c '
|
curl -fsSL -H "Authorization: token ${token}" "$url" | python3 -c '
|
||||||
import json, sys
|
import json, sys
|
||||||
data = json.load(sys.stdin)
|
data = json.load(sys.stdin)
|
||||||
print((data.get("head") or {}).get("sha", ""))
|
print((data.get("head") or {}).get("sha", ""))
|
||||||
@@ -123,7 +123,7 @@ gitea_get_commit_status_json() {
|
|||||||
local token="$3"
|
local token="$3"
|
||||||
local sha="$4"
|
local sha="$4"
|
||||||
local url="https://${host}/api/v1/repos/${repo}/commits/${sha}/status"
|
local url="https://${host}/api/v1/repos/${repo}/commits/${sha}/status"
|
||||||
curl -fsS -H "Authorization: token ${token}" "$url"
|
curl -fsSL -H "Authorization: token ${token}" "$url"
|
||||||
}
|
}
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ REPO_ID=$(wp_resolve_repo_id "$REPO") || exit 1
|
|||||||
|
|
||||||
response=$(curl -sk -w "\n%{http_code}" \
|
response=$(curl -sk -w "\n%{http_code}" \
|
||||||
-H "Authorization: Bearer $WOODPECKER_TOKEN" \
|
-H "Authorization: Bearer $WOODPECKER_TOKEN" \
|
||||||
"${WOODPECKER_URL}/api/repos/${REPO_ID}/pipelines?perPage=${LIMIT}")
|
"${WOODPECKER_URL}/api/repos/${REPO_ID}/pipelines?per_page=${LIMIT}")
|
||||||
|
|
||||||
http_code=$(echo "$response" | tail -n1)
|
http_code=$(echo "$response" | tail -n1)
|
||||||
body=$(echo "$response" | sed '$d')
|
body=$(echo "$response" | sed '$d')
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ _wp_fetch() {
|
|||||||
|
|
||||||
if [[ -z "$NUMBER" ]]; then
|
if [[ -z "$NUMBER" ]]; then
|
||||||
# Get latest pipeline number from list, then fetch full detail
|
# Get latest pipeline number from list, then fetch full detail
|
||||||
list_body=$(_wp_fetch "${WOODPECKER_URL}/api/repos/${REPO_ID}/pipelines?perPage=1") || exit 1
|
list_body=$(_wp_fetch "${WOODPECKER_URL}/api/repos/${REPO_ID}/pipelines?per_page=1") || exit 1
|
||||||
NUMBER=$(echo "$list_body" | jq -r '.[0].number // empty')
|
NUMBER=$(echo "$list_body" | jq -r '.[0].number // empty')
|
||||||
if [[ -z "$NUMBER" ]]; then
|
if [[ -z "$NUMBER" ]]; then
|
||||||
echo "Error: No pipelines found" >&2
|
echo "Error: No pipelines found" >&2
|
||||||
|
|||||||
22
packages/mosaic/src/commands/git-wrapper-redirects.spec.ts
Normal file
22
packages/mosaic/src/commands/git-wrapper-redirects.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { readFileSync } from 'node:fs';
|
||||||
|
import { join } from 'node:path';
|
||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
const packageRoot = join(import.meta.dirname, '..', '..');
|
||||||
|
const gitToolsDir = join(packageRoot, 'framework', 'tools', 'git');
|
||||||
|
|
||||||
|
function readGitTool(scriptName: string): string {
|
||||||
|
return readFileSync(join(gitToolsDir, scriptName), 'utf-8');
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Gitea git wrapper API calls', () => {
|
||||||
|
it.each(['ci-queue-wait.sh', 'pr-ci-wait.sh'])(
|
||||||
|
'%s follows Gitea API redirects before parsing JSON',
|
||||||
|
(scriptName) => {
|
||||||
|
const script = readGitTool(scriptName);
|
||||||
|
|
||||||
|
expect(script).not.toContain('curl -fsS -H "Authorization: token');
|
||||||
|
expect(script).toContain('curl -fsSL -H "Authorization: token');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { describe, it, expect, vi, beforeEach, afterEach, type MockInstance } from 'vitest';
|
import { describe, it, expect, vi, beforeEach, afterEach, type MockInstance } from 'vitest';
|
||||||
import { Command } from 'commander';
|
import { Command } from 'commander';
|
||||||
import { registerRuntimeLaunchers, type RuntimeLaunchHandler } from './launch.js';
|
import { buildPiSkillArgs, registerRuntimeLaunchers, type RuntimeLaunchHandler } from './launch.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for the commander wiring between `mosaic <runtime>` / `mosaic yolo <runtime>`
|
* Tests for the commander wiring between `mosaic <runtime>` / `mosaic yolo <runtime>`
|
||||||
@@ -22,6 +22,8 @@ function buildProgram(handler: RuntimeLaunchHandler): Command {
|
|||||||
return program;
|
return program;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fakeSkills = ['--skill', '/skills/test-driven-development', '--skill', '/skills/pdf'];
|
||||||
|
|
||||||
// `process.exit` returns `never`, so vi.spyOn demands a replacement with the
|
// `process.exit` returns `never`, so vi.spyOn demands a replacement with the
|
||||||
// same signature. We throw from the mock to short-circuit into test-land.
|
// same signature. We throw from the mock to short-circuit into test-land.
|
||||||
const exitThrows = (): never => {
|
const exitThrows = (): never => {
|
||||||
@@ -63,6 +65,30 @@ describe('registerRuntimeLaunchers — non-yolo subcommands', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('buildPiSkillArgs', () => {
|
||||||
|
it('defaults to disabling Pi skill discovery to keep startup context small', () => {
|
||||||
|
expect(buildPiSkillArgs([], {}, fakeSkills)).toEqual(['--no-skills']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps explicit user skills while disabling automatic discovery', () => {
|
||||||
|
expect(buildPiSkillArgs(['--skill', '/tmp/custom'], {}, fakeSkills)).toEqual(['--no-skills']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('supports legacy all-skills mode without double-loading settings skills', () => {
|
||||||
|
expect(buildPiSkillArgs([], { MOSAIC_PI_SKILL_MODE: 'all' }, fakeSkills)).toEqual([
|
||||||
|
'--no-skills',
|
||||||
|
'--skill',
|
||||||
|
'/skills/test-driven-development',
|
||||||
|
'--skill',
|
||||||
|
'/skills/pdf',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('supports native Pi discovery when explicitly requested', () => {
|
||||||
|
expect(buildPiSkillArgs([], { MOSAIC_PI_SKILL_MODE: 'discover' }, fakeSkills)).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('registerRuntimeLaunchers — yolo <runtime>', () => {
|
describe('registerRuntimeLaunchers — yolo <runtime>', () => {
|
||||||
let mockExit: MockInstance<typeof process.exit>;
|
let mockExit: MockInstance<typeof process.exit>;
|
||||||
let mockError: MockInstance<typeof console.error>;
|
let mockError: MockInstance<typeof console.error>;
|
||||||
|
|||||||
@@ -447,6 +447,32 @@ function discoverPiSkills(): string[] {
|
|||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PiSkillMode = 'none' | 'all' | 'discover';
|
||||||
|
|
||||||
|
function normalizePiSkillMode(env: NodeJS.ProcessEnv): PiSkillMode {
|
||||||
|
const value = env['MOSAIC_PI_SKILL_MODE']?.trim().toLowerCase();
|
||||||
|
if (value === 'all' || value === 'discover') return value;
|
||||||
|
return 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildPiSkillArgs(
|
||||||
|
_runtimeArgs: string[],
|
||||||
|
env: NodeJS.ProcessEnv = process.env,
|
||||||
|
discoveredSkillArgs: string[] = discoverPiSkills(),
|
||||||
|
): string[] {
|
||||||
|
const mode = normalizePiSkillMode(env);
|
||||||
|
|
||||||
|
if (mode === 'discover') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode === 'all') {
|
||||||
|
return ['--no-skills', ...discoveredSkillArgs];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['--no-skills'];
|
||||||
|
}
|
||||||
|
|
||||||
function discoverPiExtension(): string[] {
|
function discoverPiExtension(): string[] {
|
||||||
const ext = join(MOSAIC_HOME, 'runtime', 'pi', 'mosaic-extension.ts');
|
const ext = join(MOSAIC_HOME, 'runtime', 'pi', 'mosaic-extension.ts');
|
||||||
return existsSync(ext) ? ['--extension', ext] : [];
|
return existsSync(ext) ? ['--extension', ext] : [];
|
||||||
@@ -523,7 +549,7 @@ function launchRuntime(runtime: RuntimeName, args: string[], yolo: boolean): nev
|
|||||||
case 'pi': {
|
case 'pi': {
|
||||||
const prompt = buildRuntimePrompt('pi');
|
const prompt = buildRuntimePrompt('pi');
|
||||||
const cliArgs = ['--append-system-prompt', prompt];
|
const cliArgs = ['--append-system-prompt', prompt];
|
||||||
cliArgs.push(...discoverPiSkills());
|
cliArgs.push(...buildPiSkillArgs(args));
|
||||||
cliArgs.push(...discoverPiExtension());
|
cliArgs.push(...discoverPiExtension());
|
||||||
if (hasMissionNoArgs) {
|
if (hasMissionNoArgs) {
|
||||||
cliArgs.push(missionPrompt);
|
cliArgs.push(missionPrompt);
|
||||||
|
|||||||
Reference in New Issue
Block a user