@felan-ai/ext-powerline 0.13.0 → 0.14.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 (58) hide show
  1. package/README.md +87 -58
  2. package/dist/config.d.ts +4 -51
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/config.js +7 -184
  5. package/dist/config.js.map +1 -1
  6. package/dist/core-services.d.ts +5 -0
  7. package/dist/core-services.d.ts.map +1 -0
  8. package/dist/core-services.js +66 -0
  9. package/dist/core-services.js.map +1 -0
  10. package/dist/data.d.ts +60 -0
  11. package/dist/data.d.ts.map +1 -0
  12. package/dist/data.js +40 -0
  13. package/dist/data.js.map +1 -0
  14. package/dist/extension.d.ts +7 -0
  15. package/dist/extension.d.ts.map +1 -0
  16. package/dist/extension.js +23 -0
  17. package/dist/extension.js.map +1 -0
  18. package/dist/generic.d.ts +8 -0
  19. package/dist/generic.d.ts.map +1 -0
  20. package/dist/generic.js +130 -0
  21. package/dist/generic.js.map +1 -0
  22. package/dist/git.d.ts +7 -2
  23. package/dist/git.d.ts.map +1 -1
  24. package/dist/git.js +32 -8
  25. package/dist/git.js.map +1 -1
  26. package/dist/index.d.ts +5 -29
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +5 -142
  29. package/dist/index.js.map +1 -1
  30. package/dist/runtime.d.ts +32 -0
  31. package/dist/runtime.d.ts.map +1 -0
  32. package/dist/runtime.js +215 -0
  33. package/dist/runtime.js.map +1 -0
  34. package/dist/subscription.d.ts +7 -5
  35. package/dist/subscription.d.ts.map +1 -1
  36. package/dist/subscription.js +81 -15
  37. package/dist/subscription.js.map +1 -1
  38. package/dist/usage.d.ts +4 -0
  39. package/dist/usage.d.ts.map +1 -0
  40. package/dist/usage.js +20 -0
  41. package/dist/usage.js.map +1 -0
  42. package/package.json +20 -10
  43. package/dist/colors.d.ts +0 -18
  44. package/dist/colors.d.ts.map +0 -1
  45. package/dist/colors.js +0 -42
  46. package/dist/colors.js.map +0 -1
  47. package/dist/footer.d.ts +0 -37
  48. package/dist/footer.d.ts.map +0 -1
  49. package/dist/footer.js +0 -146
  50. package/dist/footer.js.map +0 -1
  51. package/dist/segments.d.ts +0 -39
  52. package/dist/segments.d.ts.map +0 -1
  53. package/dist/segments.js +0 -344
  54. package/dist/segments.js.map +0 -1
  55. package/dist/symbols.d.ts +0 -27
  56. package/dist/symbols.d.ts.map +0 -1
  57. package/dist/symbols.js +0 -17
  58. package/dist/symbols.js.map +0 -1
package/README.md CHANGED
@@ -1,46 +1,63 @@
1
1
  # @felan-ai/ext-powerline
2
2
 
3
- Portable ANSI-aware TUI footer extension targeting Pi. The local Felan
4
- TUI enables it by default and binds a host that can display Codex, Claude, or
5
- Grok subscription usage; the package itself is hostless by default.
3
+ Portable Powerline data for client-owned footers. The package
4
+ root publishes generic `pi.ui` views and typed statuses in TUI, ACP, and headless
5
+ sessions without requiring a presentation service. Optional usage providers add
6
+ Codex, Claude, or Grok subscription usage and estimated savings. Footer
7
+ construction remains client-side.
6
8
 
7
- The footer displays:
9
+ Published data includes:
8
10
 
9
11
  - current directory
10
12
  - cached Git branch, revision, working-tree status, tag, age, stash, upstream, and repository name
11
13
  - active model and thinking level
12
- - session token and cost totals (the local Felan TUI includes the root session
13
- and local subagent sessions; hostless consumers use the active session only)
14
+ - session token and cost totals (a configured usage provider can include root
15
+ and child sessions; without one, totals cover the active session only)
14
16
  - active Codex, Claude, or Grok subscription usage
15
17
  - estimated API-equivalent Felan savings for the configured recent-day period
16
18
  - context-window usage
