founder-vn 0.2.0__py3-none-any.whl
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.
- founder_vn/__init__.py +3 -0
- founder_vn/board.py +341 -0
- founder_vn/cfo.py +384 -0
- founder_vn/cli.py +151 -0
- founder_vn/files.py +54 -0
- founder_vn/info.py +8 -0
- founder_vn/install.py +122 -0
- founder_vn/llm.py +102 -0
- founder_vn/panel.py +704 -0
- founder_vn/plan.py +171 -0
- founder_vn/pricing.py +231 -0
- founder_vn/server.py +109 -0
- founder_vn/skills/.gitkeep +0 -0
- founder_vn/skills/founder-board/SKILL.md +75 -0
- founder_vn/skills/founder-board/lenses.md +13 -0
- founder_vn/skills/founder-cfo/SKILL.md +98 -0
- founder_vn/skills/founder-competitors/SKILL.md +68 -0
- founder_vn/skills/founder-competitors/survey-form.md +41 -0
- founder_vn/skills/founder-consumer/SKILL.md +77 -0
- founder_vn/skills/founder-plan/SKILL.md +77 -0
- founder_vn/skills/founder-pricing/SKILL.md +72 -0
- founder_vn/vnd.py +67 -0
- founder_vn-0.2.0.dist-info/METADATA +8 -0
- founder_vn-0.2.0.dist-info/RECORD +27 -0
- founder_vn-0.2.0.dist-info/WHEEL +4 -0
- founder_vn-0.2.0.dist-info/entry_points.txt +3 -0
- founder_vn-0.2.0.dist-info/licenses/LICENSE +49 -0
founder_vn/__init__.py
ADDED
founder_vn/board.py
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
"""Board run: three lens memos (Offers, Product, Systems) asked of the configured model.
|
|
2
|
+
|
|
3
|
+
One set of functions behind ``founder-vn board run`` and the MCP tool ``board_run``. The skill
|
|
4
|
+
writes a standalone brief to ``founder/board/brief.md``; the package asks the model once per lens,
|
|
5
|
+
as three independent completions, and files each valid memo as ``<lens>.json`` and ``<lens>.md``.
|
|
6
|
+
The job runs on the same runner pattern as ``panel run`` and is polled with the same ``job_status``.
|
|
7
|
+
The chair's summary is the host's job, not the package's. State goes through ``founder_vn.files``.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import hashlib
|
|
11
|
+
import json
|
|
12
|
+
import subprocess
|
|
13
|
+
import sys
|
|
14
|
+
import threading
|
|
15
|
+
import time
|
|
16
|
+
import uuid
|
|
17
|
+
from collections.abc import Callable
|
|
18
|
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
from founder_vn import files, llm, panel
|
|
23
|
+
|
|
24
|
+
BOARD_DIR = "board"
|
|
25
|
+
BRIEF = "brief.md"
|
|
26
|
+
ATTEMPTS = panel.ATTEMPTS
|
|
27
|
+
MAX_INVALID = panel.MAX_INVALID
|
|
28
|
+
BACKOFF = panel.BACKOFF
|
|
29
|
+
VOTES = {
|
|
30
|
+
"go": "nên làm",
|
|
31
|
+
"conditional": "làm có điều kiện",
|
|
32
|
+
"no_go": "chưa nên làm",
|
|
33
|
+
}
|
|
34
|
+
FIELDS = ("score", "vote", "strong", "would_kill", "questions", "conditions")
|
|
35
|
+
LIST_FIELDS = (
|
|
36
|
+
("strong", "Điểm mạnh"),
|
|
37
|
+
("would_kill", "Điều có thể giết ý tưởng này"),
|
|
38
|
+
("questions", "Câu hỏi còn mở"),
|
|
39
|
+
("conditions", "Điều kiện"),
|
|
40
|
+
)
|
|
41
|
+
RULE = (
|
|
42
|
+
"Quy tắc bắt buộc: chỉ áp dụng khung tư duy đã được xuất bản trong nguồn dưới đây như một công "
|
|
43
|
+
"cụ phân tích; không bao giờ nói thay tác giả, không đóng vai tác giả, không đặt vào miệng tác "
|
|
44
|
+
"giả một câu nào, không trích dẫn như thể tác giả đang nhận xét ý tưởng này."
|
|
45
|
+
)
|
|
46
|
+
LENSES: dict[str, dict[str, str]] = {
|
|
47
|
+
"offers": {
|
|
48
|
+
"title": "Offers",
|
|
49
|
+
"source": "100M Offers (Alex Hormozi)",
|
|
50
|
+
"framework": (
|
|
51
|
+
"Đề xuất giá trị là sản phẩm. Xét bằng phương trình giá trị: kết quả khách mơ ước và "
|
|
52
|
+
"khả năng tin là đạt được, chia cho thời gian chờ và công sức, rủi ro khách phải gánh. "
|
|
53
|
+
"Hỏi: lời hứa có cụ thể và đo được không; có gói, bảo đảm hay phần thêm nào khiến việc "
|
|
54
|
+
"từ chối là điều dại dột; giá có tương xứng với giá trị chứ không chỉ so với đối thủ; "
|
|
55
|
+
"ai là nhóm khách có nhu cầu rõ và sẵn sàng trả; có cách nào nâng giá trị mà không "
|
|
56
|
+
"giảm giá."
|
|
57
|
+
),
|
|
58
|
+
},
|
|
59
|
+
"product": {
|
|
60
|
+
"title": "Product",
|
|
61
|
+
"source": "tiểu sử Steve Jobs do Walter Isaacson viết",
|
|
62
|
+
"framework": (
|
|
63
|
+
"Chất lượng và sự tập trung của sản phẩm. Xét theo các bài học Isaacson rút ra từ "
|
|
64
|
+
"tiểu sử: sản phẩm có một trải nghiệm cốt lõi rõ ràng không; có dám nói không với "
|
|
65
|
+
"những thứ làm loãng nó không; chi tiết, kể cả phần khách không nhìn thấy, có được "
|
|
66
|
+
"chăm chút không; toàn bộ trải nghiệm từ lúc khách biết đến tới lúc quay lại có liền "
|
|
67
|
+
"mạch không; sản phẩm có khiến người dùng muốn kể cho người khác không."
|
|
68
|
+
),
|
|
69
|
+
},
|
|
70
|
+
"systems": {
|
|
71
|
+
"title": "Systems",
|
|
72
|
+
"source": "The E-Myth Revisited (Michael E. Gerber)",
|
|
73
|
+
"framework": (
|
|
74
|
+
"Doanh nghiệp là một hệ thống chứ không phải một công việc. Xét theo ba vai: kỹ "
|
|
75
|
+
"thuật viên, quản lý, nhà doanh nghiệp. Hỏi: nếu chủ vắng mặt một tháng thì tiệm có "
|
|
76
|
+
"chạy không; mỗi việc lặp lại đã có quy trình viết ra để người mới làm đúng chưa; "
|
|
77
|
+
"tiệm có thể nhân bản thành tiệm thứ hai theo cùng cách không; chủ đang làm việc "
|
|
78
|
+
"trong tiệm hay đang xây tiệm; các con số vận hành (công suất, lượt khách, giờ làm) "
|
|
79
|
+
"có người theo dõi không."
|
|
80
|
+
),
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
TEMPLATE = """Bạn là một thành viên hội đồng cố vấn, đọc bản tóm tắt ý tưởng kinh doanh của một chủ hộ \
|
|
84
|
+
kinh doanh nhỏ ở Việt Nam qua một lens duy nhất.
|
|
85
|
+
Mã lens: {id}
|
|
86
|
+
Lens: {title}
|
|
87
|
+
Nguồn của lens: {source}
|
|
88
|
+
|
|
89
|
+
{rule}
|
|
90
|
+
|
|
91
|
+
Khung của lens này: {framework}
|
|
92
|
+
|
|
93
|
+
Chỉ dựa vào bản tóm tắt dưới đây. Không biết gì ngoài nó. Không bịa số liệu, không bịa đối thủ; \
|
|
94
|
+
thiếu dữ kiện thì đặt thành câu hỏi. Viết bằng tiếng Việt, xưng hô với chủ là "anh/chị", không dùng \
|
|
95
|
+
ký hiệu đô la; tiền viết theo đồng Việt Nam, ví dụ 35.000 đ. Ý kiến của bạn có thể khác các lens \
|
|
96
|
+
khác; đừng cố đồng ý cho êm.
|
|
97
|
+
|
|
98
|
+
Bản tóm tắt:
|
|
99
|
+
|
|
100
|
+
{brief}
|
|
101
|
+
|
|
102
|
+
Chỉ trả lời bằng một đối tượng JSON, không viết thêm gì, với các trường:
|
|
103
|
+
- "score": số nguyên từ 1 đến 10, điểm của lens này cho ý tưởng
|
|
104
|
+
- "vote": một trong "go", "conditional", "no_go"
|
|
105
|
+
- "strong": danh sách câu tiếng Việt, những điểm mạnh theo lens này (ít nhất một)
|
|
106
|
+
- "would_kill": danh sách câu tiếng Việt, điều có thể giết ý tưởng này (ít nhất một)
|
|
107
|
+
- "questions": danh sách câu hỏi còn mở, mỗi câu nên được trả lời bằng một con số hay một việc \
|
|
108
|
+
làm cụ thể (có thể để trống)
|
|
109
|
+
- "conditions": danh sách điều kiện phải đạt trước khi làm, mỗi điều kiện kiểm tra được (có thể để \
|
|
110
|
+
trống)
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class BoardError(panel.PanelError):
|
|
115
|
+
"""The board input is missing or malformed; the message names the file or field."""
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _dump(obj: Any) -> str:
|
|
119
|
+
return json.dumps(obj, indent=1, ensure_ascii=False) + "\n"
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _path(*parts: str) -> str:
|
|
123
|
+
return "/".join((BOARD_DIR, *parts))
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def prompt(lens: str, brief: str) -> str:
|
|
127
|
+
"""The Vietnamese prompt of one lens: its framework, the never-speak-as-the-author rule and
|
|
128
|
+
the standalone brief. A lens sees nothing but this text."""
|
|
129
|
+
spec = LENSES[lens]
|
|
130
|
+
text = TEMPLATE
|
|
131
|
+
fields = {"id": lens, **spec, "rule": RULE, "brief": brief}
|
|
132
|
+
for key, value in fields.items():
|
|
133
|
+
text = text.replace("{" + key + "}", value)
|
|
134
|
+
return text
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def prompt_hash(brief: str) -> str:
|
|
138
|
+
"""SHA-256 of the prompt template, the lens texts and the brief."""
|
|
139
|
+
payload = "\n".join([TEMPLATE, RULE, _dump(LENSES), brief])
|
|
140
|
+
return hashlib.sha256(payload.encode("utf-8")).hexdigest()
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _text_list(value: Any) -> bool:
|
|
144
|
+
return isinstance(value, list) and all(isinstance(v, str) and v.strip() for v in value)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def memo_problem(memo: Any) -> str | None:
|
|
148
|
+
"""None when ``memo`` has the fixed shape, else a short problem naming the field."""
|
|
149
|
+
if not isinstance(memo, dict):
|
|
150
|
+
return "không phải một đối tượng JSON"
|
|
151
|
+
score = memo.get("score")
|
|
152
|
+
if isinstance(score, bool) or not isinstance(score, int) or not 1 <= score <= 10:
|
|
153
|
+
return "'score' phải là số nguyên từ 1 đến 10"
|
|
154
|
+
if memo.get("vote") not in VOTES:
|
|
155
|
+
return f"'vote' phải là một trong {', '.join(VOTES)}"
|
|
156
|
+
for field in ("strong", "would_kill"):
|
|
157
|
+
if not _text_list(memo.get(field)) or not memo[field]:
|
|
158
|
+
return f"'{field}' phải là danh sách câu, ít nhất một"
|
|
159
|
+
for field in ("questions", "conditions"):
|
|
160
|
+
if not _text_list(memo.get(field)):
|
|
161
|
+
return f"'{field}' phải là danh sách câu (có thể trống)"
|
|
162
|
+
return None
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def extract_memo(reply: str) -> tuple[dict[str, Any] | None, str | None]:
|
|
166
|
+
"""The first JSON object in ``reply`` and ``None``, or ``None`` and what is wrong with it."""
|
|
167
|
+
start = reply.find("{")
|
|
168
|
+
if start < 0:
|
|
169
|
+
return None, "không có đối tượng JSON"
|
|
170
|
+
try:
|
|
171
|
+
memo, _ = json.JSONDecoder().raw_decode(reply[start:])
|
|
172
|
+
except json.JSONDecodeError as e:
|
|
173
|
+
return None, f"JSON không đọc được: {e}"
|
|
174
|
+
problem = memo_problem(memo)
|
|
175
|
+
return (None, problem) if problem else ({k: memo[k] for k in FIELDS}, None)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def memo_md(lens: str, memo: dict[str, Any]) -> str:
|
|
179
|
+
"""The Vietnamese memo of one lens in its fixed shape."""
|
|
180
|
+
spec = LENSES[lens]
|
|
181
|
+
lines = [
|
|
182
|
+
f"# Lens {spec['title']}: {spec['source']}",
|
|
183
|
+
"",
|
|
184
|
+
f"**Điểm: {memo['score']}/10** · **Phiếu: {VOTES[memo['vote']]}**",
|
|
185
|
+
]
|
|
186
|
+
for key, title in LIST_FIELDS:
|
|
187
|
+
lines += ["", f"## {title}", ""]
|
|
188
|
+
items = memo[key]
|
|
189
|
+
lines += [f"- {item}" for item in items] if items else ["- chưa có"]
|
|
190
|
+
lines += [
|
|
191
|
+
"",
|
|
192
|
+
"Đây là ý kiến mô phỏng theo một khung đã xuất bản, không nói thay tác giả và không phải "
|
|
193
|
+
"tư vấn tài chính, thuế hay pháp lý.",
|
|
194
|
+
]
|
|
195
|
+
return "\n".join(lines) + "\n"
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def _memo_problem_on_disk(project: Path, lens: str) -> str | None:
|
|
199
|
+
try:
|
|
200
|
+
text = files.read_text(project, _path(f"{lens}.json"))
|
|
201
|
+
except FileNotFoundError:
|
|
202
|
+
return "chưa có memo"
|
|
203
|
+
try:
|
|
204
|
+
return memo_problem(json.loads(text))
|
|
205
|
+
except json.JSONDecodeError:
|
|
206
|
+
return "không phải JSON hợp lệ"
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def _read_brief(project: Path) -> str:
|
|
210
|
+
try:
|
|
211
|
+
text = files.read_text(project, _path(BRIEF)).strip()
|
|
212
|
+
except FileNotFoundError:
|
|
213
|
+
raise BoardError(
|
|
214
|
+
f"không thấy founder/{_path(BRIEF)}: viết bản tóm tắt tự đứng một mình trước"
|
|
215
|
+
) from None
|
|
216
|
+
if not text:
|
|
217
|
+
raise BoardError(f"founder/{_path(BRIEF)} trống: viết bản tóm tắt tự đứng một mình trước")
|
|
218
|
+
return text
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
def _job_path(job_id: str) -> str:
|
|
222
|
+
return panel._job_path(job_id, BOARD_DIR)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def start_job(project: Path, launch: Callable[[Path, str], None]) -> str:
|
|
226
|
+
"""Record the model and prompt hash, create a job for the lenses without a valid memo and
|
|
227
|
+
hand it to ``launch``; return at once with the job as JSON."""
|
|
228
|
+
brief = _read_brief(project)
|
|
229
|
+
try:
|
|
230
|
+
config = llm.load_config()
|
|
231
|
+
except llm.NotConfigured as e:
|
|
232
|
+
raise BoardError(str(e)) from None
|
|
233
|
+
targets = [lens for lens in LENSES if _memo_problem_on_disk(project, lens)]
|
|
234
|
+
meta = {
|
|
235
|
+
"mode": "model",
|
|
236
|
+
"model": config.model,
|
|
237
|
+
"prompt_hash": prompt_hash(brief),
|
|
238
|
+
"lenses": list(LENSES),
|
|
239
|
+
}
|
|
240
|
+
files.write_text(project, _path("board.json"), _dump(meta))
|
|
241
|
+
job_id = f"J-{uuid.uuid4().hex[:8]}"
|
|
242
|
+
state = "running" if targets else "done"
|
|
243
|
+
job = {
|
|
244
|
+
"job_id": job_id,
|
|
245
|
+
"state": state,
|
|
246
|
+
"targets": targets,
|
|
247
|
+
"done": [],
|
|
248
|
+
"failed": [],
|
|
249
|
+
"excluded": [],
|
|
250
|
+
"last_error": None,
|
|
251
|
+
}
|
|
252
|
+
files.write_text(project, _job_path(job_id), _dump(job))
|
|
253
|
+
if targets:
|
|
254
|
+
launch(project, job_id)
|
|
255
|
+
return _dump({"job_id": job_id, "state": state, "lenses": len(targets)})
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def _ask(
|
|
259
|
+
project: Path, config: llm.Config, lens: str, brief: str, timeout: float, backoff: float
|
|
260
|
+
) -> tuple[str, str | None]:
|
|
261
|
+
"""Ask one lens; return ``done``, ``failed`` or ``excluded`` and the last error.
|
|
262
|
+
|
|
263
|
+
The retry rules are the panel's: a failing call is retried with doubling backoff up to
|
|
264
|
+
``ATTEMPTS`` times (``failed``); a reply that is not a valid memo is asked once more, and
|
|
265
|
+
invalid twice the lens is ``excluded``. Only a valid memo is written.
|
|
266
|
+
"""
|
|
267
|
+
text = prompt(lens, brief)
|
|
268
|
+
problem = None
|
|
269
|
+
for _ in range(MAX_INVALID):
|
|
270
|
+
reply = ""
|
|
271
|
+
for attempt in range(ATTEMPTS):
|
|
272
|
+
try:
|
|
273
|
+
reply = llm.complete(config, text, timeout)
|
|
274
|
+
break
|
|
275
|
+
except llm.CallFailed as e:
|
|
276
|
+
if attempt == ATTEMPTS - 1:
|
|
277
|
+
return "failed", f"{lens}: {e}"
|
|
278
|
+
time.sleep(backoff * 2**attempt)
|
|
279
|
+
memo, problem = extract_memo(reply)
|
|
280
|
+
if memo is not None:
|
|
281
|
+
files.write_text(project, _path(f"{lens}.json"), _dump(memo))
|
|
282
|
+
files.write_text(project, _path(f"{lens}.md"), memo_md(lens, memo))
|
|
283
|
+
return "done", None
|
|
284
|
+
return "excluded", f"{lens}: {problem}"
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def execute(
|
|
288
|
+
project: Path, job_id: str, *, timeout: float = llm.TIMEOUT, backoff: float = BACKOFF
|
|
289
|
+
) -> None:
|
|
290
|
+
"""Ask each lens of the job, one independent completion each, and file the memos."""
|
|
291
|
+
job = panel._read_job(project, job_id, BOARD_DIR)
|
|
292
|
+
config = llm.load_config()
|
|
293
|
+
brief = _read_brief(project)
|
|
294
|
+
with ThreadPoolExecutor(max_workers=len(LENSES)) as pool:
|
|
295
|
+
futures = {
|
|
296
|
+
pool.submit(_ask, project, config, lens, brief, timeout, backoff): lens
|
|
297
|
+
for lens in job["targets"]
|
|
298
|
+
}
|
|
299
|
+
for future in as_completed(futures):
|
|
300
|
+
outcome, error = future.result()
|
|
301
|
+
job[outcome].append(futures[future])
|
|
302
|
+
if error:
|
|
303
|
+
job["last_error"] = error
|
|
304
|
+
files.write_text(project, _job_path(job_id), _dump(job))
|
|
305
|
+
job["state"] = "done"
|
|
306
|
+
files.write_text(project, _job_path(job_id), _dump(job))
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def work(project: Path, job_id: str) -> None:
|
|
310
|
+
"""Run a job to the end; whatever goes wrong is written into the job, not lost."""
|
|
311
|
+
try:
|
|
312
|
+
execute(project, job_id)
|
|
313
|
+
except Exception as e: # the worker has no caller to tell: the job file is the report
|
|
314
|
+
job = panel._read_job(project, job_id, BOARD_DIR)
|
|
315
|
+
job |= {"state": "error", "last_error": f"{type(e).__name__}: {e}"}
|
|
316
|
+
files.write_text(project, _job_path(job_id), _dump(job))
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
def _in_thread(project: Path, job_id: str) -> None:
|
|
320
|
+
threading.Thread(target=work, args=(project, job_id), daemon=True).start()
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def _in_process(project: Path, job_id: str) -> None:
|
|
324
|
+
"""A detached ``founder-vn board work``: it outlives the short-lived CLI call."""
|
|
325
|
+
subprocess.Popen(
|
|
326
|
+
[sys.executable, "-m", "founder_vn.cli", "board", "work", job_id],
|
|
327
|
+
cwd=project,
|
|
328
|
+
stdin=subprocess.DEVNULL,
|
|
329
|
+
stdout=subprocess.DEVNULL,
|
|
330
|
+
stderr=subprocess.DEVNULL,
|
|
331
|
+
start_new_session=True,
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def run(project: Path, detached: bool) -> str:
|
|
336
|
+
"""Start the job for the lenses without a valid memo and return its id at once.
|
|
337
|
+
|
|
338
|
+
``detached`` hands the work to a separate process (the CLI); otherwise a thread of the
|
|
339
|
+
long-lived MCP server does it.
|
|
340
|
+
"""
|
|
341
|
+
return start_job(project, _in_process if detached else _in_thread)
|