@nebutra/agent-runtime 0.2.0 → 0.2.1

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.
Files changed (78) hide show
  1. package/.turbo/turbo-build.log +65 -50
  2. package/.turbo/turbo-test.log +39 -36
  3. package/.turbo/turbo-typecheck.log +1 -1
  4. package/CHANGELOG.md +12 -15
  5. package/README.md +2 -0
  6. package/dist/adapters/dispatcher-sse.js +1 -0
  7. package/dist/adapters/index.js +1 -0
  8. package/dist/adapters/mcp-catalog.js +1 -0
  9. package/dist/adapters/prisma-rollout.js +1 -0
  10. package/dist/chunk-424PT5DM.js +23 -0
  11. package/dist/chunk-424PT5DM.js.map +1 -0
  12. package/dist/{chunk-NN7DATXA.js → chunk-4Y25ZTKI.js} +3 -3
  13. package/dist/chunk-4Y25ZTKI.js.map +1 -0
  14. package/dist/{chunk-BJBBR3QA.js → chunk-D4YAPLOW.js} +4 -4
  15. package/dist/chunk-D4YAPLOW.js.map +1 -0
  16. package/dist/{chunk-ZMYX5VBU.js → chunk-GQZKYWFT.js} +23 -7
  17. package/dist/chunk-GQZKYWFT.js.map +1 -0
  18. package/dist/chunk-KCNN4QUQ.js +255 -0
  19. package/dist/chunk-KCNN4QUQ.js.map +1 -0
  20. package/dist/chunk-MX2WL43P.js +90 -0
  21. package/dist/chunk-MX2WL43P.js.map +1 -0
  22. package/dist/{chunk-PGGWSUTM.js → chunk-NI4EDT4T.js} +2 -2
  23. package/dist/chunk-NI4EDT4T.js.map +1 -0
  24. package/dist/{chunk-5N4644PB.js → chunk-SD2ZJ7XG.js} +4 -4
  25. package/dist/cli.d.ts +2 -0
  26. package/dist/cli.js +52 -0
  27. package/dist/cli.js.map +1 -0
  28. package/dist/commands.js +1 -0
  29. package/dist/definitions.js +1 -0
  30. package/dist/dispatcher.js +1 -0
  31. package/dist/durable-turn.js +3 -2
  32. package/dist/hook-pipeline.js +1 -0
  33. package/dist/index.d.ts +8 -85
  34. package/dist/index.js +237 -119
  35. package/dist/index.js.map +1 -1
  36. package/dist/loop.d.ts +2 -2
  37. package/dist/loop.js +3 -2
  38. package/dist/mcp-bridge.d.ts +3 -3
  39. package/dist/mcp-bridge.js +3 -2
  40. package/dist/model.js +1 -0
  41. package/dist/orchestration.d.ts +43 -0
  42. package/dist/orchestration.js +12 -0
  43. package/dist/orchestration.js.map +1 -0
  44. package/dist/policy.js +1 -0
  45. package/dist/protocol.js +1 -0
  46. package/dist/pulsar.d.ts +78 -0
  47. package/dist/pulsar.js +17 -0
  48. package/dist/pulsar.js.map +1 -0
  49. package/dist/rollout-store-persistent.js +1 -0
  50. package/dist/rollout.js +1 -0
  51. package/dist/sandbox.js +1 -0
  52. package/dist/skills.js +2 -1
  53. package/dist/subagents.js +1 -0
  54. package/dist/tools.d.ts +4 -3
  55. package/dist/tools.js +5 -3
  56. package/examples/pulsar-quickstart.ts +35 -0
  57. package/examples/resume-branch.ts +45 -0
  58. package/examples/subagent-fanout.ts +20 -0
  59. package/package.json +12 -5
  60. package/src/cli.ts +49 -0
  61. package/src/context-compaction.ts +6 -2
  62. package/src/index.ts +2 -0
  63. package/src/loop.ts +2 -2
  64. package/src/mcp-bridge.ts +8 -3
  65. package/src/orchestration.test.ts +53 -0
  66. package/src/orchestration.ts +146 -0
  67. package/src/permission-ruleset.ts +1 -200
  68. package/src/pulsar.test.ts +156 -0
  69. package/src/pulsar.ts +322 -0
  70. package/src/skills.ts +30 -8
  71. package/src/tools.test.ts +12 -0
  72. package/src/tools.ts +5 -2
  73. package/tsup.config.ts +4 -1
  74. package/dist/chunk-BJBBR3QA.js.map +0 -1
  75. package/dist/chunk-NN7DATXA.js.map +0 -1
  76. package/dist/chunk-PGGWSUTM.js.map +0 -1
  77. package/dist/chunk-ZMYX5VBU.js.map +0 -1
  78. /package/dist/{chunk-5N4644PB.js.map → chunk-SD2ZJ7XG.js.map} +0 -0
@@ -4,6 +4,7 @@ import {
4
4
  onHookEvent,
5
5
  runHooks
6
6
  } from "./chunk-LO24VOA3.js";