17
- - statuses published by other Pi extensions
18
- - the Felan version when enabled by the host application
19
+ - the Felan version when supplied by the host application
20
+
21
+ Clients choose formatting, symbols, layout, styles, charsets and colors. Git probes
22
+ are asynchronous, cached, coalesced, time-bounded, and executed exclusively
23
+ through `pi.exec`.
24
+
25
+ The default entry publishes on `session_start` and refreshes for model,
26
+ thinking, agent, turn, tool, compaction, tree, and usage events, plus a 60-second refresh. Its generic
27
+ views publish structured segment values, semantic kinds and color roles, without
28
+ preformatted footer text, symbols, style or layout. Session
29
+ and context metrics also use typed token, percent, and USD statuses. The
30
+ optional `felan.powerline@3.0.0` hint changes presentation only; clients without
31
+ it can display the same columns, rows, and values. Other extensions' common UI
32
+ statuses remain separately available to clients rather than being copied into
33
+ Powerline through a feature service.
34
+
35
+ Shutdown aborts Git probes, usage requests, and pending publication requests,
36
+ joins owned work, closes views, and removes statuses. A failed publication stops
37
+ refresh timers and preserves a sanitized cleanup failure. Felan's client installs
38
+ the optional footer; the extension never constructs terminal components.
39
+
40
+ Semantic color roles let clients apply their own themes; the extension owns no
41
+ terminal palette or theme settings.
19
42
 
20
- Rendering is ANSI-width-aware and supports left/right alignment, wrapping,
21
- `minimal`, `powerline`, and `capsule` styles, plus text and Powerline Unicode
22
- charsets. Git probes are asynchronous, cached, coalesced, time-bounded, and
23
- executed exclusively through `pi.exec`.
24
-
25
- The extension installs its footer on `session_start` only when `ctx.mode` is
26
- `tui`, redraws for model, thinking, agent, turn, tool, compaction, tree, usage,
27
- and Git branch changes, and removes and disposes the footer on
28
- `session_shutdown`. Headless Pi modes perform no footer, Git, or subscription
29
- work.
43
+ ## Configuration
30
44
 
31
- Powerline inherits the active Pi theme. Segment roles use Pi semantic color
32
- tokens, so changing the TUI theme also changes the footer; Powerline does not
33
- maintain a second palette or color compatibility setting.
45
+ The extension declares only data-collection settings under `extensionConfig.powerline`:
34
46
 
35
- ## Configuration
47
+ ```json
48
+ { "showWorkingTree": true, "showStashCount": false, "periodDays": 7, "maxWindows": 3 }
49
+ ```
36
50
 
37
- All configuration is supplied through the declarative `powerline` extension
38
- settings. The settings include scalar display fields and ordered `lines` with
39
- supported segment objects. Theme selection and colors belong to Pi.
51
+ Felan's TUI owns style, charset, wrapping, padding, ordered lines, alignment,
52
+ color roles and per-segment display choices under `presentation.powerline` in
53
+ `$FELAN_AGENT_DIR/tui/settings.json`. It reads released display settings as a
54
+ read-only fallback. These preferences never configure the daemon. `/settings`
55
+ separates display preferences from execution settings; the old display CLI flags
56
+ remain TUI-only launch overrides.
40
57
 
41
- The optional `version` segment displays the Felan version supplied by the host.
42
- It is not enabled by the package default; hostless consumers omit it when no
43
- version is provided. Felan's local TUI supplies its current application version.
58
+ The extension publishes a `version` value when the host supplies one. Clients
59
+ decide whether and where to display it. The default Felan TUI footer does not
60
+ include a version segment.
44
61
 
45
62
  The `subscription` segment supports native OpenAI ChatGPT, Codex, Claude, and
46
63
  Grok SuperGrok / X Premium OAuth plans. ChatGPT, Codex, and Grok values show
@@ -48,16 +65,16 @@ remaining percentage; Claude values show used percentage. Native OpenAI usage
48
65
  requires both an OpenAI ChatGPT OAuth login and a separate Codex OAuth login
49
66
  for the same ChatGPT account/workspace (`/login openai-codex`). ChatGPT values
50
67
  show shared-plan primary/secondary windows only; app-specific quotas are not
