@piagent/platform 1.5.4 → 1.6.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 +136 -0
- package/README.md +9 -8
- package/README.vi.md +9 -5
- package/adapters/web-frontend/profile.json +2 -4
- package/architecture/layers.json +18 -3
- package/benchmarks/deep-logic-v1/SPECIALIST_PROTOCOL.vi.md +122 -0
- package/benchmarks/deep-logic-v1/grade.mjs +272 -10
- package/benchmarks/deep-logic-v1/project/apps/admin/src/billing-summary.js +3 -0
- package/benchmarks/deep-logic-v1/project/benchmark-contract/public-smoke.test.js +166 -0
- package/benchmarks/deep-logic-v1/project/package.json +1 -1
- package/benchmarks/deep-logic-v1/project/packages/billing/src/close-period.js +3 -0
- package/benchmarks/deep-logic-v1/project/packages/billing/src/plan-timeline.js +3 -0
- package/benchmarks/deep-logic-v1/project/test/smoke.test.js +7 -1
- package/benchmarks/deep-logic-v1/prompts/budgeted-context-graph.md +2 -0
- package/benchmarks/deep-logic-v1/prompts/fair-dependency-scheduler.md +2 -0
- package/benchmarks/deep-logic-v1/prompts/layered-policy-resolution.md +2 -0
- package/benchmarks/deep-logic-v1/prompts/resumable-stream-assembly.md +3 -1
- package/benchmarks/deep-logic-v1/prompts/revision-event-reconciliation.md +2 -0
- package/benchmarks/deep-logic-v1/prompts/temporal-usage-billing-close.md +123 -0
- package/benchmarks/deep-logic-v1/prompts/transactional-config-merge.md +2 -0
- package/benchmarks/deep-logic-v1/suite.json +51 -3
- package/benchmarks/deep-logic-v1/variant.mjs +22 -1
- package/benchmarks/production-v1/spend-control.v1.json +68 -0
- package/benchmarks/production-v1/suite.json +42 -3
- package/catalog/capabilities.json +6 -6
- package/docs/command-reference-vietnamese.md +6 -6
- package/docs/context-engine.md +7 -1
- package/docs/distribution-standard.md +7 -7
- package/docs/en/architecture.md +1 -0
- package/docs/languages.json +4 -4
- package/docs/model-options.md +8 -5
- package/docs/operator-manual-vietnamese.md +13 -11
- package/docs/project-adapters.md +2 -2
- package/docs/publishing-for-teams.md +9 -0
- package/docs/quality-benchmark.md +271 -62
- package/docs/release-install-policy.md +10 -9
- package/docs/runtime-policy-design.md +4 -4
- package/docs/runtime-quality-baseline.md +13 -6
- package/docs/security-threat-model.md +2 -2
- package/docs/task-lifecycle-vietnamese.md +2 -2
- package/docs/team-onboarding.md +2 -2
- package/docs/usage-observability.md +7 -2
- package/docs/vi/architecture.md +1 -0
- package/docs-site/architecture.html +1 -1
- package/docs-site/benchmark.html +1 -1
- package/docs-site/commands.html +1 -1
- package/docs-site/context-engine.html +1 -1
- package/docs-site/en/architecture.html +1 -1
- package/docs-site/en/benchmark.html +1 -1
- package/docs-site/en/commands.html +1 -1
- package/docs-site/en/context-engine.html +1 -1
- package/docs-site/en/index.html +1 -1
- package/docs-site/en/mcp-approval.html +1 -1
- package/docs-site/en/mcp-auth.html +1 -1
- package/docs-site/en/mcp-servers.html +1 -1
- package/docs-site/en/mcp.html +1 -1
- package/docs-site/en/permissions.html +1 -1
- package/docs-site/en/profiles.html +1 -1
- package/docs-site/en/quickstart.html +1 -1
- package/docs-site/en/runtime.html +1 -1
- package/docs-site/en/scope.html +1 -1
- package/docs-site/en/security.html +1 -1
- package/docs-site/en/team.html +1 -1
- package/docs-site/en/whats-new.html +1 -1
- package/docs-site/en/workflows.html +1 -1
- package/docs-site/index.html +1 -1
- package/docs-site/mcp-approval.html +1 -1
- package/docs-site/mcp-auth.html +1 -1
- package/docs-site/mcp-servers.html +1 -1
- package/docs-site/mcp.html +1 -1
- package/docs-site/permissions.html +1 -1
- package/docs-site/profiles.html +1 -1
- package/docs-site/quickstart.html +1 -1
- package/docs-site/runtime.html +1 -1
- package/docs-site/scope.html +1 -1
- package/docs-site/security.html +1 -1
- package/docs-site/team.html +1 -1
- package/docs-site/whats-new.html +1 -1
- package/docs-site/workflows.html +1 -1
- package/evals/fixtures/benchmark-assurance-evidence.invalid.json +1 -1
- package/evals/fixtures/benchmark-assurance-evidence.valid.json +1 -1
- package/evals/fixtures/piagent-webui/session-live-state-v1.invalid.json +18 -0
- package/evals/fixtures/piagent-webui/session-live-state-v1.valid.json +27 -0
- package/evals/fs4-readiness-matrix.v1.json +2 -2
- package/evals/fs5-causal-arm.v1.json +2 -2
- package/evals/fs5-pilot-protocol.v1.json +2 -2
- package/evals/fs5-pilot-protocol.v4.json +6 -5
- package/evals/fs5-pilot-protocol.v5.json +7 -6
- package/evals/private-holdout-v1/public-exposure.v1.json +1 -1
- package/package.json +3 -1
- package/packages/piagent-core/benchmark/benchmark-assurance.js +4 -1
- package/packages/piagent-core/benchmark/benchmark-bootstrap.js +91 -9
- package/packages/piagent-core/benchmark/benchmark-claim-restrictions.js +38 -7
- package/packages/piagent-core/benchmark/benchmark-cli.js +7 -7
- package/packages/piagent-core/benchmark/benchmark-codex.js +3 -1
- package/packages/piagent-core/benchmark/benchmark-comparison.js +271 -2
- package/packages/piagent-core/benchmark/benchmark-core.js +732 -661
- package/packages/piagent-core/benchmark/benchmark-execution-guard.js +7 -5
- package/packages/piagent-core/benchmark/benchmark-forensics.js +439 -4
- package/packages/piagent-core/benchmark/benchmark-host-readiness.js +639 -0
- package/packages/piagent-core/benchmark/benchmark-matrix.js +22 -4
- package/packages/piagent-core/benchmark/benchmark-normalized-cost.js +317 -0
- package/packages/piagent-core/benchmark/benchmark-preflight.js +3 -1
- package/packages/piagent-core/benchmark/benchmark-process.js +6 -5
- package/packages/piagent-core/benchmark/benchmark-provider-wire.js +126 -0
- package/packages/piagent-core/benchmark/benchmark-record-validation.js +183 -0
- package/packages/piagent-core/benchmark/benchmark-report.js +116 -12
- package/packages/piagent-core/benchmark/benchmark-resume-recovery.js +14 -0
- package/packages/piagent-core/benchmark/benchmark-runner-policy.js +26 -0
- package/packages/piagent-core/benchmark/benchmark-stage-diagnostic.js +782 -0
- package/packages/piagent-core/benchmark/benchmark-statistics.js +64 -0
- package/packages/piagent-core/benchmark/benchmark-stop-policy.js +8 -5
- package/packages/piagent-core/benchmark/benchmark-suite-identity.js +31 -0
- package/packages/piagent-core/benchmark/benchmark-suite-runtime.js +13 -9
- package/packages/piagent-core/benchmark/benchmark-suite.js +128 -2
- package/packages/piagent-core/benchmark/benchmark-summary-support.js +376 -0
- package/packages/piagent-core/benchmark/benchmark-timing-diagnostics.js +971 -0
- package/packages/piagent-core/benchmark/benchmark-usage.js +311 -0
- package/packages/piagent-core/benchmark/benchmark-workflow.js +166 -0
- package/packages/piagent-core/docs/context-efficiency-improvement-plan.md +1080 -0
- package/packages/piagent-core/extensions/acceptance-contract-semantics.js +83 -69
- package/packages/piagent-core/extensions/acceptance-error-classes.js +160 -0
- package/packages/piagent-core/extensions/acceptance-executable-evidence.js +12 -9
- package/packages/piagent-core/extensions/acceptance-receipt.js +34 -11
- package/packages/piagent-core/extensions/acceptance-state-machine-evidence.js +518 -0
- package/packages/piagent-core/extensions/acceptance-test-binding-evidence.js +60 -0
- package/packages/piagent-core/extensions/context-efficiency-metrics.js +302 -0
- package/packages/piagent-core/extensions/context-efficiency-report.js +167 -0
- package/packages/piagent-core/extensions/context-engine.js +148 -145
- package/packages/piagent-core/extensions/context-evidence.js +48 -0
- package/packages/piagent-core/extensions/context-import-links.js +296 -0
- package/packages/piagent-core/extensions/context-telemetry-integrity.js +65 -0
- package/packages/piagent-core/extensions/criterion-context-pack.js +422 -7
- package/packages/piagent-core/extensions/criterion-graph.js +78 -8
- package/packages/piagent-core/extensions/guard-types.ts +3 -0
- package/packages/piagent-core/extensions/javascript-regex-evidence.js +32 -0
- package/packages/piagent-core/extensions/piagent-guard.ts +250 -43
- package/packages/piagent-core/extensions/policy-core.js +1 -1
- package/packages/piagent-core/extensions/task-contract-view.js +17 -3
- package/packages/piagent-core/extensions/task-lifecycle.js +7 -2
- package/packages/piagent-core/extensions/task-state.js +40 -134
- package/packages/piagent-core/extensions/verification-intelligence.js +3 -1
- package/packages/piagent-core/extensions/workspace-evidence-roots.js +157 -0
- package/packages/piagent-core/package.json +1 -1
- package/packages/piagent-core/policies/base-policy.json +3 -0
- package/packages/piagent-core/runtime/context/context-delivery.ts +103 -0
- package/packages/piagent-core/runtime/context/context-delta-shadow.ts +53 -0
- package/packages/piagent-core/runtime/context/context-efficiency-format.ts +47 -0
- package/packages/piagent-core/runtime/context/context-evidence-qualification.ts +32 -0
- package/packages/piagent-core/runtime/context/prefix-telemetry.ts +47 -0
- package/packages/piagent-core/runtime/context/repository-memory-hints.ts +27 -0
- package/packages/piagent-core/runtime/hooks/agent-prompt-telemetry.ts +56 -0
- package/packages/piagent-core/runtime/hooks/agent-start-hook.ts +162 -102
- package/packages/piagent-core/runtime/hooks/completion-hook.ts +5 -6
- package/packages/piagent-core/runtime/hooks/input-hook.ts +11 -1
- package/packages/piagent-core/runtime/hooks/session-hooks.ts +22 -2
- package/packages/piagent-core/runtime/hooks/session-start-hook.ts +7 -2
- package/packages/piagent-core/runtime/hooks/tool-result-content-guards.ts +95 -0
- package/packages/piagent-core/runtime/hooks/tool-result-hook.ts +84 -102
- package/packages/piagent-core/runtime/inspection/activity-event-adapter.ts +9 -3
- package/packages/piagent-core/runtime/inspection/activity-recovery.ts +104 -0
- package/packages/piagent-core/runtime/inspection/approval-broker.ts +29 -5
- package/packages/piagent-core/runtime/inspection/task-compaction-history.ts +1 -1
- package/packages/piagent-core/runtime/inspection/task-handoff-history.ts +1 -1
- package/packages/piagent-core/runtime/inspection/tool-failure-classification.ts +53 -0
- package/packages/piagent-core/runtime/inspection/webui-snapshot.ts +34 -6
- package/packages/piagent-core/runtime/model/authenticated-catalog.ts +17 -9
- package/packages/piagent-core/runtime/model/openai-codex-reasoning.ts +83 -0
- package/packages/piagent-core/runtime/model/provider-wire-fingerprint.ts +238 -0
- package/packages/piagent-core/runtime/orchestration/role-policy.ts +1 -1
- package/packages/piagent-core/runtime/product/activity-inspector.ts +7 -2
- package/packages/piagent-core/runtime/product/efficiency-metrics.ts +4 -2
- package/packages/piagent-core/runtime/quality/exact-output-contract.ts +2 -1
- package/packages/piagent-core/runtime/quality/performance-assurance-signals.ts +23 -0
- package/packages/piagent-core/runtime/quality/performance-assurance.ts +6 -2
- package/packages/piagent-core/runtime/recovery/edit-recovery-context.ts +113 -0
- package/packages/piagent-core/runtime/recovery/edit-recovery-delivery.ts +42 -0
- package/packages/piagent-core/runtime/recovery/semantic-repair-handshake.ts +55 -2
- package/packages/piagent-core/runtime/recovery/semantic-repair-runtime.ts +55 -2
- package/packages/piagent-core/runtime/registration/context-commands.ts +66 -5
- package/packages/piagent-core/runtime/registration/policy-tools.ts +46 -11
- package/packages/piagent-core/runtime/registration/task-completion-tools.ts +49 -16
- package/packages/piagent-core/runtime/registration/task-start-guidance.ts +163 -0
- package/packages/piagent-core/runtime/registration/task-start-retry-helpers.ts +37 -0
- package/packages/piagent-core/runtime/registration/task-start-tool.ts +67 -62
- package/packages/piagent-core/runtime/session/runtime-state.ts +154 -2
- package/packages/piagent-core/runtime/session/system-prompt.ts +4 -4
- package/packages/piagent-core/runtime/tools/apply-patch-tool.ts +500 -0
- package/packages/piagent-core/runtime/trajectory/trajectory-runtime.ts +2 -1
- package/packages/piagent-core/runtime/workflows/task-intake.ts +43 -2
- package/packages/piagent-core/security/sensitive-data.js +13 -218
- package/packages/piagent-core/security/sensitive-project-file.js +42 -0
- package/packages/piagent-core/security/sensitive-source-expression.js +330 -0
- package/packages/piagent-core/security/sensitive-source-formats.js +394 -0
- package/packages/piagent-core/security/sensitive-text.js +234 -0
- package/packages/piagent-core/subagents/piagent-worker.md +1 -1
- package/packages/piagent-webui/dist/client/assets/{MarkdownMessage-rD9WJKxs.js → MarkdownMessage-CxeZqTte.js} +1 -1
- package/packages/piagent-webui/dist/client/assets/index-DynIMe8I.js +176 -0
- package/packages/piagent-webui/dist/client/index.html +1 -1
- package/packages/piagent-webui/gateway/gateway-events.ts +109 -5
- package/packages/piagent-webui/gateway/gateway-service.ts +3 -0
- package/packages/piagent-webui/gateway/gateway-session-stream.ts +93 -7
- package/packages/piagent-webui/gateway/session-command-controller.ts +18 -3
- package/packages/piagent-webui/gateway/session-effective-options.ts +47 -0
- package/packages/piagent-webui/gateway/session-live-state.ts +21 -0
- package/packages/piagent-webui/gateway/session-operation-start.ts +5 -1
- package/packages/piagent-webui/gateway/session-operation-watchdog.ts +158 -0
- package/packages/piagent-webui/gateway/session-runtime-factory.ts +45 -0
- package/packages/piagent-webui/gateway/session-runtime-supervisor.ts +139 -120
- package/packages/piagent-webui/server/loopback-server.ts +8 -0
- package/packages/piagent-webui/server/transcript-projection.ts +22 -4
- package/packages/piagent-webui/shared/text-visibility.ts +10 -0
- package/schemas/piagent-webui/catalog-v1.json +9 -0
- package/schemas/piagent-webui/gateway-protocol-v1.schema.json +53 -3
- package/schemas/piagent-webui/session-live-state-v1.schema.json +76 -0
- package/schemas/task-contract.schema.json +12 -1
- package/scripts/benchmark-runner-core.mjs +355 -359
- package/scripts/benchmark-runner-finalization.mjs +309 -0
- package/scripts/benchmark-runner-host-readiness.mjs +94 -0
- package/scripts/benchmark-runner-support.mjs +200 -0
- package/scripts/benchmark-session.mjs +95 -41
- package/scripts/configure-model-scope.sh +4 -3
- package/scripts/helper-evaluation.mjs +1 -1
- package/scripts/install-global.sh +2 -2
- package/scripts/pi-usage-history.mjs +37 -10
- package/scripts/piagent-dashboard.mjs +13 -1
- package/scripts/setup.sh +2 -2
- package/scripts/verify-local.sh +5 -1
- package/templates/global/settings.json +2 -1
- package/packages/piagent-webui/dist/client/assets/index-BZRFw1u6.js +0 -174
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
|
|
4
|
+
import { buildContextPack, ensureContextIndexV2 } from "../../extensions/context-engine.js";
|
|
5
|
+
import { durableContextEvidenceEntries } from "../../extensions/context-evidence.js";
|
|
6
|
+
import type { TaskContract } from "../../extensions/guard-types.js";
|
|
7
|
+
|
|
8
|
+
export type ContextDeltaShadowMode = "off" | "sample" | "on";
|
|
9
|
+
|
|
10
|
+
type ShadowInput = {
|
|
11
|
+
ctx: ExtensionContext;
|
|
12
|
+
query: string;
|
|
13
|
+
turnId: string;
|
|
14
|
+
task: TaskContract;
|
|
15
|
+
mode: ContextDeltaShadowMode;
|
|
16
|
+
protectedTarget: boolean;
|
|
17
|
+
excludePatterns: string[];
|
|
18
|
+
telemetry: (ctx: ExtensionContext, payload: Record<string, unknown>) => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function sampled(taskRunId: string, query: string): boolean {
|
|
22
|
+
const byte = crypto.createHash("sha256").update(`${taskRunId}\0${query}`).digest()[0];
|
|
23
|
+
return byte < 64;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function measureContextDeltaShadow(input: ShadowInput): Promise<void> {
|
|
27
|
+
if (input.mode === "off" || input.protectedTarget || (input.mode === "sample" && !sampled(input.task.taskRunId, input.query))) return;
|
|
28
|
+
const usage = input.ctx.getContextUsage();
|
|
29
|
+
if (usage && Number(usage.percent ?? 0) >= 80) return;
|
|
30
|
+
try {
|
|
31
|
+
const { status } = await ensureContextIndexV2(input.ctx.cwd, { excludePatterns: input.excludePatterns, rebuildMissing: false });
|
|
32
|
+
if (!status.exists || status.stale) return;
|
|
33
|
+
const pack = await buildContextPack(input.ctx.cwd, input.query, {
|
|
34
|
+
budgetTokens: 1_200,
|
|
35
|
+
includeCode: false,
|
|
36
|
+
limit: 10,
|
|
37
|
+
excludePatterns: input.excludePatterns
|
|
38
|
+
});
|
|
39
|
+
const manifested = new Set(durableContextEvidenceEntries(input.task).map((entry) => entry.path));
|
|
40
|
+
const duplicateItems = pack.selected.filter((item) => manifested.has(item.path));
|
|
41
|
+
input.telemetry(input.ctx, {
|
|
42
|
+
event: "context_delta_shadow",
|
|
43
|
+
turnId: input.turnId,
|
|
44
|
+
queryHash: pack.queryHash,
|
|
45
|
+
candidatePaths: pack.selected.map((item) => item.path),
|
|
46
|
+
pathsAlreadyManifested: duplicateItems.map((item) => item.path),
|
|
47
|
+
candidateTokens: pack.selected.reduce((sum, item) => sum + item.estimatedTokens, 0),
|
|
48
|
+
duplicateCandidateTokens: duplicateItems.reduce((sum, item) => sum + item.estimatedTokens, 0)
|
|
49
|
+
});
|
|
50
|
+
} catch (error) {
|
|
51
|
+
input.telemetry(input.ctx, { event: "context_delta_shadow", turnId: input.turnId, skipped: "error", error: error instanceof Error ? error.message : String(error) });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
type ContextEfficiencyReport = {
|
|
2
|
+
metrics: {
|
|
3
|
+
contextWasteScore: number | null;
|
|
4
|
+
contextWasteScoreEstimate: number;
|
|
5
|
+
contextWasteScoreEvidenceCoverage: number;
|
|
6
|
+
averageActiveTools: number;
|
|
7
|
+
toolSchemaPrefixShare: number;
|
|
8
|
+
toolSchemaToSystemRatio: number;
|
|
9
|
+
duplicateReads: number;
|
|
10
|
+
comparableReadCalls: number;
|
|
11
|
+
readCalls: number;
|
|
12
|
+
readEvidenceCoverage: number;
|
|
13
|
+
contextFallbackRereads: number;
|
|
14
|
+
contextSelections: number;
|
|
15
|
+
duplicateOutputRate: number;
|
|
16
|
+
lowConfidencePacks: number;
|
|
17
|
+
editRecoveryContextCount: number;
|
|
18
|
+
editRecoveryFailures: number;
|
|
19
|
+
editRecoverySuppressedFailures: number;
|
|
20
|
+
editRecoveryEstimatedTokens: number;
|
|
21
|
+
editRecoveryFailureEvidenceCoverage: number;
|
|
22
|
+
};
|
|
23
|
+
coverage: { wasteScore: { status: string } };
|
|
24
|
+
sample: { contextPacks: number };
|
|
25
|
+
recommendations: string[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export function formatContextEfficiencyReport(
|
|
29
|
+
report: ContextEfficiencyReport,
|
|
30
|
+
formatPercent: (value: number) => string
|
|
31
|
+
): string {
|
|
32
|
+
const wasteScore = report.metrics.contextWasteScore === null
|
|
33
|
+
? `unavailable (diagnostic estimate ${report.metrics.contextWasteScoreEstimate}/100; evidence ${formatPercent(report.metrics.contextWasteScoreEvidenceCoverage)}, ${report.coverage.wasteScore.status})`
|
|
34
|
+
: `${report.metrics.contextWasteScore}/100 (lower is better; evidence ${formatPercent(report.metrics.contextWasteScoreEvidenceCoverage)}, ${report.coverage.wasteScore.status})`;
|
|
35
|
+
return [
|
|
36
|
+
`contextWasteScore: ${wasteScore}`,
|
|
37
|
+
`activeTools: ${report.metrics.averageActiveTools}`,
|
|
38
|
+
`toolSchemaPrefixShare: ${formatPercent(report.metrics.toolSchemaPrefixShare)}`,
|
|
39
|
+
`toolSchemaToSystemRatio: ${report.metrics.toolSchemaToSystemRatio}`,
|
|
40
|
+
`duplicateReads: ${report.metrics.duplicateReads}/${report.metrics.comparableReadCalls} comparable (${report.metrics.readCalls} observed; coverage ${formatPercent(report.metrics.readEvidenceCoverage)})`,
|
|
41
|
+
`fallbackRereads: ${report.metrics.contextFallbackRereads}/${report.metrics.contextSelections}`,
|
|
42
|
+
`duplicateOutput: ${formatPercent(report.metrics.duplicateOutputRate)}`,
|
|
43
|
+
`lowConfidencePacks: ${report.metrics.lowConfidencePacks}/${report.sample.contextPacks}`,
|
|
44
|
+
`editRecovery: ${report.metrics.editRecoveryContextCount}/${report.metrics.editRecoveryFailures} failures returned context; ${report.metrics.editRecoverySuppressedFailures} suppressed; ${report.metrics.editRecoveryEstimatedTokens} estimated tokens; classification coverage ${formatPercent(report.metrics.editRecoveryFailureEvidenceCoverage)}`,
|
|
45
|
+
...report.recommendations.map((recommendation) => `- ${recommendation}`)
|
|
46
|
+
].join("\n");
|
|
47
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
import type { TaskContract } from "../../extensions/guard-types.js";
|
|
4
|
+
import type { ObservedTaskContext, RuntimeSessionState } from "../session/runtime-state.ts";
|
|
5
|
+
|
|
6
|
+
type TaskIdentity = { taskId: string; taskRunId: string };
|
|
7
|
+
|
|
8
|
+
type ContextEvidenceQualificationDependencies = {
|
|
9
|
+
state: RuntimeSessionState;
|
|
10
|
+
activeTask: (ctx: ExtensionContext) => TaskContract | undefined;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function recordObservedContextEvidence(
|
|
14
|
+
ctx: ExtensionContext,
|
|
15
|
+
entry: ObservedTaskContext | undefined,
|
|
16
|
+
taskIdentity: TaskIdentity | undefined,
|
|
17
|
+
dependencies: ContextEvidenceQualificationDependencies
|
|
18
|
+
): void {
|
|
19
|
+
if (!entry) return;
|
|
20
|
+
dependencies.state.rememberObservedContext(ctx, entry);
|
|
21
|
+
const activeTask = dependencies.activeTask(ctx);
|
|
22
|
+
if (
|
|
23
|
+
taskIdentity
|
|
24
|
+
&& activeTask?.trace.outcome === "pending"
|
|
25
|
+
&& activeTask.taskId === taskIdentity.taskId
|
|
26
|
+
&& activeTask.taskRunId === taskIdentity.taskRunId
|
|
27
|
+
) {
|
|
28
|
+
dependencies.state.rememberQualifiedContextEvidence(ctx, taskIdentity.taskRunId, entry);
|
|
29
|
+
} else if (!activeTask || activeTask.trace.outcome !== "pending") {
|
|
30
|
+
dependencies.state.rememberPreTaskContext(ctx, entry);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
|
|
3
|
+
type ProviderToolMetadata = {
|
|
4
|
+
name: string;
|
|
5
|
+
description?: unknown;
|
|
6
|
+
parameters?: unknown;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
function canonicalValue(value: unknown): unknown {
|
|
10
|
+
if (value === null || ["string", "number", "boolean"].includes(typeof value)) return value;
|
|
11
|
+
if (Array.isArray(value)) return value.map((item) => canonicalValue(item));
|
|
12
|
+
if (!value || typeof value !== "object") return undefined;
|
|
13
|
+
return Object.fromEntries(
|
|
14
|
+
Object.entries(value as Record<string, unknown>)
|
|
15
|
+
.filter(([, item]) => item !== undefined && typeof item !== "function" && typeof item !== "symbol")
|
|
16
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
17
|
+
.map(([key, item]) => [key, canonicalValue(item)])
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function deepCanonicalJson(value: unknown): string {
|
|
22
|
+
return JSON.stringify(canonicalValue(value));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function hash(value: string): string {
|
|
26
|
+
return crypto.createHash("sha256").update(value).digest("hex");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function buildPrefixTelemetry(systemPrompt: string, tools: ProviderToolMetadata[]): {
|
|
30
|
+
systemPromptHash: string;
|
|
31
|
+
toolSchemaHash: string;
|
|
32
|
+
prefixSurfaceHash: string;
|
|
33
|
+
canonicalToolSurface: string;
|
|
34
|
+
} {
|
|
35
|
+
const providerSurface = tools
|
|
36
|
+
.map((tool) => ({ name: tool.name, description: tool.description, parameters: tool.parameters }))
|
|
37
|
+
.sort((left, right) => left.name.localeCompare(right.name));
|
|
38
|
+
const canonicalToolSurface = deepCanonicalJson(providerSurface);
|
|
39
|
+
const systemPromptHash = hash(systemPrompt);
|
|
40
|
+
const toolSchemaHash = hash(canonicalToolSurface);
|
|
41
|
+
return {
|
|
42
|
+
systemPromptHash,
|
|
43
|
+
toolSchemaHash,
|
|
44
|
+
prefixSurfaceHash: hash(`${systemPromptHash}\0${toolSchemaHash}`),
|
|
45
|
+
canonicalToolSurface
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { estimateContextTokens } from "../../extensions/context-engine.js";
|
|
2
|
+
|
|
3
|
+
type RepositoryMemoryCandidate = {
|
|
4
|
+
record: { id?: string; fact: string; citations: Array<{ path: string }> };
|
|
5
|
+
matchedTerms: string[];
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function formatRepositoryMemoryHints(
|
|
9
|
+
candidates: RepositoryMemoryCandidate[],
|
|
10
|
+
budgetTokens: number
|
|
11
|
+
): { text: string; ids: string[] } {
|
|
12
|
+
if (budgetTokens < 80 || candidates.length === 0) return { text: "", ids: [] };
|
|
13
|
+
const lines = [
|
|
14
|
+
"[Piagent repository memory: advisory only]",
|
|
15
|
+
"Verify every hint against the cited current file before relying on it."
|
|
16
|
+
];
|
|
17
|
+
const ids: string[] = [];
|
|
18
|
+
for (const candidate of candidates) {
|
|
19
|
+
const paths = candidate.record.citations.slice(0, 4).map((citation) => citation.path).join(", ");
|
|
20
|
+
const line = `- ${candidate.record.fact.slice(0, 320)} [sources: ${paths}]`;
|
|
21
|
+
const proposed = [...lines, line].join("\n");
|
|
22
|
+
if (estimateContextTokens(proposed) > budgetTokens) break;
|
|
23
|
+
lines.push(line);
|
|
24
|
+
if (candidate.record.id) ids.push(candidate.record.id);
|
|
25
|
+
}
|
|
26
|
+
return ids.length > 0 ? { text: lines.join("\n"), ids } : { text: "", ids: [] };
|
|
27
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { RuntimeModelSnapshot } from "../model/runtime-snapshot.ts";
|
|
2
|
+
import { runtimeModelSnapshotDigest } from "../model/runtime-snapshot.ts";
|
|
3
|
+
import type { ModelRouteEvaluation } from "../model/model-route-runtime.ts";
|
|
4
|
+
import type { SolverShadowEvaluation } from "../solver/solver-shadow.ts";
|
|
5
|
+
|
|
6
|
+
export function runtimeSnapshotTelemetry(snapshot?: RuntimeModelSnapshot) {
|
|
7
|
+
if (!snapshot) return undefined;
|
|
8
|
+
return {
|
|
9
|
+
schemaVersion: snapshot.schemaVersion,
|
|
10
|
+
digest: runtimeModelSnapshotDigest(snapshot),
|
|
11
|
+
provider: snapshot.provider,
|
|
12
|
+
modelId: snapshot.modelId,
|
|
13
|
+
contextWindow: snapshot.contextWindow,
|
|
14
|
+
requestedThinkingLevel: snapshot.requestedThinkingLevel,
|
|
15
|
+
effectiveThinkingLevel: snapshot.effectiveThinkingLevel,
|
|
16
|
+
warningCount: snapshot.warnings.length
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function solverShadowTelemetry(evaluation?: SolverShadowEvaluation) {
|
|
21
|
+
if (evaluation?.status !== "ok") return evaluation;
|
|
22
|
+
return {
|
|
23
|
+
mode: evaluation.decision.mode,
|
|
24
|
+
route: evaluation.decision.route,
|
|
25
|
+
featureHash: evaluation.features.featureHash,
|
|
26
|
+
reasonCodes: evaluation.decision.reasonCodes,
|
|
27
|
+
confidence: evaluation.decision.confidence,
|
|
28
|
+
reused: evaluation.reused,
|
|
29
|
+
persisted: evaluation.persisted,
|
|
30
|
+
durationMs: evaluation.durationMs,
|
|
31
|
+
warnings: evaluation.warnings
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function modelRouteTelemetry(evaluation?: ModelRouteEvaluation) {
|
|
36
|
+
if (evaluation?.status !== "ok") return evaluation;
|
|
37
|
+
return {
|
|
38
|
+
mode: evaluation.decision.mode,
|
|
39
|
+
objective: evaluation.decision.objective,
|
|
40
|
+
capabilityBand: evaluation.decision.capabilityBand,
|
|
41
|
+
safetyFloor: evaluation.decision.safetyFloor,
|
|
42
|
+
disposition: evaluation.decision.disposition,
|
|
43
|
+
selectionSource: evaluation.decision.selectionSource,
|
|
44
|
+
provider: evaluation.decision.provider,
|
|
45
|
+
modelId: evaluation.decision.modelId,
|
|
46
|
+
effort: evaluation.decision.effort,
|
|
47
|
+
downgradeSteps: evaluation.decision.downgradeSteps,
|
|
48
|
+
enforced: evaluation.decision.enforced,
|
|
49
|
+
decisionDigest: evaluation.decision.decisionDigest,
|
|
50
|
+
reasonCodes: evaluation.decision.reasonCodes,
|
|
51
|
+
reused: evaluation.reused,
|
|
52
|
+
persisted: evaluation.persisted,
|
|
53
|
+
durationMs: evaluation.durationMs,
|
|
54
|
+
warnings: evaluation.warnings
|
|
55
|
+
};
|
|
56
|
+
}
|