@obrigado/surface 0.1.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/LICENSE +202 -0
- package/README.md +36 -0
- package/dist/index.d.ts +98 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +90 -0
- package/dist/index.js.map +10 -0
- package/package.json +49 -0
- package/src/index.ts +186 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @obrigado/surface
|
|
2
|
+
|
|
3
|
+
What a host that draws its own UI needs from [Obrigado](https://obrigado.dev)'s renderer, and
|
|
4
|
+
nothing else.
|
|
5
|
+
|
|
6
|
+
Obrigado puts one labeled sponsored line in a coding agent's status line, and 70% of the
|
|
7
|
+
revenue funds the open-source packages the developer's project depends on. There is one
|
|
8
|
+
renderer, `obrigado statusline`, and every host serialises from it. A host that composes the
|
|
9
|
+
line from parts rather than printing an ANSI string — OpenCode's TUI plugin, the VS Code
|
|
10
|
+
extension — runs `obrigado statusline --agent <host> --json` and draws what it is handed.
|
|
11
|
+
|
|
12
|
+
This package is the three things every such host needs, once, with no dependencies and no I/O:
|
|
13
|
+
|
|
14
|
+
- **The shape** of one `--json` line: `Sponsored`, `SponsoredSpan`, `SponsoredBrand`, and the
|
|
15
|
+
palette a span may ask for.
|
|
16
|
+
- **`parseSponsored(line)`** — a complete line, or `null`. Label, copy and URL or nothing: a
|
|
17
|
+
creative without its label is an undisclosed advertisement, and one without its URL is an
|
|
18
|
+
impression nobody can act on. Unknown colours degrade to the host's foreground.
|
|
19
|
+
- **`statuslineArgv(agent, override?)`** and **`splitCommand(text)`** — the argv to spawn, with
|
|
20
|
+
a quote-aware split so a source checkout under a path with a space still runs.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { parseSponsored, statuslineArgv } from "@obrigado/surface";
|
|
24
|
+
|
|
25
|
+
const [bin, ...args] = statuslineArgv("my-host", process.env["OBRIGADO_STATUSLINE_COMMAND"]);
|
|
26
|
+
// spawn bin with args, write `{ "session_id": …, "cwd": … }` to stdin, read the first line
|
|
27
|
+
const ad = parseSponsored(firstLine);
|
|
28
|
+
if (ad !== null) draw(ad.label, ad.spans, ad.url);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
A host never fetches, counts or formats an ad itself; rotation, batching, beacons and the
|
|
32
|
+
disclosure stay in the renderer. That is what keeps "always labeled" a property rather than a
|
|
33
|
+
convention. To add a host, see `docs/ADDING-A-SURFACE.md` in the
|
|
34
|
+
[client repository](https://github.com/obrigado-dev/client).
|
|
35
|
+
|
|
36
|
+
Apache-2.0.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a host that draws its own UI needs from the renderer, and nothing else.
|
|
3
|
+
*
|
|
4
|
+
* INVARIANT 13: there is one renderer, and every host serialises from it. A host package —
|
|
5
|
+
* the OpenCode plugin, the VS Code extension — runs `obrigado statusline --json` and composes
|
|
6
|
+
* the parts it is handed with its own primitives. It never fetches, counts or formats an ad.
|
|
7
|
+
* That boundary is what keeps "always labeled" a property rather than a convention, and it is
|
|
8
|
+
* why host packages import nothing from `@obrigado/shared`: the wire contract, the money and
|
|
9
|
+
* the rotation are the renderer's business.
|
|
10
|
+
*
|
|
11
|
+
* What the hosts DID each carry was a copy of the same three things — the shape of one `--json`
|
|
12
|
+
* line, the checks that decide whether a line is complete enough to draw, and the splitting of
|
|
13
|
+
* a configured command into an argv. Three copies drift: the palette had reached five spellings,
|
|
14
|
+
* and every copy of the argv split broke on a path with a space in it. This package is those
|
|
15
|
+
* three things, once, with no dependencies and no I/O. It speaks no HTTP and reads no file, so
|
|
16
|
+
* depending on it changes nothing about what a host is allowed to do.
|
|
17
|
+
*
|
|
18
|
+
* The Pi extension does not depend on it, deliberately: that file is COPIED into a developer's
|
|
19
|
+
* extensions directory and must stand alone. It keeps its own copy of `splitCommand`, and a test
|
|
20
|
+
* in its package holds the two to the same behaviour.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* The four colours a creative may wear. Never red or yellow: in a terminal those mean error
|
|
24
|
+
* and warning, and an ad wearing either is impersonating a build failure. This is the one
|
|
25
|
+
* copy the hosts see; `@obrigado/shared`'s contract is the other, and a test in the client
|
|
26
|
+
* package holds the two together.
|
|
27
|
+
*/
|
|
28
|
+
export declare const SPAN_COLORS: readonly ["cyan", "blue", "green", "magenta"];
|
|
29
|
+
export type SpanColor = (typeof SPAN_COLORS)[number];
|
|
30
|
+
/** Line-level colour slot; `default` means the host's own foreground. */
|
|
31
|
+
export declare const LINE_STYLES: readonly ["default", "cyan", "blue", "green", "magenta"];
|
|
32
|
+
export type LineStyle = (typeof LINE_STYLES)[number];
|
|
33
|
+
/** Line-level effect. Nothing louder than italic is offered, so nothing louder is drawn. */
|
|
34
|
+
export declare const LINE_EFFECTS: readonly ["none", "italic"];
|
|
35
|
+
export type LineEffect = (typeof LINE_EFFECTS)[number];
|
|
36
|
+
/** A run of styled text, as the renderer serialises it. */
|
|
37
|
+
export interface SponsoredSpan {
|
|
38
|
+
readonly text: string;
|
|
39
|
+
readonly bold?: boolean;
|
|
40
|
+
readonly italic?: boolean;
|
|
41
|
+
/** Reverse video in a terminal; a host with no such thing ignores it. */
|
|
42
|
+
readonly highlight?: boolean;
|
|
43
|
+
/** One of the four slots an advertiser may choose. */
|
|
44
|
+
readonly color?: SpanColor;
|
|
45
|
+
/** Part of the single tracking link whose URL is `Sponsored.url`. */
|
|
46
|
+
readonly link?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/** Who is paying, as they name themselves. */
|
|
49
|
+
export interface SponsoredBrand {
|
|
50
|
+
readonly name: string;
|
|
51
|
+
/** A `data:image/png;base64,…` URI built server-side from validated bytes, or null. Never a URL. */
|
|
52
|
+
readonly logo: string | null;
|
|
53
|
+
}
|
|
54
|
+
/** One `--json` line from `obrigado statusline`. */
|
|
55
|
+
export interface Sponsored {
|
|
56
|
+
/** The disclosure. A host renders it before the copy, always, and never styles it. */
|
|
57
|
+
readonly label: string;
|
|
58
|
+
/** The plain copy: the accessible fallback, and the form that belongs in a log. */
|
|
59
|
+
readonly copy: string;
|
|
60
|
+
/** The click redirect, `https://obrigado.dev/c/<token>`. */
|
|
61
|
+
readonly url: string;
|
|
62
|
+
readonly spans: readonly SponsoredSpan[];
|
|
63
|
+
readonly style: LineStyle;
|
|
64
|
+
readonly effect: LineEffect;
|
|
65
|
+
readonly brand: SponsoredBrand | null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* One line of `--json` output, or null for anything that is not a complete sponsored line.
|
|
69
|
+
*
|
|
70
|
+
* Label, copy and URL, or nothing: a creative without its label is an undisclosed
|
|
71
|
+
* advertisement, and one without its URL is an impression nobody can act on. Styling is
|
|
72
|
+
* optional on the wire — an older renderer that sends none still renders, as one unstyled link
|
|
73
|
+
* over the whole line. A brand without a name is not a brand; the alt text for a logo IS the
|
|
74
|
+
* name, so a malformed one is dropped rather than rendered half-way.
|
|
75
|
+
*/
|
|
76
|
+
export declare function parseSponsored(line: string): Sponsored | null;
|
|
77
|
+
/**
|
|
78
|
+
* A configured command, split the way a shell would split it — quotes and all.
|
|
79
|
+
*
|
|
80
|
+
* `OBRIGADO_STATUSLINE_COMMAND` exists so a host can run a source checkout, and a checkout
|
|
81
|
+
* lives at a path. Splitting on spaces broke the moment that path contained one: `bun
|
|
82
|
+
* "/Users/Jane Doe/obrigado/cli.ts" statusline` became four arguments and the spawn failed
|
|
83
|
+
* silently. Double quotes, single quotes and backslash escapes are honoured; nothing else is
|
|
84
|
+
* interpreted — no variables, no globs, no operators — because this is a command, not a script.
|
|
85
|
+
*/
|
|
86
|
+
export declare function splitCommand(text: string): string[];
|
|
87
|
+
/**
|
|
88
|
+
* The argv a host spawns to get its line.
|
|
89
|
+
*
|
|
90
|
+
* `obrigado` from PATH is the installed case. An override — a setting, an environment
|
|
91
|
+
* variable — replaces the executable and its leading arguments and keeps everything after:
|
|
92
|
+
* the host names itself so the impression attributes to it, and asks for `--json` because it
|
|
93
|
+
* draws with its own primitives rather than printing an ANSI string.
|
|
94
|
+
*/
|
|
95
|
+
export declare function statuslineArgv(agent: string, override?: string | undefined, options?: {
|
|
96
|
+
readonly json?: boolean;
|
|
97
|
+
}): string[];
|
|
98
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,WAAW,+CAAgD,CAAC;AACzE,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD,yEAAyE;AACzE,eAAO,MAAM,WAAW,0DAAuC,CAAC;AAChE,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD,4FAA4F;AAC5F,eAAO,MAAM,YAAY,6BAA8B,CAAC;AACxD,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AAUvD,2DAA2D;AAC3D,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE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|
+
// src/index.ts
|
|
2
|
+
var SPAN_COLORS = ["cyan", "blue", "green", "magenta"];
|
|
3
|
+
var LINE_STYLES = ["default", ...SPAN_COLORS];
|
|
4
|
+
var LINE_EFFECTS = ["none", "italic"];
|
|
5
|
+
function isLineStyle(value) {
|
|
6
|
+
return typeof value === "string" && LINE_STYLES.includes(value);
|
|
7
|
+
}
|
|
8
|
+
function isLineEffect(value) {
|
|
9
|
+
return typeof value === "string" && LINE_EFFECTS.includes(value);
|
|
10
|
+
}
|
|
11
|
+
function parseSponsored(line) {
|
|
12
|
+
let parsed;
|
|
13
|
+
try {
|
|
14
|
+
parsed = JSON.parse(line);
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
19
|
+
return null;
|
|
20
|
+
const { label, copy, url, spans, style, effect, brand } = parsed;
|
|
21
|
+
if (typeof label !== "string" || typeof copy !== "string" || typeof url !== "string") {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
if (label.length === 0 || copy.length === 0 || url.length === 0)
|
|
25
|
+
return null;
|
|
26
|
+
return {
|
|
27
|
+
label,
|
|
28
|
+
copy,
|
|
29
|
+
url,
|
|
30
|
+
spans: Array.isArray(spans) && spans.length > 0 ? spans : [{ text: copy, link: true }],
|
|
31
|
+
style: isLineStyle(style) ? style : "default",
|
|
32
|
+
effect: isLineEffect(effect) ? effect : "none",
|
|
33
|
+
brand: brand !== null && brand !== undefined && typeof brand.name === "string" ? { name: brand.name, logo: typeof brand.logo === "string" ? brand.logo : null } : null
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function splitCommand(text) {
|
|
37
|
+
const out = [];
|
|
38
|
+
let current = "";
|
|
39
|
+
let inToken = false;
|
|
40
|
+
let quote = null;
|
|
41
|
+
for (let index = 0;index < text.length; index += 1) {
|
|
42
|
+
const character = text[index] ?? "";
|
|
43
|
+
if (quote !== null) {
|
|
44
|
+
if (character === quote) {
|
|
45
|
+
quote = null;
|
|
46
|
+
} else if (character === "\\" && quote === '"' && index + 1 < text.length) {
|
|
47
|
+
index += 1;
|
|
48
|
+
current += text[index] ?? "";
|
|
49
|
+
} else {
|
|
50
|
+
current += character;
|
|
51
|
+
}
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (character === '"' || character === "'") {
|
|
55
|
+
quote = character;
|
|
56
|
+
inToken = true;
|
|
57
|
+
} else if (character === "\\" && index + 1 < text.length) {
|
|
58
|
+
index += 1;
|
|
59
|
+
current += text[index] ?? "";
|
|
60
|
+
inToken = true;
|
|
61
|
+
} else if (/\s/u.test(character)) {
|
|
62
|
+
if (inToken)
|
|
63
|
+
out.push(current);
|
|
64
|
+
current = "";
|
|
65
|
+
inToken = false;
|
|
66
|
+
} else {
|
|
67
|
+
current += character;
|
|
68
|
+
inToken = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (inToken)
|
|
72
|
+
out.push(current);
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
function statuslineArgv(agent, override, options = {}) {
|
|
76
|
+
const configured = override?.trim() ?? "";
|
|
77
|
+
const base = configured.length > 0 ? splitCommand(configured) : ["obrigado", "statusline"];
|
|
78
|
+
return [...base, "--agent", agent, ...options.json === false ? [] : ["--json"]];
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
statuslineArgv,
|
|
82
|
+
splitCommand,
|
|
83
|
+
parseSponsored,
|
|
84
|
+
SPAN_COLORS,
|
|
85
|
+
LINE_STYLES,
|
|
86
|
+
LINE_EFFECTS
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//# debugId=A0FDAF5235B084AD64756E2164756E21
|
|
90
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * What a host that draws its own UI needs from the renderer, and nothing else.\n *\n * INVARIANT 13: there is one renderer, and every host serialises from it. A host package —\n * the OpenCode plugin, the VS Code extension — runs `obrigado statusline --json` and composes\n * the parts it is handed with its own primitives. It never fetches, counts or formats an ad.\n * That boundary is what keeps \"always labeled\" a property rather than a convention, and it is\n * why host packages import nothing from `@obrigado/shared`: the wire contract, the money and\n * the rotation are the renderer's business.\n *\n * What the hosts DID each carry was a copy of the same three things — the shape of one `--json`\n * line, the checks that decide whether a line is complete enough to draw, and the splitting of\n * a configured command into an argv. Three copies drift: the palette had reached five spellings,\n * and every copy of the argv split broke on a path with a space in it. This package is those\n * three things, once, with no dependencies and no I/O. It speaks no HTTP and reads no file, so\n * depending on it changes nothing about what a host is allowed to do.\n *\n * The Pi extension does not depend on it, deliberately: that file is COPIED into a developer's\n * extensions directory and must stand alone. It keeps its own copy of `splitCommand`, and a test\n * in its package holds the two to the same behaviour.\n */\n\n/**\n * The four colours a creative may wear. Never red or yellow: in a terminal those mean error\n * and warning, and an ad wearing either is impersonating a build failure. This is the one\n * copy the hosts see; `@obrigado/shared`'s contract is the other, and a test in the client\n * package holds the two together.\n */\nexport const SPAN_COLORS = [\"cyan\", \"blue\", \"green\", \"magenta\"] as const;\nexport type SpanColor = (typeof SPAN_COLORS)[number];\n\n/** Line-level colour slot; `default` means the host's own foreground. */\nexport const LINE_STYLES = [\"default\", ...SPAN_COLORS] as const;\nexport type LineStyle = (typeof LINE_STYLES)[number];\n\n/** Line-level effect. Nothing louder than italic is offered, so nothing louder is drawn. */\nexport const LINE_EFFECTS = [\"none\", \"italic\"] as const;\nexport type LineEffect = (typeof LINE_EFFECTS)[number];\n\nfunction isLineStyle(value: unknown): value is LineStyle {\n return typeof value === \"string\" && (LINE_STYLES as readonly string[]).includes(value);\n}\n\nfunction isLineEffect(value: unknown): value is LineEffect {\n return typeof value === \"string\" && (LINE_EFFECTS as readonly string[]).includes(value);\n}\n\n/** A run of styled text, as the renderer serialises it. */\nexport interface SponsoredSpan {\n readonly text: string;\n readonly bold?: boolean;\n readonly italic?: boolean;\n /** Reverse video in a terminal; a host with no such thing ignores it. */\n readonly highlight?: boolean;\n /** One of the four slots an advertiser may choose. */\n readonly color?: SpanColor;\n /** Part of the single tracking link whose URL is `Sponsored.url`. */\n readonly link?: boolean;\n}\n\n/** Who is paying, as they name themselves. */\nexport interface SponsoredBrand {\n readonly name: string;\n /** A `data:image/png;base64,…` URI built server-side from validated bytes, or null. Never a URL. */\n readonly logo: string | null;\n}\n\n/** One `--json` line from `obrigado statusline`. */\nexport interface Sponsored {\n /** The disclosure. A host renders it before the copy, always, and never styles it. */\n readonly label: string;\n /** The plain copy: the accessible fallback, and the form that belongs in a log. */\n readonly copy: string;\n /** The click redirect, `https://obrigado.dev/c/<token>`. */\n readonly url: string;\n readonly spans: readonly SponsoredSpan[];\n readonly style: LineStyle;\n readonly effect: LineEffect;\n readonly brand: SponsoredBrand | null;\n}\n\n/**\n * One line of `--json` output, or null for anything that is not a complete sponsored line.\n *\n * Label, copy and URL, or nothing: a creative without its label is an undisclosed\n * advertisement, and one without its URL is an impression nobody can act on. Styling is\n * optional on the wire — an older renderer that sends none still renders, as one unstyled link\n * over the whole line. A brand without a name is not a brand; the alt text for a logo IS the\n * name, so a malformed one is dropped rather than rendered half-way.\n */\nexport function parseSponsored(line: string): Sponsored | null {\n let parsed: unknown;\n try {\n parsed = JSON.parse(line);\n } catch {\n return null;\n }\n if (typeof parsed !== \"object\" || parsed === null) return null;\n\n const { label, copy, url, spans, style, effect, brand } = parsed as Partial<Sponsored>;\n if (typeof label !== \"string\" || typeof copy !== \"string\" || typeof url !== \"string\") {\n return null;\n }\n if (label.length === 0 || copy.length === 0 || url.length === 0) return null;\n\n return {\n label,\n copy,\n url,\n spans: Array.isArray(spans) && spans.length > 0 ? spans : [{ text: copy, link: true }],\n // A slot or effect this copy does not know is drawn as none: a newer renderer's colour\n // must degrade to the host's foreground, never to a string the host cannot parse.\n style: isLineStyle(style) ? style : \"default\",\n effect: isLineEffect(effect) ? effect : \"none\",\n brand:\n brand !== null && brand !== undefined && typeof brand.name === \"string\"\n ? { name: brand.name, logo: typeof brand.logo === \"string\" ? brand.logo : null }\n : null,\n };\n}\n\n/**\n * A configured command, split the way a shell would split it — quotes and all.\n *\n * `OBRIGADO_STATUSLINE_COMMAND` exists so a host can run a source checkout, and a checkout\n * lives at a path. Splitting on spaces broke the moment that path contained one: `bun\n * \"/Users/Jane Doe/obrigado/cli.ts\" statusline` became four arguments and the spawn failed\n * silently. Double quotes, single quotes and backslash escapes are honoured; nothing else is\n * interpreted — no variables, no globs, no operators — because this is a command, not a script.\n */\nexport function splitCommand(text: string): string[] {\n const out: string[] = [];\n let current = \"\";\n let inToken = false;\n let quote: '\"' | \"'\" | null = null;\n\n for (let index = 0; index < text.length; index += 1) {\n const character = text[index] ?? \"\";\n if (quote !== null) {\n if (character === quote) {\n quote = null;\n } else if (character === \"\\\\\" && quote === '\"' && index + 1 < text.length) {\n index += 1;\n current += text[index] ?? \"\";\n } else {\n current += character;\n }\n continue;\n }\n if (character === '\"' || character === \"'\") {\n quote = character;\n inToken = true;\n } else if (character === \"\\\\\" && index + 1 < text.length) {\n index += 1;\n current += text[index] ?? \"\";\n inToken = true;\n } else if (/\\s/u.test(character)) {\n if (inToken) out.push(current);\n current = \"\";\n inToken = false;\n } else {\n current += character;\n inToken = true;\n }\n }\n if (inToken) out.push(current);\n return out;\n}\n\n/**\n * The argv a host spawns to get its line.\n *\n * `obrigado` from PATH is the installed case. An override — a setting, an environment\n * variable — replaces the executable and its leading arguments and keeps everything after:\n * the host names itself so the impression attributes to it, and asks for `--json` because it\n * draws with its own primitives rather than printing an ANSI string.\n */\nexport function statuslineArgv(\n agent: string,\n override?: string | undefined,\n options: { readonly json?: boolean } = {},\n): string[] {\n const configured = override?.trim() ?? \"\";\n const base = configured.length > 0 ? splitCommand(configured) : [\"obrigado\", \"statusline\"];\n return [...base, \"--agent\", agent, ...(options.json === false ? [] : [\"--json\"])];\n}\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C,IAAI,CAAC,QAAQ,CAAE;AAAA;",
|
|
8
|
+
"debugId": "A0FDAF5235B084AD64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@obrigado/surface",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "What an Obrigado host composes: the `obrigado statusline --json` shape, its parser, and how to invoke the renderer.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"coding-agent",
|
|
7
|
+
"obrigado",
|
|
8
|
+
"opencode",
|
|
9
|
+
"sponsored",
|
|
10
|
+
"statusline",
|
|
11
|
+
"vscode"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://obrigado.dev",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/obrigado-dev/client/issues"
|
|
16
|
+
},
|
|
17
|
+
"license": "Apache-2.0",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/obrigado-dev/client.git",
|
|
21
|
+
"directory": "packages/surface"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"dist/index.js",
|
|
26
|
+
"dist/index.js.map",
|
|
27
|
+
"dist/index.d.ts",
|
|
28
|
+
"dist/index.d.ts.map",
|
|
29
|
+
"src/index.ts"
|
|
30
|
+
],
|
|
31
|
+
"type": "module",
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"bun": "./src/index.ts",
|
|
37
|
+
"import": "./dist/index.js",
|
|
38
|
+
"default": "./dist/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"provenance": true
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target node --format esm --sourcemap=linked && tsc --build tsconfig.json --force",
|
|
47
|
+
"prepack": "bun run build"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a host that draws its own UI needs from the renderer, and nothing else.
|
|
3
|
+
*
|
|
4
|
+
* INVARIANT 13: there is one renderer, and every host serialises from it. A host package —
|
|
5
|
+
* the OpenCode plugin, the VS Code extension — runs `obrigado statusline --json` and composes
|
|
6
|
+
* the parts it is handed with its own primitives. It never fetches, counts or formats an ad.
|
|
7
|
+
* That boundary is what keeps "always labeled" a property rather than a convention, and it is
|
|
8
|
+
* why host packages import nothing from `@obrigado/shared`: the wire contract, the money and
|
|
9
|
+
* the rotation are the renderer's business.
|
|
10
|
+
*
|
|
11
|
+
* What the hosts DID each carry was a copy of the same three things — the shape of one `--json`
|
|
12
|
+
* line, the checks that decide whether a line is complete enough to draw, and the splitting of
|
|
13
|
+
* a configured command into an argv. Three copies drift: the palette had reached five spellings,
|
|
14
|
+
* and every copy of the argv split broke on a path with a space in it. This package is those
|
|
15
|
+
* three things, once, with no dependencies and no I/O. It speaks no HTTP and reads no file, so
|
|
16
|
+
* depending on it changes nothing about what a host is allowed to do.
|
|
17
|
+
*
|
|
18
|
+
* The Pi extension does not depend on it, deliberately: that file is COPIED into a developer's
|
|
19
|
+
* extensions directory and must stand alone. It keeps its own copy of `splitCommand`, and a test
|
|
20
|
+
* in its package holds the two to the same behaviour.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The four colours a creative may wear. Never red or yellow: in a terminal those mean error
|
|
25
|
+
* and warning, and an ad wearing either is impersonating a build failure. This is the one
|
|
26
|
+
* copy the hosts see; `@obrigado/shared`'s contract is the other, and a test in the client
|
|
27
|
+
* package holds the two together.
|
|
28
|
+
*/
|
|
29
|
+
export const SPAN_COLORS = ["cyan", "blue", "green", "magenta"] as const;
|
|
30
|
+
export type SpanColor = (typeof SPAN_COLORS)[number];
|
|
31
|
+
|
|
32
|
+
/** Line-level colour slot; `default` means the host's own foreground. */
|
|
33
|
+
export const LINE_STYLES = ["default", ...SPAN_COLORS] as const;
|
|
34
|
+
export type LineStyle = (typeof LINE_STYLES)[number];
|
|
35
|
+
|
|
36
|
+
/** Line-level effect. Nothing louder than italic is offered, so nothing louder is drawn. */
|
|
37
|
+
export const LINE_EFFECTS = ["none", "italic"] as const;
|
|
38
|
+
export type LineEffect = (typeof LINE_EFFECTS)[number];
|
|
39
|
+
|
|
40
|
+
function isLineStyle(value: unknown): value is LineStyle {
|
|
41
|
+
return typeof value === "string" && (LINE_STYLES as readonly string[]).includes(value);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function isLineEffect(value: unknown): value is LineEffect {
|
|
45
|
+
return typeof value === "string" && (LINE_EFFECTS as readonly string[]).includes(value);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** A run of styled text, as the renderer serialises it. */
|
|
49
|
+
export interface SponsoredSpan {
|
|
50
|
+
readonly text: string;
|
|
51
|
+
readonly bold?: boolean;
|
|
52
|
+
readonly italic?: boolean;
|
|
53
|
+
/** Reverse video in a terminal; a host with no such thing ignores it. */
|
|
54
|
+
readonly highlight?: boolean;
|
|
55
|
+
/** One of the four slots an advertiser may choose. */
|
|
56
|
+
readonly color?: SpanColor;
|
|
57
|
+
/** Part of the single tracking link whose URL is `Sponsored.url`. */
|
|
58
|
+
readonly link?: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Who is paying, as they name themselves. */
|
|
62
|
+
export interface SponsoredBrand {
|
|
63
|
+
readonly name: string;
|
|
64
|
+
/** A `data:image/png;base64,…` URI built server-side from validated bytes, or null. Never a URL. */
|
|
65
|
+
readonly logo: string | null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** One `--json` line from `obrigado statusline`. */
|
|
69
|
+
export interface Sponsored {
|
|
70
|
+
/** The disclosure. A host renders it before the copy, always, and never styles it. */
|
|
71
|
+
readonly label: string;
|
|
72
|
+
/** The plain copy: the accessible fallback, and the form that belongs in a log. */
|
|
73
|
+
readonly copy: string;
|
|
74
|
+
/** The click redirect, `https://obrigado.dev/c/<token>`. */
|
|
75
|
+
readonly url: string;
|
|
76
|
+
readonly spans: readonly SponsoredSpan[];
|
|
77
|
+
readonly style: LineStyle;
|
|
78
|
+
readonly effect: LineEffect;
|
|
79
|
+
readonly brand: SponsoredBrand | null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* One line of `--json` output, or null for anything that is not a complete sponsored line.
|
|
84
|
+
*
|
|
85
|
+
* Label, copy and URL, or nothing: a creative without its label is an undisclosed
|
|
86
|
+
* advertisement, and one without its URL is an impression nobody can act on. Styling is
|
|
87
|
+
* optional on the wire — an older renderer that sends none still renders, as one unstyled link
|
|
88
|
+
* over the whole line. A brand without a name is not a brand; the alt text for a logo IS the
|
|
89
|
+
* name, so a malformed one is dropped rather than rendered half-way.
|
|
90
|
+
*/
|
|
91
|
+
export function parseSponsored(line: string): Sponsored | null {
|
|
92
|
+
let parsed: unknown;
|
|
93
|
+
try {
|
|
94
|
+
parsed = JSON.parse(line);
|
|
95
|
+
} catch {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
99
|
+
|
|
100
|
+
const { label, copy, url, spans, style, effect, brand } = parsed as Partial<Sponsored>;
|
|
101
|
+
if (typeof label !== "string" || typeof copy !== "string" || typeof url !== "string") {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
if (label.length === 0 || copy.length === 0 || url.length === 0) return null;
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
label,
|
|
108
|
+
copy,
|
|
109
|
+
url,
|
|
110
|
+
spans: Array.isArray(spans) && spans.length > 0 ? spans : [{ text: copy, link: true }],
|
|
111
|
+
// A slot or effect this copy does not know is drawn as none: a newer renderer's colour
|
|
112
|
+
// must degrade to the host's foreground, never to a string the host cannot parse.
|
|
113
|
+
style: isLineStyle(style) ? style : "default",
|
|
114
|
+
effect: isLineEffect(effect) ? effect : "none",
|
|
115
|
+
brand:
|
|
116
|
+
brand !== null && brand !== undefined && typeof brand.name === "string"
|
|
117
|
+
? { name: brand.name, logo: typeof brand.logo === "string" ? brand.logo : null }
|
|
118
|
+
: null,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A configured command, split the way a shell would split it — quotes and all.
|
|
124
|
+
*
|
|
125
|
+
* `OBRIGADO_STATUSLINE_COMMAND` exists so a host can run a source checkout, and a checkout
|
|
126
|
+
* lives at a path. Splitting on spaces broke the moment that path contained one: `bun
|
|
127
|
+
* "/Users/Jane Doe/obrigado/cli.ts" statusline` became four arguments and the spawn failed
|
|
128
|
+
* silently. Double quotes, single quotes and backslash escapes are honoured; nothing else is
|
|
129
|
+
* interpreted — no variables, no globs, no operators — because this is a command, not a script.
|
|
130
|
+
*/
|
|
131
|
+
export function splitCommand(text: string): string[] {
|
|
132
|
+
const out: string[] = [];
|
|
133
|
+
let current = "";
|
|
134
|
+
let inToken = false;
|
|
135
|
+
let quote: '"' | "'" | null = null;
|
|
136
|
+
|
|
137
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
138
|
+
const character = text[index] ?? "";
|
|
139
|
+
if (quote !== null) {
|
|
140
|
+
if (character === quote) {
|
|
141
|
+
quote = null;
|
|
142
|
+
} else if (character === "\\" && quote === '"' && index + 1 < text.length) {
|
|
143
|
+
index += 1;
|
|
144
|
+
current += text[index] ?? "";
|
|
145
|
+
} else {
|
|
146
|
+
current += character;
|
|
147
|
+
}
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (character === '"' || character === "'") {
|
|
151
|
+
quote = character;
|
|
152
|
+
inToken = true;
|
|
153
|
+
} else if (character === "\\" && index + 1 < text.length) {
|
|
154
|
+
index += 1;
|
|
155
|
+
current += text[index] ?? "";
|
|
156
|
+
inToken = true;
|
|
157
|
+
} else if (/\s/u.test(character)) {
|
|
158
|
+
if (inToken) out.push(current);
|
|
159
|
+
current = "";
|
|
160
|
+
inToken = false;
|
|
161
|
+
} else {
|
|
162
|
+
current += character;
|
|
163
|
+
inToken = true;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (inToken) out.push(current);
|
|
167
|
+
return out;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The argv a host spawns to get its line.
|
|
172
|
+
*
|
|
173
|
+
* `obrigado` from PATH is the installed case. An override — a setting, an environment
|
|
174
|
+
* variable — replaces the executable and its leading arguments and keeps everything after:
|
|
175
|
+
* the host names itself so the impression attributes to it, and asks for `--json` because it
|
|
176
|
+
* draws with its own primitives rather than printing an ANSI string.
|
|
177
|
+
*/
|
|
178
|
+
export function statuslineArgv(
|
|
179
|
+
agent: string,
|
|
180
|
+
override?: string | undefined,
|
|
181
|
+
options: { readonly json?: boolean } = {},
|
|
182
|
+
): string[] {
|
|
183
|
+
const configured = override?.trim() ?? "";
|
|
184
|
+
const base = configured.length > 0 ? splitCommand(configured) : ["obrigado", "statusline"];
|
|
185
|
+
return [...base, "--agent", agent, ...(options.json === false ? [] : ["--json"])];
|
|
186
|
+
}
|