51
- displayed. The TUI uses Codex credentials only for the companion ChatGPT usage
68
+ displayed. The host uses Codex credentials only for the companion ChatGPT usage
52
69
  endpoints; it never sends native OpenAI tokens to ChatGPT backend endpoints.
53
70
  These companion endpoints are undocumented. If the Codex companion is missing
54
- or its app registration cannot be matched, the footer displays
71
+ or its app registration cannot be matched, the published data reports companion unavailability; clients can display
55
72
  `ChatGPT usage: web only`; users can review usage at
56
73
  <https://chatgpt.com/settings/usage>. App-registration matching is a safeguard,
57
74
  not independent proof that the accounts match. Native OpenAI usage is
58
75
  session-local and is not persisted/shared with Codex usage. The segment can
59
76
  configure `showProviderName`, `showReset`,
60
- `showPercentage`, and `maxWindows`. It refreshes at startup, after turns and
77
+ `showPercentage` in the TUI. Extension `maxWindows` bounds published windows. It refreshes at startup, after turns and
61
78
  model changes, and once per minute. Only model changes bypass the 30-second
62
79
  minimum between requests. For Codex, Claude, and Grok, after HTTP 429 every
63
80
  refresh waits for the provider's `Retry-After` or an exponential backoff from
@@ -65,56 +82,68 @@ one minute up to 30 minutes, and the segment keeps showing the last successful
65
82
  values whose reset time has not passed. Hosts can pass a `subscriptionStore`,
66
83
  optionally backed by host-owned persistence, to share those values, the latest
67
84
  error, and the backoff across sessions, restarts, and processes. A host that coordinates processes returns
68
- `REFRESH_DEFERRED` when another process owns the refresh; the segment then shows
85
+ `REFRESH_DEFERRED` when another process owns the refresh; the extension then publishes
69
86
  the shared values. Native OpenAI values are neither persisted nor shared across
70
87
  sessions and clear to the web-only fallback when companion validation fails.
71
88
  The controller calls `releaseRefreshLease` when the model changes provider or
72
89
  the session shuts down.
73
90
 
74
- The `savings` segment is enabled by default at the end of the first line and is
91
+ Felan's TUI enables the `savings` segment by default at the end of the first line; it is
75
92
  right-aligned above the model. It reports estimated API-equivalent savings
76
93
  across all retained local Felan activity for seven inclusive UTC calendar days
77
94
  (today plus the six previous days), displayed as
78
- `Est. Savings(7d): $33.00`. Set `periodDays` on the segment to choose another
95
+ `Est. Savings(7d): $33.00`. Set extension `periodDays` to choose another
79
96
  period. A `~` before the amount means at least one measurement had unavailable
80
- pricing, so the USD total is incomplete. The local TUI supplies the host query;
97
+ pricing, so the USD total is incomplete. The configured usage provider supplies the query;
81
98
  the portable package does not access storage itself.
82
99
 
83
- Scalar display settings are available through generated `felan --powerline-*`
84
- options and `/settings`; structured `lines` values are edited as JSON in
85
- `settings.json` or `/settings`.
100
+ Display settings are available through TUI-only `felan --powerline-*`
101
+ options and `/settings`; structured `lines` values live in `tui/settings.json`.
86
102
 
87
- The package default export is hostless and renders no subscription data.
88
- Consumers enable subscription usage with
89
- `createPowerlineExtension(subscriptionUsageHost)`. The portable package owns
90
- provider detection, response parsing, caching, throttling, and rendering; the
103
+ The package default export obtains optional Models, Usage and Sessions services.
104
+ The portable package owns
105
+ provider detection, response parsing, caching, and throttling; the
91
106
  host owns credential access and provider requests.
92
107
 
93
- Hosts can supply `options.footerRows` as the second argument to append
94
- width-aware rows after the configured powerline status lines.
95
-
96
- Felan's local TUI supplies a host backed by `ModelRuntime`. It uses the active
108
+ Models whose provider is `claude-code` use session-local
109
+ `after_provider_response` headers instead of the host subscription service. The
110
+ Claude Plan reports used percentages and reset times for the five-hour and weekly
111
+ windows. Allowed overage appears as `Extra [on]`, or `Extra [active]` when the
112
+ plan is exhausted and overage remains allowed; rejected or unknown overage does
113
+ not appear as enabled. These headers do not supply extra-usage spending, so no
114
+ spending amount is inferred from the overage-included weekly window. Before the
115
+ first usage headers arrive, no usage error is reported. Header-based usage works
116
+ without the optional Models service and is neither fetched, persisted, nor
117
+ shared across sessions. Other providers continue using the host service.
118
+
119
+ A local host can supply usage backed by `ModelRuntime`. It uses the active
97
120
  provider's Felan OAuth credential and fixed Codex, Anthropic, or xAI Grok Build