7
+ import "./chunk-424PT5DM.js";
7
8
  export {
8
9
  fromToolHooks,
9
10
  matchesMatcher,
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { BodyLoader, CommandRecord, CommandRegistry, ContentBlock, ExpandedCommand, expandCommand } from './commands.js';
2
2
  import { z } from 'zod';
3
+ import { BaseTokenEstimator } from '@nebutra/ai-primitives';
3
4
  export { Definition, DefinitionResolver, Frontmatter, ResolveContext, SOURCE_TIERS, SourceTier, frontmatterSchema, parseFrontmatter, substituteArguments } from './definitions.js';
4
5
  export { JsonRpcResponse, MethodHandler, NotificationListener, ProtocolDispatcher } from './dispatcher.js';
5
6
  export { CreateDurableTurnDeps, DurableTurn, DurableTurnJob, DurableTurnQueuePort, DurableTurnRunner, TurnContext, createDurableTurn } from './durable-turn.js';
@@ -7,14 +8,17 @@ export { FunctionTransport, HookConfig, HookContext, HookEvent, HookExitResult,
7
8
  export { ApprovalGate, ModelEmission, ModelInvoker, ModelRoundRequest, ModelRoundResult, RuleEvaluator, RunTurnDeps, runTurn } from './loop.js';
8
9
  export { ActivateMcpToolsResult, McpServerCatalogPort, activateMcpTools } from './mcp-bridge.js';
9
10
  export { AgentMessageItem, CommandExecutionItem, ErrorItem, FileChangeItem, FileUpdateChange, McpToolCallItem, PatchApplyStatus, PatchChangeKind, ReasoningItem, RunStatus, ThreadError, ThreadEvent, ThreadEventType, ThreadItem, ThreadItemType, TodoEntry, TodoListItem, TurnConfig, TurnConfigOverrides, TurnUsage, WebSearchItem, isTurnTerminal, mergeTurnConfig } from './model.js';
11
+ export { Brief, BudgetCap, DispatchPlan, DispatchPlanOptions, DispatchStrategy, SubagentCostReport, SubagentResult, costReport, fanOutSubagents, planSubagentDispatch } from './orchestration.js';
12
+ export * from '@nebutra/execution-policy';
10
13
  export { ApprovalPolicy, CapabilityPolicy, DEFAULT_APPROVAL_POLICY, DEFAULT_CAPABILITY_POLICY, DENIED, GranularApprovalConfig, NetworkPolicyAmendment, ReviewDecision, RuleAmendment, RuleDecision, WritableRoot, approvalPolicySchema, capabilityPolicySchema, granularApprovalConfigSchema, isApproval, resolveRuleDecision, writableRootSchema } from './policy.js';
11
14
  export { METHOD_REGISTRY, MethodName, MethodSpec, NOTIFICATIONS, NotificationName, RequestEnvelope, ScopeRule, SerializationScope, ServerRequest, requestEnvelopeSchema, resolveScope, scopeKey } from './protocol.js';
15
+ export { Pulsar, PulsarBranchRecord, PulsarBuilder, PulsarDeps, PulsarEventInput, PulsarEventLogPort, PulsarThread, StartThreadOptions } from './pulsar.js';
12
16
  export { EventPersistenceMode, InMemoryRolloutStore, PERSISTED_OUTPUT_MAX_BYTES, RolloutLine, RolloutStore, ThreadProjection, isPersisted, replay, sanitizeForPersist } from './rollout.js';
13
17
  export { PersistentRolloutStore, RolloutPersistencePort, RoundTripError } from './rollout-store-persistent.js';
14
18
  export { ExternalSandbox, NoExecutorConfiguredError, REFUSING_SANDBOX, SandboxDelegationError, SandboxExecRequest, SandboxExecResult, assertSafePosture, createHttpSandbox } from './sandbox.js';
15
19
  export { ExpandContext, ExpandedSkill, SkillListing, SkillListingEntry, SkillListingOptions, SkillMessage, SkillRecord, buildSkillListing, expandSkill } from './skills.js';
16
20
  export { DeferredEnvelope, DispatchCtx, DispatchEnvelope, DispatchMode, PrepareDispatchInput, PreparedDispatch, SettleDeferredTarget, SubagentRecord, SyncEnvelope, TASK_KINDS, TASK_STATUSES, TaskKind, TaskRecord, TaskRegistry, TaskStatus, assertNotPeeking, makeDeferred, prepareDispatch, resolveSubagentTools, settleDeferred } from './subagents.js';
17
- export { McpClientLike, RegisteredTool, ToolDefinition, ToolDispatchContext, ToolHandler, ToolHooks, ToolOrigin, ToolRegistry, adaptMcpTool } from './tools.js';
21
+ export { McpClientLike, RegisteredTool, RuntimeToolRegistry, ToolDefinition, ToolDispatchContext, ToolHandler, ToolHooks, ToolOrigin, RuntimeToolRegistry as ToolRegistry, adaptMcpTool } from './tools.js';
18
22
 
19
23
  /**
20
24
  * Streaming artifact/action protocol.
@@ -711,6 +715,7 @@ declare function generateCommitMessage(args: {
711
715
  * transcript plus the injected `summarize` and `base` estimator. The transcript
712
716
  * is never mutated; every transformation builds new arrays/strings.
713
717
  */
718
+
714
719
  /** Tokenizers undercount real BPE by ~15-30%; scale the base estimate up. */
715
720
  declare const TOKEN_CORRECTION = 1.3;
716
721
  /** Fraction of the usable window the recap is allowed to occupy. */
@@ -753,7 +758,7 @@ type Transcript = readonly Message[];
753
758
  */
754
759
  type Summarize = (prompt: string) => Promise<string>;
755
760
  /** Caller-injected cheap token heuristic; defaults to chars/4. */
756
- type BaseEstimator = (text: string) => number;
761
+ type BaseEstimator = BaseTokenEstimator;
757
762
  /** The eligibility signal this module keys on (also the failure sentinel). */
758
763
  declare const COMPACT_SENTINEL = "compact";
759
764
  /**
@@ -1312,88 +1317,6 @@ declare class MemoryManager {
1312
1317
  shutdown(): Promise<void>;
1313
1318
  }
1314
1319
 
1315
- /**
1316
- * Permission ruleset evaluator.
1317
- *
1318
- * A small, pure, stateless re-expression of a two-dimensional wildcard
1319
- * permission model plus a bash-command-prefix extractor. No global state,
1320
- * no I/O, no mutation of inputs — every function is referentially transparent.
1321
- *
1322
- * The model has two independent dimensions per rule:
1323
- * - `permission` — the capability namespace (e.g. "bash", "edit", "net")
1324
- * - `pattern` — the concrete subject within that namespace
1325
- * A rule applies only when BOTH dimensions match the query via {@link wildcardMatch}.
1326
- */
1327
- /** The decision a rule yields. Unknown queries fail safe to "ask". */
1328
- type Action = "allow" | "deny" | "ask";
1329
- /** A single permission rule. Both dimensions are matched as wildcard globs. */
1330
- interface Rule {
1331
- permission: string;
1332
- pattern: string;
1333
- action: Action;
1334
- }
1335
- /** An ordered list of rules. Earlier rules take precedence. */
1336
- type Ruleset = Rule[];
1337
- /**
1338
- * Anchored full-string glob matcher.
1339
- *
1340
- * Semantics:
1341
- * - `*` matches any run of characters, including the empty run.
1342
- * - `?` matches exactly one character.
1343
- * - Every other character is matched literally (regex metacharacters in
1344
- * `pattern` carry no special meaning).
1345
- * - The match is anchored: the entire `str` must be consumed.
1346
- *
1347
- * Special rule (ported faithfully): if `pattern` ends with `" *"` (a single
1348
- * space immediately followed by `*`), that trailing ` *` is OPTIONAL. The
1349
- * pattern then matches both `"<head> <rest>"` and exactly `"<head>"` with
1350
- * nothing after it. For example `"git *"` matches `"git"` and `"git status"`.
1351
- *
1352
- * Implemented with a backtracking two-pointer scan whose `*` handling uses a
1353
- * single saved restart position, giving O(|str| * |pattern|) worst case with
1354
- * no catastrophic blow-up.
1355
- */
1356
- declare function wildcardMatch(str: string, pattern: string): boolean;
1357
- /**
1358
- * Resolve a permission query against one or more rulesets.
1359
- *
1360
- * Rulesets are concatenated in argument order (no mutation) and scanned
1361
- * front-to-back. The FIRST rule whose `permission` and `pattern` both match
1362
- * the query (via {@link wildcardMatch}) is returned. If no rule matches, a
1363
- * fail-safe default is returned: the queried permission/pattern with action
1364
- * `"ask"` (unknown → ask, never silently allow).
1365
- */
1366
- declare function evaluate(permission: string, pattern: string, ...rulesets: Ruleset[]): Rule;
1367
- /**
1368
- * Built-in command arity table. Maps a (possibly multi-word) command prefix
1369
- * to the number of leading tokens that constitute its "human-understandable
1370
- * command" for permission matching. Longest matching prefix wins.
1371
- *
1372
- * Frozen so the shared default cannot be mutated by callers.
1373
- */
1374
- declare const BUILTIN_ARITY: Readonly<Record<string, number>>;
1375
- /**
1376
- * Extract the human-understandable command from already-split, flag-free
1377
- * shell tokens.
1378
- *
1379
- * Strategy: try the longest prefix first. For `len` from `tokens.length` down
1380
- * to 1, if `tokens.slice(0, len).join(" ")` is a key in the (merged) arity
1381
- * table, return `tokens.slice(0, arity[thatPrefix])`. If the tokens are empty,
1382
- * return `[]`. Otherwise default to the first token only.
1383
- *
1384
- * `arity` is shallow-merged OVER the built-in table; neither the caller's
1385
- * object nor the built-in table is mutated.
1386
- */
1387
- declare function commandPrefix(tokens: string[], arity?: Record<string, number> | undefined): string[];
1388
- /**
1389
- * Derive the `pattern` to feed {@link evaluate} for a bash permission.
1390
- *
1391
- * Splits `command` on arbitrary whitespace, drops tokens that begin with `-`
1392
- * (flags are not conceptually part of the command identity), applies
1393
- * {@link commandPrefix}, and joins the result with single spaces.
1394
- */
1395
- declare function commandPermissionKey(command: string): string;
1396
-
1397
1320
  /**
1398
1321
  * Git-backed project repository model.
1399
1322
  *
@@ -1871,4 +1794,4 @@ declare class InMemoryProjectStore implements ProjectPersistencePort {
1871
1794
  get(tenant: string, project: string): Promise<Project | undefined>;
1872
1795
  }
1873
1796
 
1874
- export { type Action, type ActionEvent, type ActionPorts, ActionRunner, type ActionState, type ActionStatus, type AdmissionDeps, type AdmissionPolicy, type AdmissionReason, type AdmissionResult, type AllowlistMatch, type ApplyEditResult, type ArtifactEvent, type ArtifactStreamCallbacks, ArtifactStreamParser, BUDGET_RATIO, BUILTIN_ARITY, type BaseEstimator, type BuildAction, CLIP_TEXT_CHARS, CLIP_TOOL_CHARS, COMPACT_SENTINEL, CONCURRENCY, CONVERSATIONS_DIR, type ChannelAdapter, type ChannelCapabilities, ChannelGateway, type ChannelId, type ChannelMeta, ChannelRegistry, type ChatType, type Clock, CommitMessageError, type CommitRef, type CompactTranscriptInput, type CompiledAllowlist, type CompletionModel, type ConversationSummary, DEFAULT_ABORT_MS, DEFAULT_TEMPERATURE, type DataAction, type DebounceResult, type DeployState, type DeploymentCommitRef, type DeploymentRecord, type DeploymentState, DeploymentStateError, type DeploymentSummary, type DeploymentTimelineEntry, type DeploymentUiStatus, type DesignContext, type DiffFile, type DiffResult, type DistillOptions, type DistilledSkill, type DistilledSkillFrontmatter, type DistilledSkillProvenance, DuplicateChannelError, type EditBlock, type EditIntent, type EditMerger, EditType, type EligibilityOptions, type FileAction, type FileContext, type FileEntry, type FileInfo, type FileKind, type FileManifest, type FileMap, type FileMutationInput, type FuzzyMatch, type FuzzyMatchFn, type GenerateOptions, type GitContext, type GitHostPort, type GroupBinding, type Hunk, type IdMint, InMemoryProjectStore, InMemoryShareStore, InMemorySuggestionHistoryStore, type InboundAttachment, InboundDebouncer, type InboundLike, type InboundMessage, LARGE_SET, type LatestStatusInput, MAX_RETRIES, MEMORY_CONTEXT_BANNER_CLOSE, MEMORY_CONTEXT_BANNER_OPEN, METADATA_PATH, MIN_BUDGET, type MatchClassification, type MatchType, type MemoryContext, MemoryManager, type MemoryProvider, type MentionContext, type Message, type NudgeOptions, OUTPUT_TOKEN_CAP, type OutboundMessage, type OwnsRepoPredicate, type Part, type PlanAction, type Project, type ProjectDiff, type ProjectMetadata, type ProjectPersistencePort, ProjectRepo, type ProjectRepoDeps, ProjectRepoError, type ProjectRepoErrorCode, type ProjectSnapshot, REDUCE_DEPTH, type RankOptions, type RankedFuzzyResult, type RankedSuggestion, type RawScrapeResult, type ReplyOptions, type ReviewFinding, type ReviewModel, ReviewParseError, type ReviewScope, type Rule, type Ruleset, type RunQueueOptions, type ScrapeFormat, type ScrapeProvider, type SessionKeyOptions, type SessionRef, SessionShare, type SessionShareOptions, ShareDisabledError, type ShareRecord, type ShareStore, type ShareSyncEvent, type ShellAction, SnapshotHistory, type StartAction, StreamingContextScrubber, type SuggestionHistoryStore, type SuggestionItem, type SuggestionResults, type SuggestionType, type Summarize, type SyncSink, type Synthesizer, TOKEN_CORRECTION, type TenantContext, TenantMismatchError, type TextPart, type TimelineOpts, type ToolPart, type Trajectory, type TrajectoryStep, type Transcript, UnknownChannelError, type UrlBuilder, type ViewerVerdict, WorkbenchError, admitInbound, advanceState, analyzeEditIntent, appendJsonlLine, applyEditBlock, applyFileMutation, asChannelId, assertTenantContext, buildCommitPrompt, buildDistillationPrompt, buildEditInstructions, buildImprovementPrompt, buildMemoryContextBlock, buildReviewPrompt, classifyMatch, commandPermissionKey, commandPrefix, compactTranscript, compileAllowlist, computeBudget, constantTimeEquals, dedupeByText, deriveLatestStatus, deriveTimelineFromCommits, diffProjects, distillSkill, domainForCommit, emptyFileMap, emptyProjectMetadata, estimateTokens, evaluate, fallbackMerger, generateCommitMessage, getDeploymentStatus, getDeploymentTimeline, getFile, hasMention, historyCandidates, improveSkill, ingestDesignContext, isDistillable, kebab, listFiles, makeProject, matchIndices, matchIndicesCaseInsensitive, matchIndicesCaseInsensitiveIgnoreSpaces, matchWildcardPattern, matchWildcardPatternCaseInsensitive, matchesAllowlist, nextMode, normalizeScrapeResult, parseDiff, parseEditBlocks, parseFindings, parseJsonl, planEdit, rankByFuzzy, rankSuggestions, recordHistory, removeFile, renderClipped, replyTo, requiresMention, resolveBranchBase, resolveSessionKey, restore, runReview, sanitizeContext, selectFilesForEdit, setFile, shouldCompact, shouldNudgePersist, snapshot, split, stripFencedWrapper, stripFormatting, toGenerationSeed, unescapeEntities, wildcardMatch };
1797
+ export { type ActionEvent, type ActionPorts, ActionRunner, type ActionState, type ActionStatus, type AdmissionDeps, type AdmissionPolicy, type AdmissionReason, type AdmissionResult, type AllowlistMatch, type ApplyEditResult, type ArtifactEvent, type ArtifactStreamCallbacks, ArtifactStreamParser, BUDGET_RATIO, type BaseEstimator, type BuildAction, CLIP_TEXT_CHARS, CLIP_TOOL_CHARS, COMPACT_SENTINEL, CONCURRENCY, CONVERSATIONS_DIR, type ChannelAdapter, type ChannelCapabilities, ChannelGateway, type ChannelId, type ChannelMeta, ChannelRegistry, type ChatType, type Clock, CommitMessageError, type CommitRef, type CompactTranscriptInput, type CompiledAllowlist, type CompletionModel, type ConversationSummary, DEFAULT_ABORT_MS, DEFAULT_TEMPERATURE, type DataAction, type DebounceResult, type DeployState, type DeploymentCommitRef, type DeploymentRecord, type DeploymentState, DeploymentStateError, type DeploymentSummary, type DeploymentTimelineEntry, type DeploymentUiStatus, type DesignContext, type DiffFile, type DiffResult, type DistillOptions, type DistilledSkill, type DistilledSkillFrontmatter, type DistilledSkillProvenance, DuplicateChannelError, type EditBlock, type EditIntent, type EditMerger, EditType, type EligibilityOptions, type FileAction, type FileContext, type FileEntry, type FileInfo, type FileKind, type FileManifest, type FileMap, type FileMutationInput, type FuzzyMatch, type FuzzyMatchFn, type GenerateOptions, type GitContext, type GitHostPort, type GroupBinding, type Hunk, type IdMint, InMemoryProjectStore, InMemoryShareStore, InMemorySuggestionHistoryStore, type InboundAttachment, InboundDebouncer, type InboundLike, type InboundMessage, LARGE_SET, type LatestStatusInput, MAX_RETRIES, MEMORY_CONTEXT_BANNER_CLOSE, MEMORY_CONTEXT_BANNER_OPEN, METADATA_PATH, MIN_BUDGET, type MatchClassification, type MatchType, type MemoryContext, MemoryManager, type MemoryProvider, type MentionContext, type Message, type NudgeOptions, OUTPUT_TOKEN_CAP, type OutboundMessage, type OwnsRepoPredicate, type Part, type PlanAction, type Project, type ProjectDiff, type ProjectMetadata, type ProjectPersistencePort, ProjectRepo, type ProjectRepoDeps, ProjectRepoError, type ProjectRepoErrorCode, type ProjectSnapshot, REDUCE_DEPTH, type RankOptions, type RankedFuzzyResult, type RankedSuggestion, type RawScrapeResult, type ReplyOptions, type ReviewFinding, type ReviewModel, ReviewParseError, type ReviewScope, type RunQueueOptions, type ScrapeFormat, type ScrapeProvider, type SessionKeyOptions, type SessionRef, SessionShare, type SessionShareOptions, ShareDisabledError, type ShareRecord, type ShareStore, type ShareSyncEvent, type ShellAction, SnapshotHistory, type StartAction, StreamingContextScrubber, type SuggestionHistoryStore, type SuggestionItem, type SuggestionResults, type SuggestionType, type Summarize, type SyncSink, type Synthesizer, TOKEN_CORRECTION, type TenantContext, TenantMismatchError, type TextPart, type TimelineOpts, type ToolPart, type Trajectory, type TrajectoryStep, type Transcript, UnknownChannelError, type UrlBuilder, type ViewerVerdict, WorkbenchError, admitInbound, advanceState, analyzeEditIntent, appendJsonlLine, applyEditBlock, applyFileMutation, asChannelId, assertTenantContext, buildCommitPrompt, buildDistillationPrompt, buildEditInstructions, buildImprovementPrompt, buildMemoryContextBlock, buildReviewPrompt, classifyMatch, compactTranscript, compileAllowlist, computeBudget, constantTimeEquals, dedupeByText, deriveLatestStatus, deriveTimelineFromCommits, diffProjects, distillSkill, domainForCommit, emptyFileMap, emptyProjectMetadata, estimateTokens, fallbackMerger, generateCommitMessage, getDeploymentStatus, getDeploymentTimeline, getFile, hasMention, historyCandidates, improveSkill, ingestDesignContext, isDistillable, kebab, listFiles, makeProject, matchIndices, matchIndicesCaseInsensitive, matchIndicesCaseInsensitiveIgnoreSpaces, matchWildcardPattern, matchWildcardPatternCaseInsensitive, matchesAllowlist, nextMode, normalizeScrapeResult, parseDiff, parseEditBlocks, parseFindings, parseJsonl, planEdit, rankByFuzzy, rankSuggestions, recordHistory, removeFile, renderClipped, replyTo, requiresMention, resolveBranchBase, resolveSessionKey, restore, runReview, sanitizeContext, selectFilesForEdit, setFile, shouldCompact, shouldNudgePersist, snapshot, split, stripFencedWrapper, stripFormatting, toGenerationSeed, unescapeEntities };
package/dist/index.js CHANGED
@@ -1,3 +1,8 @@
1
+ import {
2
+ Pulsar,
3
+ PulsarBuilder,
4
+ PulsarThread
5
+ } from "./chunk-KCNN4QUQ.js";
1
6
  import {
2
7
  PersistentRolloutStore,
3
8
  RoundTripError
@@ -12,7 +17,7 @@ import {
12
17
  import {
13
18
  buildSkillListing,
14
19
  expandSkill
15
- } from "./chunk-ZMYX5VBU.js";
20
+ } from "./chunk-GQZKYWFT.js";
16
21
  import {
17
22
  TASK_KINDS,
18
23
  TASK_STATUSES,
@@ -23,9 +28,19 @@ import {
23
28
  resolveSubagentTools,
24
29
  settleDeferred
25
30
  } from "./chunk-5YS7WAPS.js";
31
+ import {
32
+ ProtocolDispatcher
33
+ } from "./chunk-RDKYDMXT.js";
34
+ import {
35
+ METHOD_REGISTRY,
36
+ NOTIFICATIONS,
37
+ requestEnvelopeSchema,
38
+ resolveScope,
39
+ scopeKey
40
+ } from "./chunk-FUG5DT2C.js";
26
41
  import {
27
42
  createDurableTurn
28
- } from "./chunk-5N4644PB.js";
43
+ } from "./chunk-SD2ZJ7XG.js";
29
44
  import {
30
45
  fromToolHooks,
31
46
  matchesMatcher,
@@ -34,18 +49,30 @@ import {
34
49
  } from "./chunk-LO24VOA3.js";
35
50
  import {
36
51
  runTurn
37
- } from "./chunk-BJBBR3QA.js";
52
+ } from "./chunk-D4YAPLOW.js";
53
+ import {
54
+ InMemoryRolloutStore,
55
+ PERSISTED_OUTPUT_MAX_BYTES,
56
+ isPersisted,
57
+ replay,
58
+ sanitizeForPersist
59
+ } from "./chunk-37BBB2P2.js";
38
60
  import {
39
61
  activateMcpTools
40
- } from "./chunk-PGGWSUTM.js";
62
+ } from "./chunk-NI4EDT4T.js";
41
63
  import {
42
- ToolRegistry,
64
+ RuntimeToolRegistry,
43
65
  adaptMcpTool
44
- } from "./chunk-NN7DATXA.js";
66
+ } from "./chunk-4Y25ZTKI.js";
45
67
  import {
46
68
  isTurnTerminal,
47
69
  mergeTurnConfig
48
70
  } from "./chunk-6EGG2OZC.js";
71
+ import {
72
+ costReport,
73
+ fanOutSubagents,
74
+ planSubagentDispatch
75
+ } from "./chunk-MX2WL43P.js";
49
76
  import {
50
77
  DEFAULT_APPROVAL_POLICY,
51
78
  DEFAULT_CAPABILITY_POLICY,
@@ -57,13 +84,6 @@ import {
57
84
  resolveRuleDecision,
58
85
  writableRootSchema
59
86
  } from "./chunk-CGRCUKGT.js";
60
- import {
61
- InMemoryRolloutStore,
62
- PERSISTED_OUTPUT_MAX_BYTES,
63
- isPersisted,
64
- replay,
65
- sanitizeForPersist
66
- } from "./chunk-37BBB2P2.js";
67
87
  import {
68
88
  CommandRegistry,
69
89
  expandCommand
@@ -76,15 +96,192 @@ import {
76
96
  substituteArguments
77
97
  } from "./chunk-7BUOF367.js";
78
98
  import {
79
- ProtocolDispatcher
80
- } from "./chunk-RDKYDMXT.js";
81
- import {
82
- METHOD_REGISTRY,
83
- NOTIFICATIONS,
84
- requestEnvelopeSchema,
85
- resolveScope,
86
- scopeKey
87
- } from "./chunk-FUG5DT2C.js";
99
+ __export,
100
+ __reExport
101
+ } from "./chunk-424PT5DM.js";
102
+
103
+ // src/index.ts
104
+ var src_exports = {};
105
+ __export(src_exports, {
106
+ ActionRunner: () => ActionRunner,
107
+ ArtifactStreamParser: () => ArtifactStreamParser,
108
+ BUDGET_RATIO: () => BUDGET_RATIO,
109
+ CLIP_TEXT_CHARS: () => CLIP_TEXT_CHARS,
110
+ CLIP_TOOL_CHARS: () => CLIP_TOOL_CHARS,
111
+ COMPACT_SENTINEL: () => COMPACT_SENTINEL,
112
+ CONCURRENCY: () => CONCURRENCY,
113
+ CONVERSATIONS_DIR: () => CONVERSATIONS_DIR,
114
+ ChannelGateway: () => ChannelGateway,
115
+ ChannelRegistry: () => ChannelRegistry,
116
+ CommandRegistry: () => CommandRegistry,
117
+ CommitMessageError: () => CommitMessageError,
118
+ DEFAULT_ABORT_MS: () => DEFAULT_ABORT_MS,
119
+ DEFAULT_APPROVAL_POLICY: () => DEFAULT_APPROVAL_POLICY,
120
+ DEFAULT_CAPABILITY_POLICY: () => DEFAULT_CAPABILITY_POLICY,
121
+ DEFAULT_TEMPERATURE: () => DEFAULT_TEMPERATURE,
122
+ DENIED: () => DENIED,
123
+ DefinitionResolver: () => DefinitionResolver,
124
+ DeploymentStateError: () => DeploymentStateError,
125
+ DuplicateChannelError: () => DuplicateChannelError,
126
+ EditType: () => EditType,
127
+ InMemoryProjectStore: () => InMemoryProjectStore,
128
+ InMemoryRolloutStore: () => InMemoryRolloutStore,
129
+ InMemoryShareStore: () => InMemoryShareStore,
130
+ InMemorySuggestionHistoryStore: () => InMemorySuggestionHistoryStore,
131
+ InboundDebouncer: () => InboundDebouncer,
132
+ LARGE_SET: () => LARGE_SET,
133
+ MAX_RETRIES: () => MAX_RETRIES,
134
+ MEMORY_CONTEXT_BANNER_CLOSE: () => MEMORY_CONTEXT_BANNER_CLOSE,
135
+ MEMORY_CONTEXT_BANNER_OPEN: () => MEMORY_CONTEXT_BANNER_OPEN,
136
+ METADATA_PATH: () => METADATA_PATH,
137
+ METHOD_REGISTRY: () => METHOD_REGISTRY,
138
+ MIN_BUDGET: () => MIN_BUDGET,
139
+ MemoryManager: () => MemoryManager,
140
+ NOTIFICATIONS: () => NOTIFICATIONS,
141
+ NoExecutorConfiguredError: () => NoExecutorConfiguredError,
142
+ OUTPUT_TOKEN_CAP: () => OUTPUT_TOKEN_CAP,
143
+ PERSISTED_OUTPUT_MAX_BYTES: () => PERSISTED_OUTPUT_MAX_BYTES,
144
+ PersistentRolloutStore: () => PersistentRolloutStore,
145
+ ProjectRepo: () => ProjectRepo,
146
+ ProjectRepoError: () => ProjectRepoError,
147
+ ProtocolDispatcher: () => ProtocolDispatcher,
148
+ Pulsar: () => Pulsar,
149
+ PulsarBuilder: () => PulsarBuilder,
150
+ PulsarThread: () => PulsarThread,
151
+ REDUCE_DEPTH: () => REDUCE_DEPTH,
152
+ REFUSING_SANDBOX: () => REFUSING_SANDBOX,
153
+ ReviewParseError: () => ReviewParseError,
154
+ RoundTripError: () => RoundTripError,
155
+ RuntimeToolRegistry: () => RuntimeToolRegistry,
156
+ SOURCE_TIERS: () => SOURCE_TIERS,
157
+ SandboxDelegationError: () => SandboxDelegationError,
158
+ SessionShare: () => SessionShare,
159
+ ShareDisabledError: () => ShareDisabledError,
160
+ SnapshotHistory: () => SnapshotHistory,
161
+ StreamingContextScrubber: () => StreamingContextScrubber,
162
+ TASK_KINDS: () => TASK_KINDS,
163
+ TASK_STATUSES: () => TASK_STATUSES,
164
+ TOKEN_CORRECTION: () => TOKEN_CORRECTION,
165
+ TaskRegistry: () => TaskRegistry,
166
+ TenantMismatchError: () => TenantMismatchError,
167
+ ToolRegistry: () => RuntimeToolRegistry,
168
+ UnknownChannelError: () => UnknownChannelError,
169
+ WorkbenchError: () => WorkbenchError,
170
+ activateMcpTools: () => activateMcpTools,
171
+ adaptMcpTool: () => adaptMcpTool,
172
+ admitInbound: () => admitInbound,
173
+ advanceState: () => advanceState,
174
+ analyzeEditIntent: () => analyzeEditIntent,
175
+ appendJsonlLine: () => appendJsonlLine,
176
+ applyEditBlock: () => applyEditBlock,
177
+ applyFileMutation: () => applyFileMutation,
178
+ approvalPolicySchema: () => approvalPolicySchema,
179
+ asChannelId: () => asChannelId,
180
+ assertNotPeeking: () => assertNotPeeking,
181
+ assertSafePosture: () => assertSafePosture,
182
+ assertTenantContext: () => assertTenantContext,
183
+ buildCommitPrompt: () => buildCommitPrompt,
184
+ buildDistillationPrompt: () => buildDistillationPrompt,
185
+ buildEditInstructions: () => buildEditInstructions,
186
+ buildImprovementPrompt: () => buildImprovementPrompt,
187
+ buildMemoryContextBlock: () => buildMemoryContextBlock,
188
+ buildReviewPrompt: () => buildReviewPrompt,
189
+ buildSkillListing: () => buildSkillListing,
190
+ capabilityPolicySchema: () => capabilityPolicySchema,
191
+ classifyMatch: () => classifyMatch,
192
+ compactTranscript: () => compactTranscript,
193
+ compileAllowlist: () => compileAllowlist,
194
+ computeBudget: () => computeBudget,
195
+ constantTimeEquals: () => constantTimeEquals,
196
+ costReport: () => costReport,
197
+ createDurableTurn: () => createDurableTurn,
198
+ createHttpSandbox: () => createHttpSandbox,
199
+ dedupeByText: () => dedupeByText,
200
+ deriveLatestStatus: () => deriveLatestStatus,
201
+ deriveTimelineFromCommits: () => deriveTimelineFromCommits,
202
+ diffProjects: () => diffProjects,
203
+ distillSkill: () => distillSkill,
204
+ domainForCommit: () => domainForCommit,
205
+ emptyFileMap: () => emptyFileMap,
206
+ emptyProjectMetadata: () => emptyProjectMetadata,
207
+ estimateTokens: () => estimateTokens,
208
+ expandCommand: () => expandCommand,
209
+ expandSkill: () => expandSkill,
210
+ fallbackMerger: () => fallbackMerger,
211
+ fanOutSubagents: () => fanOutSubagents,
212
+ fromToolHooks: () => fromToolHooks,
213
+ frontmatterSchema: () => frontmatterSchema,
214
+ generateCommitMessage: () => generateCommitMessage,
215
+ getDeploymentStatus: () => getDeploymentStatus,
216
+ getDeploymentTimeline: () => getDeploymentTimeline,
217
+ getFile: () => getFile,
218
+ granularApprovalConfigSchema: () => granularApprovalConfigSchema,
219
+ hasMention: () => hasMention,
220
+ historyCandidates: () => historyCandidates,
221
+ improveSkill: () => improveSkill,
222
+ ingestDesignContext: () => ingestDesignContext,
223
+ isApproval: () => isApproval,
224
+ isDistillable: () => isDistillable,
225
+ isPersisted: () => isPersisted,
226
+ isTurnTerminal: () => isTurnTerminal,
227
+ kebab: () => kebab,
228
+ listFiles: () => listFiles,
229
+ makeDeferred: () => makeDeferred,
230
+ makeProject: () => makeProject,
231
+ matchIndices: () => matchIndices,
232
+ matchIndicesCaseInsensitive: () => matchIndicesCaseInsensitive,
233
+ matchIndicesCaseInsensitiveIgnoreSpaces: () => matchIndicesCaseInsensitiveIgnoreSpaces,
234
+ matchWildcardPattern: () => matchWildcardPattern,
235
+ matchWildcardPatternCaseInsensitive: () => matchWildcardPatternCaseInsensitive,
236
+ matchesAllowlist: () => matchesAllowlist,
237
+ matchesMatcher: () => matchesMatcher,
238
+ mergeTurnConfig: () => mergeTurnConfig,
239
+ nextMode: () => nextMode,
240
+ normalizeScrapeResult: () => normalizeScrapeResult,
241
+ onHookEvent: () => onHookEvent,
242
+ parseDiff: () => parseDiff,
243
+ parseEditBlocks: () => parseEditBlocks,
244
+ parseFindings: () => parseFindings,
245
+ parseFrontmatter: () => parseFrontmatter,
246
+ parseJsonl: () => parseJsonl,
247
+ planEdit: () => planEdit,
248
+ planSubagentDispatch: () => planSubagentDispatch,
249
+ prepareDispatch: () => prepareDispatch,
250
+ rankByFuzzy: () => rankByFuzzy,
251
+ rankSuggestions: () => rankSuggestions,
252
+ recordHistory: () => recordHistory,
253
+ removeFile: () => removeFile,
254
+ renderClipped: () => renderClipped,
255
+ replay: () => replay,
256
+ replyTo: () => replyTo,
257
+ requestEnvelopeSchema: () => requestEnvelopeSchema,
258
+ requiresMention: () => requiresMention,
259
+ resolveBranchBase: () => resolveBranchBase,
260
+ resolveRuleDecision: () => resolveRuleDecision,
261
+ resolveScope: () => resolveScope,
262
+ resolveSessionKey: () => resolveSessionKey,
263
+ resolveSubagentTools: () => resolveSubagentTools,
264
+ restore: () => restore,
265
+ runHooks: () => runHooks,
266
+ runReview: () => runReview,
267
+ runTurn: () => runTurn,
268
+ sanitizeContext: () => sanitizeContext,
269
+ sanitizeForPersist: () => sanitizeForPersist,
270
+ scopeKey: () => scopeKey,
271
+ selectFilesForEdit: () => selectFilesForEdit,
272
+ setFile: () => setFile,
273
+ settleDeferred: () => settleDeferred,
274
+ shouldCompact: () => shouldCompact,
275
+ shouldNudgePersist: () => shouldNudgePersist,
276
+ snapshot: () => snapshot,
277
+ split: () => split,
278
+ stripFencedWrapper: () => stripFencedWrapper,
279
+ stripFormatting: () => stripFormatting,
280
+ substituteArguments: () => substituteArguments,
281
+ toGenerationSeed: () => toGenerationSeed,
282
+ unescapeEntities: () => unescapeEntities,
283
+ writableRootSchema: () => writableRootSchema
284
+ });
88
285
 
89
286
  // src/artifact-stream.ts
90
287
  import { z } from "zod";
@@ -1068,6 +1265,9 @@ async function generateCommitMessage(args) {
1068
1265
  }
1069
1266
 
1070
1267
  // src/context-compaction.ts
1268
+ import {
1269
+ estimateTokens as estimatePrimitiveTokens
1270
+ } from "@nebutra/ai-primitives";
1071
1271
  import { z as z6 } from "zod";
1072
1272
  var TOKEN_CORRECTION = 1.3;
1073
1273
  var BUDGET_RATIO = 0.6;
@@ -1099,7 +1299,7 @@ var compactInputSchema = z6.object({
1099
1299
  usableTokens: z6.number().int().positive()
1100
1300
  });
1101
1301
  function estimateTokens(text, base = defaultBase) {
1102
- return Math.ceil(base(text) * TOKEN_CORRECTION);
1302
+ return estimatePrimitiveTokens(text, { base, correction: TOKEN_CORRECTION });
1103
1303
  }
1104
1304
  function computeBudget(usableTokens) {
1105
1305
  return Math.max(MIN_BUDGET, Math.floor(usableTokens * BUDGET_RATIO));
@@ -2148,96 +2348,12 @@ var MemoryManager = class {
2148
2348
  };
2149
2349
 
2150
2350
  // src/permission-ruleset.ts
2151
- function wildcardMatch(str, pattern) {
2152
- if (isOptionalTrailingStar(pattern)) {
2153
- const head = pattern.slice(0, -2);
2154
- if (globMatch2(str, head)) {
2155
- return true;
2156
- }
2157
- return globMatch2(str, pattern);
2158
- }
2159
- return globMatch2(str, pattern);
2160
- }
2161
- function isOptionalTrailingStar(pattern) {
2162
- return pattern.length >= 2 && pattern.endsWith(" *");
2163
- }
2164
- function globMatch2(str, pattern) {
2165
- let s = 0;
2166
- let p = 0;
2167
- let starP = -1;
2168
- let starS = 0;
2169
- while (s < str.length) {
2170
- const pc = p < pattern.length ? pattern[p] : void 0;
2171
- if (pc === "*") {
2172
- starP = p;
2173
- starS = s;
2174
- p += 1;
2175
- } else if (pc === "?" || pc === str[s]) {
2176
- p += 1;
2177
- s += 1;
2178
- } else if (starP !== -1) {
2179
- p = starP + 1;
2180
- starS += 1;
2181
- s = starS;
2182
- } else {
2183
- return false;
2184
- }
2185
- }
2186
- while (p < pattern.length && pattern[p] === "*") {
2187
- p += 1;
2188
- }
2189
- return p === pattern.length;
2190
- }
2191
- function evaluate(permission, pattern, ...rulesets) {
2192
- for (const ruleset of rulesets) {
2193
- for (const rule of ruleset) {
2194
- if (wildcardMatch(permission, rule.permission) && wildcardMatch(pattern, rule.pattern)) {
2195
- return rule;
2196
- }
2197
- }
2198
- }
2199
- return { permission, pattern: "*", action: "ask" };
2200
- }
2201
- var BUILTIN_ARITY = Object.freeze({
2202
- git: 2,
2203
- npm: 2,
2204
- "npm run": 3,
2205
- docker: 2,
2206
- kubectl: 2,
2207
- cargo: 2,
2208
- pnpm: 2,
2209
- yarn: 2,
2210
- go: 2,
2211
- ls: 1,
2212
- cat: 1,
2213
- cd: 1,
2214
- rm: 1,
2215
- cp: 1,
2216
- mv: 1,
2217
- mkdir: 1,
2218
- echo: 1,
2219
- grep: 1,
2220
- python: 1,
2221
- node: 1
2222
- });
2223
- function commandPrefix(tokens, arity) {
2224
- if (tokens.length === 0) {
2225
- return [];
2226
- }
2227
- const table = { ...BUILTIN_ARITY, ...arity ?? {} };
2228
- for (let len = tokens.length; len >= 1; len -= 1) {
2229
- const prefixKey = tokens.slice(0, len).join(" ");
2230
- const take = table[prefixKey];
2231
- if (take !== void 0) {
2232
- return tokens.slice(0, Math.min(take, tokens.length));
2233
- }
2234
- }
2235
- return tokens.slice(0, 1);
2236
- }
2237
- function commandPermissionKey(command) {
2238
- const tokens = command.split(/\s+/).filter((token) => token.length > 0 && !token.startsWith("-"));
2239
- return commandPrefix(tokens).join(" ");
2240
- }
2351
+ var permission_ruleset_exports = {};
2352
+ __reExport(permission_ruleset_exports, execution_policy_star);
2353
+ import * as execution_policy_star from "@nebutra/execution-policy";
2354
+
2355
+ // src/index.ts
2356
+ __reExport(src_exports, permission_ruleset_exports);
2241
2357
 
2242
2358
  // src/project-repo.ts
2243
2359
  import { z as z12 } from "zod";
@@ -2940,7 +3056,6 @@ export {
2940
3056
  ActionRunner,
2941
3057
  ArtifactStreamParser,
2942
3058
  BUDGET_RATIO,
2943
- BUILTIN_ARITY,
2944
3059
  CLIP_TEXT_CHARS,
2945
3060
  CLIP_TOOL_CHARS,
2946
3061
  COMPACT_SENTINEL,
@@ -2980,10 +3095,14 @@ export {
2980
3095
  ProjectRepo,
2981
3096
  ProjectRepoError,
2982
3097
  ProtocolDispatcher,
3098
+ Pulsar,
3099
+ PulsarBuilder,
3100
+ PulsarThread,
2983
3101
  REDUCE_DEPTH,
2984
3102
  REFUSING_SANDBOX,
2985
3103
  ReviewParseError,
2986
3104
  RoundTripError,
3105
+ RuntimeToolRegistry,
2987
3106
  SOURCE_TIERS,
2988
3107
  SandboxDelegationError,
2989
3108
  SessionShare,
@@ -2995,7 +3114,7 @@ export {
2995
3114
  TOKEN_CORRECTION,
2996
3115
  TaskRegistry,
2997
3116
  TenantMismatchError,
2998
- ToolRegistry,
3117
+ RuntimeToolRegistry as ToolRegistry,
2999
3118
  UnknownChannelError,
3000
3119
  WorkbenchError,
3001
3120
  activateMcpTools,
@@ -3020,12 +3139,11 @@ export {
3020
3139
  buildSkillListing,
3021
3140
  capabilityPolicySchema,
3022
3141
  classifyMatch,
3023
- commandPermissionKey,
3024
- commandPrefix,
3025
3142
  compactTranscript,
3026
3143
  compileAllowlist,
3027
3144
  computeBudget,
3028
3145
  constantTimeEquals,
3146
+ costReport,
3029
3147
  createDurableTurn,
3030
3148
  createHttpSandbox,
3031
3149
  dedupeByText,
@@ -3037,10 +3155,10 @@ export {
3037
3155
  emptyFileMap,
3038
3156
  emptyProjectMetadata,
3039
3157
  estimateTokens,
3040
- evaluate,
3041
3158
  expandCommand,
3042
3159
  expandSkill,
3043
3160
  fallbackMerger,
3161
+ fanOutSubagents,
3044
3162
  fromToolHooks,
3045
3163
  frontmatterSchema,
3046
3164
  generateCommitMessage,
@@ -3077,6 +3195,7 @@ export {
3077
3195
  parseFrontmatter,
3078
3196
  parseJsonl,
3079
3197
  planEdit,
3198
+ planSubagentDispatch,
3080
3199
  prepareDispatch,
3081
3200
  rankByFuzzy,
3082
3201
  rankSuggestions,
@@ -3111,7 +3230,6 @@ export {
3111
3230
  substituteArguments,
3112
3231
  toGenerationSeed,
3113
3232
  unescapeEntities,
3114
- wildcardMatch,
3115
3233
  writableRootSchema
3116
3234
  };
3117
3235
  //# sourceMappingURL=index.js.map