98
121
  billing endpoints. The extension package does not inspect authentication files,
99
122
  receive stored credential objects, or perform network requests.
100
123
 
101
124
  ## Package boundary and requirements
102
125
 
103
- ```ts
104
- import { createPowerlineExtension } from '@felan-ai/ext-powerline';
126
+ The root uses optional Agent Core services:
105
127
 
106
- const extension = createPowerlineExtension();
107
- ```
128
+ - `felan.models@1` supplies authenticated subscription usage without exposing credentials; the provider shares caching and rate-limit backoff across sessions.
129
+ - `felan.usage@1` supplies savings summaries.
130
+ - `felan.sessions@1` supplies execution usage totals and execution change events.
131
+ - `pi.runtime.host` supplies host version metadata without exposing a runtime factory.
132
+
133
+ There is no Powerline-specific service. Omitting optional services leaves normal
134
+ session/model/context and header-based Claude Code data intact and omits unavailable subscription and
135
+ savings segments. The root exports portable runtime APIs plus the service-backed
136
+ default; `./runtime` exposes explicit runtime composition and `./data` exposes
137
+ normalized records. Neither loads footer implementations or Pi-TUI. The package
138
+ exports no TUI or view entrypoint; native footer rendering belongs to `apps/felan`.
108
139
 
109
- The package owns width-safe rendering, layout/config validation, Git-cache
110
- behavior, provider detection, response parsing, caching, and throttling. Hosts
111
- own credential access, provider requests, TUI installation, and any extra footer
112
- rows. The footer is installed only in TUI mode; headless sessions do no Git or
113
- subscription work.
140
+ The package owns data validation, Git-cache behavior, provider detection,
141
+ response parsing, caching, and throttling. Hosts own credential access and provider
142
+ requests. Clients own rendering, symbols, layout and extra footer rows; generic data collection and
143
+ publication are not gated by client mode or the presence of a footer.
114
144
 
115
- The local default can be disabled with `builtinExtensions.powerline: false` in
116
- Felan settings. The package requires a compatible `@felan-ai/agent-core` peer
117
- and Pi-TUI.
145
+ Configured hosts select this package through their extension list. The package
146
+ requires a compatible `@felan-ai/agent-core` peer.
118
147
 
119
148
  ## Development
120
149
 
package/dist/config.d.ts CHANGED
@@ -1,54 +1,7 @@
1
- export type FooterStyle = 'minimal' | 'powerline' | 'capsule';
2
- export type Charset = 'unicode' | 'text';
3
- export type DirectoryStyle = 'full' | 'fish' | 'basename';
4
- export type SessionDisplayType = 'cost' | 'tokens' | 'both' | 'breakdown';
5
- export type ContextDisplayStyle = 'text' | 'bar' | 'blocks' | 'blocks-line' | 'dots';
6
- export type SegmentAlignment = 'left' | 'right';
7
- export type SegmentName = 'directory' | 'git' | 'model' | 'session' | 'subscription' | 'savings' | 'context' | 'status' | 'version';
8
- export type ThemeColorKey = SegmentName | 'warning' | 'critical' | 'muted' | 'extensionStatus1' | 'extensionStatus2' | 'extensionStatus3' | 'extensionStatus4';
9
- export interface SegmentConfig {
10
- enabled: boolean;
11
- align?: SegmentAlignment;
12
- style?: DirectoryStyle;
13
- showSha?: boolean;
14
- showWorkingTree?: boolean;
15
- showTag?: boolean;
16
- showTimeSinceCommit?: boolean;
17
- showStashCount?: boolean;
18
- showUpstream?: boolean;
19
- showRepoName?: boolean;
20
- type?: SessionDisplayType;
21
- displayStyle?: ContextDisplayStyle;
22
- showPercentageOnly?: boolean;
23
- showTokensOnly?: boolean;
24
- showProviderName?: boolean;
25
- showReset?: boolean;
26
- showPercentage?: boolean;
27
- maxWindows?: number;
28
- periodDays?: number;
29
- width?: number;
30
- warningThreshold?: number;
31
- criticalThreshold?: number;
32
- }
33
- export interface DisplayLineConfig {
34
- segments: Partial<Record<SegmentName, SegmentConfig>>;
35
- }
36
- export interface PowerlineConfig {
37
- display: {
38
- style: FooterStyle;
39
- charset: Charset;
40
- autoWrap: boolean;
41
- padding: number;
42
- lines: DisplayLineConfig[];
43
- };
44
- }
45
- export declare const DEFAULT_CONFIG: PowerlineConfig;
46
1
  export declare const POWERLINE_CONFIG: import("@felan-ai/agent-core").ExtensionConfigDefinition<{
47
- readonly style: import("@felan-ai/agent-core").ExtensionConfigField<"minimal" | "powerline" | "capsule">;
48
- readonly charset: import("@felan-ai/agent-core").ExtensionConfigField<"unicode" | "text">;
49
- readonly autoWrap: import("@felan-ai/agent-core").ExtensionConfigField<boolean>;
50
- readonly padding: import("@felan-ai/agent-core").ExtensionConfigField<number>;
51
- readonly lines: import("@felan-ai/agent-core").ExtensionConfigField<DisplayLineConfig[]>;
2
+ readonly showWorkingTree: import("@felan-ai/agent-core").ExtensionConfigField<boolean>;
3
+ readonly showStashCount: import("@felan-ai/agent-core").ExtensionConfigField<boolean>;
4
+ readonly periodDays: import("@felan-ai/agent-core").ExtensionConfigField<number>;
5
+ readonly maxWindows: import("@felan-ai/agent-core").ExtensionConfigField<number>;
52
6
  }>;
53
- export declare function powerlineConfigFromSettings(values: Readonly<Record<string, unknown>>): PowerlineConfig;
54
7
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAC;AAC9D,MAAM,MAAM,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AACzC,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;AAC1D,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;AAC1E,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,aAAa,GAAG,MAAM,CAAC;AACrF,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,CAAC;AAChD,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,KAAK,GA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AK,EAAE,WAAW,CAAC;QACnB,OAAO,EAAE,OAAO,CAAC;QACjB,QAAQ,EAAE,OAAO,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,iBAAiB,EAAE,CAAC;KAC5B,CAAC;CACH;AAED,eAAO,MAAM,cAAc,EAAE,eA6B5B,CAAC;AAyBF,eAAO,MAAM,gBAAgB;;;;;;EAU3B,CAAC;AAEH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,eAAe,CAQtG"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gBAAgB;;;;;EAS3B,CAAC"}
package/dist/config.js CHANGED
@@ -1,189 +1,12 @@
1
1
  import { configField, defineExtensionConfig } from '@felan-ai/agent-core';
2
- export const DEFAULT_CONFIG = {
3
- display: {
4
- style: 'minimal',
5
- charset: 'text',
6
- autoWrap: true,
7
- padding: 1,
8
- lines: [
9
- {
10
- segments: {
11
- directory: { enabled: true, style: 'fish' },
12
- git: { enabled: true, showSha: false, showWorkingTree: true },
13
- savings: { enabled: true, align: 'right', periodDays: 7 },
14
- },
15
- },
16
- {
17
- segments: {
18
- context: { enabled: true, displayStyle: 'text', showTokensOnly: true },
19
- session: { enabled: true, type: 'cost' },
20
- subscription: { enabled: true, showProviderName: false, showReset: true, maxWindows: 3 },
21
- model: { enabled: true, align: 'right' },
22
- },
23
- },
24
- {
25
- segments: {
26
- status: { enabled: true },
27
- },
28
- },
29
- ],
30
- },
31
- };
32
- const STYLES = new Set(['minimal', 'powerline', 'capsule']);
33
- const CHARSETS = new Set(['unicode', 'text']);
34
- const DIRECTORY_STYLES = new Set(['full', 'fish', 'basename']);
35
- const SESSION_TYPES = new Set(['cost', 'tokens', 'both', 'breakdown']);
36
- const CONTEXT_STYLES = new Set(['text', 'bar', 'blocks', 'blocks-line', 'dots']);
37
- const ALIGNMENTS = new Set(['left', 'right']);
38
- const SEGMENT_NAMES = new Set(['directory', 'git', 'model', 'session', 'subscription', 'savings', 'context', 'status', 'version']);
39
- const BOOLEAN_SEGMENT_FIELDS = [
40
- 'showSha',
41
- 'showWorkingTree',
42
- 'showTag',
43
- 'showTimeSinceCommit',
44
- 'showStashCount',
45
- 'showUpstream',
46
- 'showRepoName',
47
- 'showPercentageOnly',
48
- 'showTokensOnly',
49
- 'showProviderName',
50
- 'showReset',
51
- 'showPercentage',
52
- ];
53
- const NUMBER_SEGMENT_FIELDS = ['maxWindows', 'periodDays', 'width', 'warningThreshold', 'criticalThreshold'];
54
2
  export const POWERLINE_CONFIG = defineExtensionConfig({
55
- id: 'powerline',
56
- title: 'Powerline',
57
- fields: {
58
- style: configField.enum(['minimal', 'powerline', 'capsule'], { default: DEFAULT_CONFIG.display.style, description: 'Powerline footer style' }),
59
- charset: configField.enum(['text', 'unicode'], { default: DEFAULT_CONFIG.display.charset, description: 'Powerline footer charset' }),
60
- autoWrap: configField.boolean({ default: DEFAULT_CONFIG.display.autoWrap, description: 'Wrap long powerline segments' }),
61
- padding: configField.number({ default: DEFAULT_CONFIG.display.padding, description: 'Horizontal segment padding', validate: validatePadding }),
62
- lines: configField.json({ default: DEFAULT_CONFIG.display.lines, description: 'Ordered powerline lines and segments', validate: validateLines }),
3
+ id: 'powerline', title: 'Powerline', fields: {
4
+ showWorkingTree: configField.boolean({ default: true, description: 'Collect Git working-tree changes' }),
5
+ showStashCount: configField.boolean({ default: false, description: 'Collect Git stash count' }),
6
+ periodDays: configField.number({ default: 7, description: 'Savings query period in days',
7
+ validate: value => Number.isSafeInteger(value) && Number(value) >= 1 && Number(value) <= 3650 ? undefined : 'must be an integer from 1 to 3650' }),
8
+ maxWindows: configField.number({ default: 3, description: 'Maximum subscription usage windows',
9
+ validate: value => Number.isSafeInteger(value) && Number(value) >= 1 && Number(value) <= 8 ? undefined : 'must be an integer from 1 to 8' }),
63
10
  },
64
11
  });
65
- export function powerlineConfigFromSettings(values) {
66
- const config = cloneConfig(DEFAULT_CONFIG);
67
- if (typeof values.style === 'string' && STYLES.has(values.style))
68
- config.display.style = values.style;
69
- if (typeof values.charset === 'string' && CHARSETS.has(values.charset))
70
- config.display.charset = values.charset;
71
- if (typeof values.autoWrap === 'boolean')
72
- config.display.autoWrap = values.autoWrap;
73
- if (typeof values.padding === 'number')
74
- config.display.padding = values.padding;
75
- if (values.lines !== undefined)
76
- config.display.lines = parseDisplayLines(values.lines);
77
- return config;
78
- }
79
- function cloneConfig(config) {
80
- return {
81
- display: {
82
- ...config.display,
83
- lines: config.display.lines.map((line) => ({
84
- segments: Object.fromEntries(Object.entries(line.segments).map(([name, segment]) => [name, segment ? { ...segment } : segment])),
85
- })),
86
- },
87
- };
88
- }
89
- function validatePadding(value) {
90
- return typeof value === 'number' && Number.isFinite(value) && value >= 0
91
- ? undefined
92
- : 'must be a finite non-negative number';
93
- }
94
- function validateLines(value) {
95
- try {
96
- parseDisplayLines(value);
97
- return undefined;
98
- }
99
- catch (error) {
100
- return errorMessage(error);
101
- }
102
- }
103
- function parseDisplayLines(value) {
104
- if (!Array.isArray(value))
105
- throw new Error('must be an array');
106
- return value.map((line, index) => parseDisplayLine(line, `lines[${index}]`));
107
- }
108
- function parseDisplayLine(value, source) {
109
- const segments = {};
110
- if (!isRecord(value))
111
- throw new Error(`${source} must be an object`);
112
- if (!isRecord(value.segments))
113
- throw new Error(`${source}.segments must be an object`);
114
- for (const [name, segment] of Object.entries(value.segments)) {
115
- if (!SEGMENT_NAMES.has(name))
116
- throw new Error(`${source}.segments contains unknown segment: ${name}`);
117
- const parsed = parseSegmentConfig(segment, `${source}.segments.${name}`);
118
- segments[name] = parsed;
119
- }
120
- return { segments };
121
- }
122
- function parseSegmentConfig(value, source) {
123
- if (!isRecord(value))
124
- throw new Error(`${source} must be an object`);
125
- const allowed = new Set(['enabled', 'align', 'style', 'type', 'displayStyle', ...BOOLEAN_SEGMENT_FIELDS, ...NUMBER_SEGMENT_FIELDS]);
126
- for (const field of Object.keys(value)) {
127
- if (!allowed.has(field))
128
- throw new Error(`${source} contains unknown field: ${field}`);
129
- }
130
- const config = {
131
- enabled: value.enabled === undefined ? true : value.enabled,
132
- };
133
- if (typeof config.enabled !== 'boolean')
134
- throw new Error(`${source}.enabled must be a boolean`);
135
- if (typeof value.align === 'string' && ALIGNMENTS.has(value.align)) {
136
- config.align = value.align;
137
- }
138
- else if (value.align !== undefined)
139
- throw new Error(`${source}.align is invalid`);
140
- if (typeof value.style === 'string' && DIRECTORY_STYLES.has(value.style)) {
141
- config.style = value.style;
142
- }
143
- else if (value.style !== undefined)
144
- throw new Error(`${source}.style is invalid`);
145
- if (typeof value.type === 'string' && SESSION_TYPES.has(value.type)) {
146
- config.type = value.type;
147
- }
148
- else if (value.type !== undefined)
149
- throw new Error(`${source}.type is invalid`);
150
- if (typeof value.displayStyle === 'string' && CONTEXT_STYLES.has(value.displayStyle)) {
151
- config.displayStyle = value.displayStyle;
152
- }
153
- else if (value.displayStyle !== undefined)
154
- throw new Error(`${source}.displayStyle is invalid`);
155
- for (const field of BOOLEAN_SEGMENT_FIELDS) {
156
- if (value[field] !== undefined && typeof value[field] !== 'boolean')
157
- throw new Error(`${source}.${field} must be a boolean`);
158
- if (typeof value[field] === 'boolean')
159
- config[field] = value[field];
160
- }
161
- for (const field of NUMBER_SEGMENT_FIELDS) {
162
- if (value[field] !== undefined && (typeof value[field] !== 'number' || !Number.isFinite(value[field])))
163
- throw new Error(`${source}.${field} must be a finite number`);
164
- if (typeof value[field] === 'number')
165
- config[field] = value[field];
166
- }
167
- if (config.periodDays !== undefined && (!Number.isSafeInteger(config.periodDays) || config.periodDays < 1 || config.periodDays > 3_650)) {
168
- throw new Error(`${source}.periodDays must be an integer from 1 to 3650`);
169
- }
170
- return config;
171
- }
172
- function findSegment(config, name) {
173
- for (const line of config.display.lines) {
174
- const segment = line.segments[name];
175
- if (segment)
176
- return segment;
177
- }
178
- return undefined;
179
- }
180
- function isRecord(value) {
181
- return typeof value === 'object' && value !== null && !Array.isArray(value);
182
- }
183
- function isNodeError(error) {
184
- return error instanceof Error && 'code' in error;
185
- }
186
- function errorMessage(error) {
187
- return error instanceof Error ? error.message : String(error);
188
- }
189
12
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAkD1E,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC7C,OAAO,EAAE;QACP,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE,CAAC;QACV,KAAK,EAAE;YACL;gBACE,QAAQ,EAAE;oBACR,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE;oBAC3C,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE;oBAC7D,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE;iBAC1D;aACF;YACD;gBACE,QAAQ,EAAE;oBACR,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE;oBACtE,OAAO,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE;oBACxC,YAAY,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE;oBACxF,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE;iBACzC;aACF;YACD;gBACE,QAAQ,EAAE;o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,CAAC"}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE1E,MAAM,CAAC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;IACpD,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE;QAC3C,eAAe,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,kCAAkC,EAAE,CAAC;QACxG,cAAc,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,yBAAyB,EAAE,CAAC;QAC/F,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,8BAA8B;YACtF,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,mCAAmC,EAAE,CAAC;QACpJ,UAAU,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,oCAAoC;YAC5F,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,gCAAgC,EAAE,CAAC;KAC/I;CACF,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { SessionsService, UsageService } from '@felan-ai/agent-core';
2
+ import type { PowerlineRuntimeOptions } from './runtime.js';
3
+ export declare function createSavingsUsage(usage: UsageService): NonNullable<PowerlineRuntimeOptions['savingsHost']>;
4
+ export declare function createSessionUsage(sessions: SessionsService): NonNullable<PowerlineRuntimeOptions['additionalSessionUsageHost']>;
5
+ //# sourceMappingURL=core-services.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-services.d.ts","sourceRoot":"","sources":["../src/core-services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAG5D,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CAAC,uBAAuB,CAAC,aAAa,CAAC,CAAC,CAS3G;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,eAAe,GAAG,WAAW,CAAC,uBAAuB,CAAC,4BAA4B,CAAC,CAAC,CA0ChI"}
@@ -0,0 +1,66 @@
1
+ export function createSavingsUsage(usage) {
2
+ return {
3
+ query({ periodDays, signal }) {
4
+ const to = new Date();
5
+ const from = new Date(Date.UTC(to.getUTCFullYear(), to.getUTCMonth(), to.getUTCDate()));
6
+ from.setUTCDate(from.getUTCDate() - (periodDays - 1));
7
+ return usage.querySavings({ from, to, signal });
8
+ },
9
+ };
10
+ }
11
+ export function createSessionUsage(sessions) {
12
+ let totals = emptyTotals();
13
+ let active;
14
+ let controller;
15
+ let dirty = false;
16
+ const listeners = new Set();
17
+ const refresh = () => {
18
+ dirty = true;
19
+ if (active)
20
+ return active;
21
+ controller ??= new AbortController();
22
+ const signal = controller.signal;
23
+ active = (async () => {
24
+ do {
25
+ dirty = false;
26
+ const next = emptyTotals();
27
+ let cursor;
28
+ do {
29
+ const page = await sessions.executions({ includeDescendants: true, signal, ...(cursor ? { cursor } : {}) });
30
+ for (const execution of page.items) {
31
+ if (!execution.usage)
32
+ continue;
33
+ const usage = execution.usage;
34
+ next.input += usage.input;
35
+ next.output += usage.output;
36
+ next.cacheRead += usage.cacheRead;
37
+ next.cacheWrite += usage.cacheWrite;
38
+ next.cost += usage.cost;
39
+ }
40
+ cursor = page.nextCursor;
41
+ } while (cursor);
42
+ if (!signal.aborted) {
43
+ totals = next;
44
+ for (const listener of listeners)
45
+ listener();
46
+ }
47
+ } while (dirty && !signal.aborted);
48
+ })().catch(() => { }).finally(() => { active = undefined; });
49
+ return active;
50
+ };
51
+ return {
52
+ getUsage: () => totals,
53
+ settle: async () => { await active; },
54
+ subscribe(listener) {
55
+ listeners.add(listener);
56
+ const unsubscribe = sessions.subscribe(event => { if (event.kind === 'execution')
57
+ void refresh(); });
58
+ void refresh();
59
+ return () => { unsubscribe(); listeners.delete(listener); controller?.abort(); controller = undefined; };
60
+ },
61
+ };
62
+ }
63
+ function emptyTotals() {
64
+ return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0 };
65
+ }
66
+ //# sourceMappingURL=core-services.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-services.js","sourceRoot":"","sources":["../src/core-services.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,kBAAkB,CAAC,KAAmB;IACpD,OAAO;QACL,KAAK,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE;YAC1B,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC;YACtB,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,cAAc,EAAE,EAAE,EAAE,CAAC,WAAW,EAAE,EAAE,EAAE,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;YACxF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC;YACtD,OAAO,KAAK,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QAClD,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MA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